使用 encoded-words 的 MIME headers 中的换行是否合法?
Are newlines in MIME headers using encoded-words legal?
RFC 2047 定义了 encoded-words 机制,用于对 MIME 文档中的 non-ASCII 字符进行编码。它指定 encoded-word.
中不允许使用白色 space 字符(space 和制表符)
但是,RFC 5322 用于解析电子邮件 MIME 文档指定应“折叠”较长的 header 行。这种折叠应该发生在 encoded-words 解码之前还是之后?
我最近收到一封电子邮件,其中 encoded-text 部分 header 中有换行符,如下所示:
Header: =?UTF-8?Q?=C3=A5
=C3=A4?=
这有效吗?
当然,电子邮件可能以许多令人兴奋的方式无效,解析器需要处理它,但了解“正确”方式很有趣。 :)
我看错了问题,回答的好像是另一种白人space。在这种情况下,白色 space 出现在 MIME 字内,而不是由白色 space.
分隔的多个字
明确禁止这种事情。从RFC2047中对格式的介绍:
2. Syntax of encoded-words
An 'encoded-word' is defined by the following ABNF grammar. The
notation of RFC 822 is used, with the exception that white space
characters MUST NOT appear between components of an 'encoded-word'.
稍后在同一部分:
IMPORTANT: 'encoded-word's are designed to be recognized as 'atom's
by an RFC 822 parser. As a consequence, unencoded white space
characters (such as SPACE and HTAB) are FORBIDDEN within an
'encoded-word'. For example, the character sequence
=?iso-8859-1?q?this is some text?=
would be parsed as four 'atom's, rather than as a single 'atom' (by
an RFC 822 parser) or 'encoded-word' (by a parser which understands
'encoded-words'). The correct way to encode the string "this is some
text" is to encode the SPACE characters as well, e.g.
=?iso-8859-1?q?this=20is=20some=20text?=
The characters which may appear in 'encoded-text' are further
restricted by the rules in section 5.
较早的回答
这种事情是明确允许的。 Headers with MIME words 应为 76 个字符或更少,并在需要时折叠。 RFC822 folded headers 缩进第二行和任何其他行。 RFC2047 headers 应该只缩进一个 space。第一行 ?= 和 =? 之间的 whitespace应该从输出中抑制。
参见 RFC 第 12 页底部的示例:
encoded form displayed as
---------------------------------------------------------------------
(=?ISO-8859-1?Q?a?= (ab)
=?ISO-8859-1?Q?b?=)
Any amount of linear-space-white between 'encoded-word's,
even if it includes a CRLF followed by one or more SPACEs,
is ignored for the purposes of display.
RFC 2047 定义了 encoded-words 机制,用于对 MIME 文档中的 non-ASCII 字符进行编码。它指定 encoded-word.
中不允许使用白色 space 字符(space 和制表符)但是,RFC 5322 用于解析电子邮件 MIME 文档指定应“折叠”较长的 header 行。这种折叠应该发生在 encoded-words 解码之前还是之后?
我最近收到一封电子邮件,其中 encoded-text 部分 header 中有换行符,如下所示:
Header: =?UTF-8?Q?=C3=A5
=C3=A4?=
这有效吗?
当然,电子邮件可能以许多令人兴奋的方式无效,解析器需要处理它,但了解“正确”方式很有趣。 :)
我看错了问题,回答的好像是另一种白人space。在这种情况下,白色 space 出现在 MIME 字内,而不是由白色 space.
分隔的多个字明确禁止这种事情。从RFC2047中对格式的介绍:
2. Syntax of encoded-words
An 'encoded-word' is defined by the following ABNF grammar. The
notation of RFC 822 is used, with the exception that white space
characters MUST NOT appear between components of an 'encoded-word'.
稍后在同一部分:
IMPORTANT: 'encoded-word's are designed to be recognized as 'atom's
by an RFC 822 parser. As a consequence, unencoded white space
characters (such as SPACE and HTAB) are FORBIDDEN within an
'encoded-word'. For example, the character sequence
=?iso-8859-1?q?this is some text?=
would be parsed as four 'atom's, rather than as a single 'atom' (by
an RFC 822 parser) or 'encoded-word' (by a parser which understands
'encoded-words'). The correct way to encode the string "this is some
text" is to encode the SPACE characters as well, e.g.
=?iso-8859-1?q?this=20is=20some=20text?=
The characters which may appear in 'encoded-text' are further
restricted by the rules in section 5.
较早的回答
这种事情是明确允许的。 Headers with MIME words 应为 76 个字符或更少,并在需要时折叠。 RFC822 folded headers 缩进第二行和任何其他行。 RFC2047 headers 应该只缩进一个 space。第一行 ?= 和 =? 之间的 whitespace应该从输出中抑制。
参见 RFC 第 12 页底部的示例:
encoded form displayed as
---------------------------------------------------------------------
(=?ISO-8859-1?Q?a?= (ab)
=?ISO-8859-1?Q?b?=)
Any amount of linear-space-white between 'encoded-word's,
even if it includes a CRLF followed by one or more SPACEs,
is ignored for the purposes of display.