[英]Decode email messages to UTF-7 with PHP
我一直在尝试将许多IMAP消息正文转换为更具可读性的内容(UTF-8或同等功能)。 我似乎找不到开箱即用的功能。
这是我要解码的示例:
President Trump signed an executive order Thursday tar= geting North Korea=E2=80=99s trading partners, calling it a =E2=80=9Cpowerful=E2= =80=9D new tool aimed at isolating and de-nuclearizing the regime.
More on thi= s: http://www.foxnews.com= /politics/2017/09/21/trump-signs-executive-order-targeting-north-koreas-tra= ding-partners.html
(在上面的示例中,任何“ =”,应该有一个换行符)
我尝试过的几件事:
iconv("UTF-8", "Windows-1252//TRANSLIT//IGNORE", $data);
//this resulted in a server error 500
imap_mime_header_decode($data);
//this outputs an array (just something that I tried; yes, I know that it is only good for headers)
iconv_mime_decode($test, 0, "ISO-8859-1");
//This works for a few messages (plaintext ones) but does not output anything for the example above; for others, it only outputs part of the message body
mb_convert_encoding($test, "UTF8");
//this results in another internal server error!
$data = str_replace("=92", "'", $data);
//I have also tried to manually find and replace an occurrence of a utf-7 (I guess) encoded string
无论如何,有些事情我做的完全错了,但不确定是什么。 大家如何阅读使用IMAP检索的电子邮件的正文?
我还有什么可以尝试的? 人们必须始终这样做,但是我似乎找不到解决方案...
谢谢你,罗格
您实际上不在这里处理UTF-7编码。 您实际上看到的是quoted-printable 。
实际上,我已经有一段时间没有写PHP了,所以请原谅我的样式失败,这是一个解码文本的示例:
<?php
$s = 'President Trump signed an executive order Thursday tar= geting North Korea=E2=80=99s trading partners, calling it a =E2=80=9Cpowerful=E2= =80=9D new tool aimed at isolating and de-nuclearizing the regime.';
// It's unclear why I have to replace out `= `, I have a feeling these
// are actually newlines and copy paste error?
echo quoted_printable_decode(str_replace('= ', '', $s));
?>
运行时会产生:
President Trump signed an executive order Thursday targeting North Korea’s trading partners, calling it a “powerful” new tool aimed at isolating and de-nuclearizing the regime.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.