PHP, IMAP and Outlook 2010 - folder names encoding is different?

醉酒当歌 提交于 2019-12-11 07:16:24

问题


Im developing e-mail client in php (with symfony2) and i have problem with folders with non-ascii characters in name.

Folder created in php app is visible in same app correctly. Same in Outlook, created in outlook looks good in outlook. In other cases not. Folder created in outlook is not displayed correctly in php and vice-versa.

Im using utf-7 to encode folder names in php. Which encoding uses Outlook?

Example: Folder named "Wysłąne" (misspelled polish word meaning "sent"), first one is encoded in utf7 by php, and second created in Outlook:

PHP:

Wys&xYLEhQ-ne

Outlook:

Wys&AUIBBQ-ne

Why it differs? How to make it in same encoding?


回答1:


There seems to be a mixup in your source character encoding. imap_utf7_encode (and similar) expect your string in ISO-8859-1 encoding.

AFAICT there is no way to represent Wysłąne in ISO-8859-1. "Wysłąne" represented as UTF-8 becomes (hex bytes)

byte value (hex)    57, 79, 73, C5 82, C4 85, 6E 65
unicode character   W   y   s   ł      ą      n  e

The PHP result Wys&xYLEhQ-ne when decoded is "Wys얂쒅ne". The the two special characters therein are Korean characters with code points U+C582 and U+C485 respectively. So it appears a character-per-character translation is somehow attempted, where the UTF-8 representation of two of the characters is interpreted as Unicode code points instead.

The simplest way to fix this is to use the mbstring extension which has the mb_convert_encoding function.

$utf7encoded = mb_convert_encoding($utf8SourceString, "UTF7-IMAP","UTF-8")
$decodedAsUTF8 = mb_convert_encoding($utf7String,"UTF-8", "UTF7-IMAP")


来源:https://stackoverflow.com/questions/10445774/php-imap-and-outlook-2010-folder-names-encoding-is-different

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