Convert inline specified UTF-8 mail subject to UTF

2019-08-30 04:05发布

问题:

I want to convert the following raw mail subject to normal UTF-8 text:

=?UTF-8?B?UmU6ICMyLUZpbmFsIEFjY2VwdGFuY2UgdGVzdCB3aXRoIG5ldyB0ZXh0IHdpdGggU2xvdg==?= =?UTF-8?B?YWsgaW50ZXJwdW5jdGlvbnMgIivEvsWhxI3FpcW+w73DocOtw6khxYgi?=

The real text for that is (yes, there are some crazy diacritics in it):

Re: #2-Final Acceptance test with new text with Slovak interpunctions "+ľščťžýáíé!ň"

The way I handle mail subjects:

function subject_imapUtf8($str){
    $conv = '';
        $subParts = preg_split('/[\r\n]+/',$str);
    for($i=0;$i<count($subParts);$i++){
        $conv .=  imap_utf8(trim($subParts[$i]));
    }
    return $conv;
} 

For the example this gives me:

=?UTF-8?B?UmU6ICMyLUZpbmFsIEFjY2VwdGFuY2UgdGVzdCB3aXRoIG5ldyB0ZXh0IHdpdGggU2xvdg==?=ak interpunctions "+ľščťžýáíé!ň"

So as you can see the second part/line of the subject is converted correclty.

What do I need to change to convert the first part correctly?

回答1:

mb_internal_encoding("UTF-8");
echo mb_decode_mimeheader($mime); 
  • Demo http://codepad.viper-7.com/a9l4IA