【发布时间】:2017-10-28 08:06:48
【问题描述】:
我正在尝试使用 Gmail API 阅读电子邮件正文
我使用的是 IMAP,但出于性能原因(在 IMAP 中阅读电子邮件需要花费大量时间),我必须迁移到更快的 Gmail API。
问题是我试图解码 Body,IMAP 很简单,只需从 imap_fetchstructure 返回中读取传输编码并使用适当的函数进行解码。 (imap_qprint、imap_7bit 等)
对于 Gmail
$message = $service->users_messages->get($user, $msg->id, ["format"=>"full"]);
$payload = $message->getPayload();
$mime = $payload->getMimeType();
$body = $payload->getBody();
$headers = $payload->getHeaders();
$content = $body->getData();
$decoded = base64_decode($content);
变量 $contents 是 base64 中的正文,但如果我解码包含奇怪的字符,例如 IMAP 中没有发生的 ��ѽ����。 内容是纯文本 UTF-8,没有额外的部分或附件,只是纯文本。它也发生在 HTML 中。
这些是相关的标题
[{"name":"MIME-Version","value":"1.0"},
{"name":"Content-Type","value":"text\/plain; charset=utf-8"},
{"name":"Content-Transfer-Encoding","value":"quoted-printable"}]
我认为问题在于正文是可引用打印的,但即使我在解码的 base64 上使用 imap_qprint 或quoted_printable_decode,这些奇怪的字符也会继续。
【问题讨论】:
-
您好,引用可打印
-
使用 imap_qprint 或quoted_printable_decode 解码正文内容
-
问题是变量$content不是base64,是base64url,developers.google.com/gmail/api/v1/reference/users/messages/…用这个固定:php.net/manual/es/function.base64-decode.php#118244然后使用imap_qprint