Skip to main content

Appendix A. Collected Grammar (语法汇总)

本附录包含RFC 2046中定义的媒体类型语法规则的完整BNF语法.

Media Type语法

media-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

x-token = <The two characters "X-" or "x-" followed, with
no intervening white space, by any token>

ietf-token = <An extension token defined by a
standards-track RFC and registered
with IANA.>

subtype = extension-token / iana-token

iana-token = <A publicly-defined extension token>

parameter = attribute "=" value

attribute = token

value = token / quoted-string

Multipart语法

boundary := 0*69<bchars> bcharsnospace

bchars := bcharsnospace / " "

bcharsnospace := DIGIT / ALPHA / "'" / "(" / ")" /
"+" / "_" / "," / "-" / "." /
"/" / ":" / "=" / "?"

dash-boundary := "--" boundary

close-delimiter := delimiter "--"

delimiter := CRLF dash-boundary

discard-text := *(*text CRLF)

preamble := discard-text

epilogue := discard-text

body-part := MIME-part-headers [CRLF *OCTET]

encapsulation := delimiter
body-part

multipart-body := [preamble]
dash-boundary CRLF
body-part
*encapsulation
close-delimiter
[epilogue]

注释:

  • 此语法与RFC 2045和RFC 822结合使用
  • 完整的语法需要参考所有相关RFC
  • IANA维护注册的媒体类型列表