Im using Zend_Mail_Storage_Pop3 to retrieve mail messages.
My subject on a mail is Foo/æøå
$message->getHeader('content-type')
gives me text/plain; charset=ISO-8859-1; format=flowed
Before any encoding my $message->subject
looks like this
Foo/µ°à - 2h - comment
Then I try to do a iconv on the subject
$message->subject = iconv('ISO-8859-1','UTF-8', $message->subject);
Now my subject looks like this
Foo/âªâ©âà - 2h - comment
Which is not utf-8 :)
So what should I do? I also tried with utf8_encode and mb_convert_encoding but these gives the same result
Well I got it - but its a bit messy, but it works
$this->mails = new Zend_Mail_Storage_Pop3(...);
$currentMessageId = $this->mails->getNumberByUniqueId($this->mails->getUniqueId($messageId));
$raw = $this->mails->getRawHeader($currentMessageId);
$l = explode("\n", $raw);
foreach($l AS $m) {
if (strpos($m, 'Subject: ') === 0) {
$subject = trim(str_replace('Subject: ', '', $m));
break;
}
}
$subject = str_replace("_"," ", mb_decode_mimeheader($subject));
The content-type
-field usually holds the encoding for the message body, not for the header. Can you have a look at the message in it's raw format? A field in ISO 8859-1 should look like this:
=?ISO-8859-1?Q?Graphgr=F6=DFen?=
while an UTF8 encoded header should look like this:
=?UTF-8?B?w5xtbMOkdXRlIGluIFVURjg=?=
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With