2

Is an email with different character encoding for it's header and body valid? The Use Case: While processing an email, should I check for the character encoding of it's header separately, or will checking that of it's body be sufficient? Can someone guide me as to how to figure this out? Thanks in advance!

4

1 回答 1

9

电子邮件标头应使用 ASCII 字符集,如果您希望标头字段具有不同的编码,则需要使用编码字语法:http ://en.wikipedia.org/wiki/MIME#Encoded-Word

仅当传输它的邮件服务器启用了 8 位 mime 时,电子邮件正文才能直接以不同的编码进行编码(现在每个邮件服务器都应该启用它,但不能保证),否则您需要在传输编码中对正文进行编码(引用 -可打印或base64)

每种情况下的字符集都可以不同,也就是说,您可以将每个编码的单词放在不同的字符集中,将每个邮件部分编码为不同的字符集,甚至也可以使用不同的传输编码。

例如,您可以拥有:

Subject: =?UTF-8?Q?Zg=C5=82oszenie?= //header value in UTF-8 encoded with quoted printable

和正文编码:

Content-Type: text/plain; charset="iso-8859-2"
Content-Transfer-Encoding: base64

WmG/87PmIEfqtmyxIEphvPE=

不同的字符集,同一封电子邮件中的不同传输编码,没问题。

根据经验,我可以告诉您,此类邮件非常普遍。更糟糕的是,您会收到一封电子邮件,其中在 Content-Type 标头中声明一个字符集,在 html 正文元标记中声明另一个字符集:

Content-Type: text/html; charset="iso-8859-2"

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charser=utf-8">

由您来猜测使用的实际字符集。可能是元标记中的那个。

假设什么。期待一切。不要俘虏。这是斯巴达。

于 2014-11-20T14:01:04.553 回答