【发布时间】:2017-01-27 22:21:29
【问题描述】:
除了another StackOverflow question 中提到的奇怪的标记消失问题之外,我还注意到一些奇怪的编码问题,其中一些字符被随机字母替换。当标记中有很长的行时,这似乎会发生。以下是示例:
正常行为
处理 Gmail API 之前
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Email Title</title>
</head>
<body>
<p style="font-size: 16px; line-height: 24px; margin-top: 0; margin-bottom: 0; font-family: 'ff-tisa-web-pro, Georgia, serif;">Pinterest mumblecore authentic stumptown, deep v slowcarb skateboard Intelligentsia food truck VHS. Asymmetrical swag raw denim put a bird on it Echo Park. Pinterest four loko lofi forage gentrify cray.</p>
</body>
</html>
Gmail API 处理后(通过在 Gmail 中打开邮件,然后选择Show original)。
--001a1133f016eff52804ff2a2885
Content-Type: text/html; charset=ISO-8859-1
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Email Title</title>
</head>
<body>
<p style>Pinterest mumblecore authentic stumptown, deep v slowcarb skateboard Intelligentsia food truck VHS. Asymmetrical swag raw denim put a bird on it Echo Park. Pinterest four loko lofi forage gentrify cray.</p>
</body>
</html>
--001a1133f016eff52804ff2a2885--
在上面的例子中,发生的事情是我们所期望的。但是,一旦p 元素的行长变长,我们就会出现异常行为。
奇怪的行为
处理 Gmail API 之前
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Email Title</title>
</head>
<body>
<p style="font-size: 16px; line-height: 24px; margin-top: 0; margin-bottom: 0; font-family: 'ff-tisa-web-pro, Georgia, serif;">Pinterest mumblecore authentic stumptown, deep v slowcarb skateboard Intelligentsia food truck VHS. Asymmetrical swag raw denim put a bird on it Echo Park. Pinterest four loko lofi forage gentrify cray. Pinterest mumblecore authentic stumptown, deep v slowcarb skateboard Intelligentsia food truck VHS. Asymmetrical swag raw denim put a bird on it Echo Park. Pinterest four loko lofi forage gentrify cray.</p>
</body>
</html>
Gmail API 处理后(通过在 Gmail 中打开邮件,然后选择Show original)。
--001a1133547278e12e04ff2a28d8
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<html>
<head>
<meta name=3D"viewport" content=3D"width=3Ddevice-width, initial-scale=
=3D1.0">
<title>Email Title</title>
</head>
<body>
<p style>Pinterest mumblecore authentic stumptown, deep v slowcarb skat=
eboard Intelligentsia food truck VHS. Asymmetrical swag raw denim put a bir=
d on it Echo Park. Pinterest four loko lofi forage gentrify cray. Pinterest=
mumblecore authentic stumptown, deep v slowcarb skateboard Intelligentsia =
food truck VHS. Asymmetrical swag raw denim put a bird on it Echo Park. Pin=
terest four loko lofi forage gentrify cray.</p>
</body>
</html>
--001a1133547278e12e04ff2a28d8--
在上面的示例中,p 元素内的字符数增加了一倍。不知何故,这会触发各种奇怪的编码问题。请注意,添加了关于标记的Content-Transfer-Encoding: quoted-printable。另请注意,3D 出现在每个 = 之后。此外,p 元素中添加了硬换行符。在每一行的末尾都有一个= 符号。
如何防止这种情况发生?
【问题讨论】:
-
我不知道如何防止这种情况,但这很像我所有电子邮件存储在我电脑上的格式。 (我正在使用一个使用
Maildir来存储消息的客户端。) -
顺便说一句:转义的不仅是换行符和等号,还有元音变音(自己试试:äöüß)。
-
啊,在那个话题上找到了Wikipedia article。
-
电子邮件是否正确呈现?如果是这样,那么确切的传输机制就不应该那么重要了。