【问题标题】:imap_fetchbody vs Gmail api get methodimap_fetchbody 与 Gmail api 获取方法
【发布时间】:2018-10-14 18:43:02
【问题描述】:

html imap_fetchbodyGmail api GET 方法的返回格式不同。

我将电子邮件写入一个文件,然后重新导入到 Thunderbird。 imap_fetchbody 写入的电子邮件被加载到 Thunderbird 中,没有填充问题,而 API 返回的同一电子邮件有填充问题。

我看到的最大区别是 3D

这里有几行来自imap_fetchbody

<html lang=3Den><head><meta content=3D"date=3Dno" name=3D"format-detection"=
><meta content=3D"email=3Dno" name=3D"format-detection"><style>.awl a {colo=
r: #FFFFFF; text-decoration: none;}.abml a {color: #000000; font-family: Ro=
boto-Medium,Helvetica,Arial,sans-serif; font-weight: bold; text-decoration:=
 none;}.adgl a {color: rgba(0, 0, 0, 0.87); text-decoration: none;}.afal a =
{color: #b0b0b0; text-decoration: none;}@media screen and (min-width: 600px=
) {.v2sp {padding: 6px 30px 0px;} .v2rsp {padding: 0px 10px;}}</style></hea=
d>

还有几行来自GMAIL api GET 方法:

<html lang=en><head><meta content="date=no" name="format-detection"><meta 
 content="email=no" name="format-detection"><style>.awl a {color: #FFFFFF; 
 text-decoration: none;}.abml a {color: #000000; font-family: Roboto-
 Medium,Helvetica,Arial,sans-serif; font-weight: bold; text-decoration: 
 none;}.adgl a {color: rgba(0, 0, 0, 0.87); text-decoration: none;}.afal a 
 {color: #b0b0b0; text-decoration: none;}@media screen and (min-width: 
 600px) {.v2sp {padding: 6px 30px 0px;} .v2rsp {padding: 0px 10px;}}</style> 
 </head>`

虽然Gmail api GET 方法返回base64 encode 版本,但我通过以下方式进行转换:

function decode($data)
{
    return base64_decode(str_pad(strtr($data, '-_', '+/'), strlen($data) % 4, '=', STR_PAD_RIGHT));
}

两者之间到底有什么区别?为什么真的有区别?

Screen shot of the mail fetched through gmail api

Screen shot of the mail fetched through imap_fetchbody

您的 cmets 和答案将受到赞赏。

谢谢

【问题讨论】:

    标签: php encryption imap gmail-api mbox


    【解决方案1】:

    两者的区别在于imap_fetchbody返回:

    它是带引号的可打印文本,可能是通过“哑”邮件客户端的结果。 = 用于编码/转义不可打印/元字符,很像 &...;在 HTML 中使用。 =3d 是 = 的引用可打印表示:3d hex = 61 ascii = 等号。

    参考:imap_fetchbody HTML with strange chars

    Gmail api GET 方法返回base64_encoded 字符串,它需要是decoded。我们可以通过以下方式添加相同的quoted-printable 效果:

    quoted_printable_encode($string)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-02
      • 2021-03-25
      • 2018-09-29
      • 2015-09-16
      • 2020-09-02
      • 2019-11-04
      • 1970-01-01
      • 2020-10-27
      相关资源
      最近更新 更多