Convert inline specified UTF-8 mail subject to UTF-8 text

南楼画角 提交于 2019-12-24 20:18:17

问题


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


来源:https://stackoverflow.com/questions/8193854/convert-inline-specified-utf-8-mail-subject-to-utf-8-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!