附录 A. 汇总语法 (Collected Grammar)
本附录包含 RFC 2045 中定义的所有 MIME 语法规则的完整 BNF 语法.
这些 ABNF/BNF 片段是 MIME 头字段解析规则的一部分, 因此规则名、字面量、终结符和引用符号保持原文. 中文标题用于帮助读者定位语法区域, 不改变语法定义.
MIME 头字段
MIME-message-headers := entity-headers
fields
version CRLF
entity-headers := [ content CRLF ]
[ encoding CRLF ]
[ id CRLF ]
[ description CRLF ]
*( MIME-extension-field CRLF )
version := "MIME-Version" ":" 1*DIGIT "." 1*DIGIT
Content-Type
content := "Content-Type" ":" type "/" subtype
*(";" parameter)
type := discrete-type / composite-type
discrete-type := "text" / "image" / "audio" / "video" /
"application" / extension-token
composite-type := "message" / "multipart" / extension-token
extension-token := ietf-token / x-token
ietf-token := <An extension token defined by a
standards-track RFC and registered
with IANA.>
x-token := <The two characters "X-" or "x-" followed, with
no intervening white space, by any token>
subtype := extension-token / iana-token
iana-token := <A publicly-defined extension token.>
parameter := attribute "=" value
attribute := token
value := token / quoted-string
token := 1*<any (US-ASCII) CHAR except SPACE, CTLs,
or tspecials>
tspecials := "(" / ")" / "<" / ">" / "@" /
"," / ";" / ":" / "\" / <">
"/" / "[" / "]" / "?" / "="
Content-Transfer-Encoding
encoding := "Content-Transfer-Encoding" ":" mechanism
mechanism := "7bit" / "8bit" / "binary" /
"quoted-printable" / "base64" /
ietf-token / x-token
Content-ID
id := "Content-ID" ":" msg-id
Content-Description
description := "Content-Description" ":" *text
说明:
- 此语法与 RFC 822 的 BNF 结合使用
- 一些规则引用 RFC 822 中定义的术语
- 完整语法需要参考 RFC 822 和 RFC 1123
- 实现解析器时应按语法规则处理大小写、特殊字符、quoted-string 和扩展 token, 不应翻译代码块中的任何符号