* Karen Cravens <[EMAIL PROTECTED]> [2008-06-26T15:38:17]
> (Dangitall, if 7-bit ASCII was good enough for Fidonet, it ought to be good 
> enough for email. Kids these days.)
>
> I'm getting this when I try to retrieve
> $SomeEmailMimeMessage->header('subject'):
>
> Unknown encoding "X-UNKNOWN" at /usr/lib/perl/5.8/Encode.pm line 166

Wow.  I had never noticed this bit of HORRIBLENESS before.

> Well, crud. But here's the funky thing, that I'm not quite getting: it's 
> not happening when I *create* $SomeEmailMimeMessage. I could deal with 
> that. It's happening when I *look* at that header. Why is that, and how can 
> I trap it (or ideally, detect it when I first load up the message)?

Email::MIME, once again, is shown to be useful for a very, very small set of
email.  That is, email that is not wrong; all correct email won't work either,
but this email is failing because it's not to-spec.

Probably.  I'm not sure if the encoding in a encoded-word needs to be in a
registry somewhere, and whether X-UNKNOWN is.

Anyway, if you must solve this while still using Email::MIME, try the following
awful incantation, which happens to probably work:

  my @values = $email_mime->Email::Simple::header('foo');

> Or should I not be handing Email::MIME something that's gone through 
> encode('unicode', $mailstring) at all? It's mail that was improperly stored 
> in an SQL-ASCII database, and is going into a UNICODE database, so it's a 
> one-time conversion utility on what may well be lightly-fried data. If this 
> is something that's never going to come up on fresh mail, I can code for 
> the finite number of exceptions in this database.

Headers *must* be encoded into a seven bit format.  I have no idea what
"unicode" means as the first arg to encode, but I doubt that it's 7-bit safe.
You'll want to use Encode::MIME::Header, which means you'll need to have a
utf-8 string first.

  my $octets = $octets_that_you_know_are_latin_3;
  my $string = Encode::decode('latin-3', $octets);
  my $header = encode('MIME-Q', $string);

  my $email = Email::MIME->create(
    header => [ From => $header ],
    ...
  );

You need to have a utf8 decoded character string before you make the header
value.


-- 
rjbs

Reply via email to