跳到主要内容

2. encoded-words 的语法

"encoded-word" 由下列 ABNF 语法定义. 使用的是 RFC 822 的记法, 但有一个例外: encoded-word 各组成部分之间 MAY NOT 出现空白字符.

encoded-word = "=?" charset "?" encoding "?" encoded-text "?="
charset = token    ; see section 3
encoding = token   ; see section 4
token = 1*<Any CHAR except SPACE, CTLs, and especials>
especials = "(" / ")" / "<" / ">" / "@" / "," / ";" / ":" / "
<"> / "/" / "[" / "]" / "?" / "." / "="
encoded-text = 1*<Any printable ASCII character other
than "?" or SPACE>
; (but see "Use of encoded-words in message
; headers", section 5)

"encoding" 和 "charset" 的名称都与大小写无关. 因此, charset 名称 "ISO-8859-1" 等价于 "iso-8859-1", 而名为 "Q" 的编码可以写成 "Q" 或 "q".

encoded-word 的长度不得超过 75 个字符, 其中包括 charset, encoding, encoded-text 和定界符. 如果要编码的文本多到一个 75 字符的 encoded-word 容纳不下, 可以使用多个 encoded-word (以 CRLF SPACE 分隔).

虽然多行头字段的长度没有限制, 但包含一个或多个 encoded-word 的头字段的每一行限制为 76 个字符.

设置这些长度限制, 不仅是为了便于经由网间邮件网关 (internetwork mail gateway) 实现互操作, 也是为了限制头解析器在判定某个 token 是 encoded-word 还是其他东西之前所必须使用的前视 (lookahead) 量 (在寻找结尾的 ?= 定界符时).

encoded-text 中可出现的字符还受到第 5 节规则的进一步限制.