While creating a new webmailer, I had to coop with a lot of mails and only half of them were correct encoded!
Often the text is tagged as ISO but in real its UTF :/
After trying a lot of solutions and combination a found a way which seems to work for all our mails. Maybe its usefull to someone else too.
<?php
function mime_encode($data)
{
$resp = imap_utf8(trim($data));
if(preg_match("/=\?/", $resp))
$resp = iconv_mime_decode($data, ICONV_MIME_DECODE_CONTINUE_ON_ERROR, "ISO-8859-15");
if(json_encode($resp) == 'null')
$resp = utf8_encode($resp);
return $resp;
}
?>