Mik*_*old 2 php encoding imap utf-8
我有一个功能,旨在将Gmail帐户中的邮件从一个文件夹移动到另一个文件夹。在移动邮件时,该功能是完全可用的。使用utf-8编码的邮箱时出现我的问题。我解码了IMAP文件夹列表响应,但是两个值的转储给出了不同的结果。
// Getting the folders
$folders = imap_list(CONNECTION, MAILBOX, PATTERN);
// After a foreach, stripping slash, prefix and such
// $folder is the raw mailbox name from the IMAP list
$mailbox = utf8_encode(imap_utf7_decode($folder)); // = string(12) "Tæstbåks"
// The entered search from the client
$search_for = "Tæstbåks"; // = string(10) "Tæstbåks"
if($search_for == $mailbox)
print "Yeah!";
else
print "Noo!";
Run Code Online (Sandbox Code Playgroud)
我不知道为什么这两个字符串不匹配,这是我的问题。
PHP的功能imap_utf7_decode($folder)是记录在ISO-8859-1编码返回一个字符串。鉴于IMAP的修改后的UTF-7方案可以对Unicode的整个范围进行编码(这意味着“很多”),并且ISO-8859-1只能表示256个单独的字符,因此您不可能在这种情况下使用该功能。我要建议的是,决定提供这种无用功能的PHP开发人员在他设计该产品的那一天并没有处于最佳状态。
看起来mbstring扩展可以完成您在这里真正想要做的事情-使用类似的东西$mailbox = mb_convert_encoding($folder, "UTF-8", "UTF7-IMAP"),如PHP文档下面的注释中所建议。