imap_fetchbody 与 Gmail api 获取方法
imap_fetchbody vs Gmail api get method
return格式与htmlimap_fetchbody vs Gmail api GET方法不同。
我将电子邮件写入一个文件,然后重新导入 Thunderbird。 imap_fetchbody
的书面电子邮件被加载到 Thunderbird 而没有填充问题,而同一电子邮件 return 由 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
方法 returns 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
您的评论和回答将被采纳。
谢谢
两者的区别在于imap_fetchbody
returns:
It's quoted-printable text, probably the result of passing through a "dumb" mail client. = is used to encode/escape unprintable/metacharacters, much like &...; is used in HTML.
=3d is the quoted-printable representation of an =: 3d hex = 61 ascii = equals sign.
参考:imap_fetchbody HTML with strange chars
虽然 Gmail api GET
方法 returns base64_encoded
需要 decoded
的字符串。我们可以通过以下方式添加相同的 quoted-printable
效果:
quoted_printable_encode($string)
return格式与htmlimap_fetchbody vs Gmail api GET方法不同。
我将电子邮件写入一个文件,然后重新导入 Thunderbird。 imap_fetchbody
的书面电子邮件被加载到 Thunderbird 而没有填充问题,而同一电子邮件 return 由 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
方法 returns 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
您的评论和回答将被采纳。
谢谢
两者的区别在于imap_fetchbody
returns:
It's quoted-printable text, probably the result of passing through a "dumb" mail client. = is used to encode/escape unprintable/metacharacters, much like &...; is used in HTML. =3d is the quoted-printable representation of an =: 3d hex = 61 ascii = equals sign.
参考:imap_fetchbody HTML with strange chars
虽然 Gmail api GET
方法 returns base64_encoded
需要 decoded
的字符串。我们可以通过以下方式添加相同的 quoted-printable
效果:
quoted_printable_encode($string)