这份标准讲文本消息格式标准,现在已经被RFC 2822取代
摘要:
整体来看, 消息内容包含信封和信件体. 信封包含的信息用来完成传送和投递. 信件体是由需要投递给收件人的信息元素组成. 本标准只涉及信件体,没有定义信封相关的信息(注:熟悉SMTP协议的就清楚,协议上的MAIL FROM:, RCPT TO:就是信封, 而DATA后的MIME是信件体, 本协议只是定义信件体)。
本标准使用了一种扩展的巴克斯范式(BNF)
命令规则
"foo / bar"表示foo和bar都满足条件.
"(elem (foo / bar) elem)" 可以是"elem foo elem",也可以是"elem bar elem"
星号 "*" 代表星号之后的一个元素的重复. 完整的语法是<最小次数>*<最大次数>元素."1*(元素)"代表元素被重复1到任意次,"1*2(元素)"代表重复一次或者两次.
<最小次数>#<最大次数>元素 代表元素被重复至少<最小次数>次,最多<最大次数>次
方括号里的元素, 表示可有可无, "[foo bar]" 等价于 "*1(foo bar)"
"<n>(元素)" 等价于 "<n>*<n>(元素)", 表示元素被重复n次
分号表示注释, 从分号的位置到行尾都是注释.
消息头
To: "Joe & J. Harvey" <ddd @Org>, JJV @ BBN
消息头的内容折行的规则是: 在CRLF(注:回车换行)之后紧跟至少一个LWSP-char(注:LSWP-char指空格或者制表符tab).(注:消息头的名字里不能有空格,消息头必须顶格写,所以正常的消息头是不会出现行开始就是空格的情况, 如果出现,就是上一行的继续)
消息头域,由两部分组成,用冒号(":")分开,左边是名称右边是域的内容,最后由回车换行(CRLF)结束.
一些消息头域的内容部分,可能还需要再次解释,它们有自己的内部语法(注:如地址被编码为<?GB18030?B?suLK1A==?=>).这样的域叫结构化域("structured fields"),例如包含时间和地址的域.
消息头域的名称,结构化和非结构化域的消息头内容,会使用不同的,各自独立的词法分析器
非结构化的消息头域内容:
一些消息头的域,如"Subject"和"Comments",在消息体里,会被假设为非结构的内容,它们被当作文本来处理。
结构化的消息头域内容:
折行字符(注:linear-white-space 就是1*([CRLF] LWSP-char))允许出现在词和词的中间.
结构化元素包括:
- individual special characters
- quoted-strings
- domain-literals
- comments
- atoms前四种是"本身可以确定分割界限的"(self-delimiting),atoms不可以;
例子:
":sysmail"@ Some-Group. Some-Org,
Muhammed.(I am the greatest) Ali @(the)Vegas.WBA解析:
:sysmail quoted string
规范的表述这个地址的方法如下:
@ special
Some-Group atom
. special
Some-Org atom
, special
Muhammed atom
. special
(I am the greatest) comment
Ali atom
@ atom
(the) comment
Vegas atom
. special
WBA atom":sysmail"@Some-Group.Some-Org
和
Muhammed.Ali@Vegas.WBA
消息头域定义
field = field-name ":" [ field-body ] CRLF
field-name = 1*<any CHAR, excluding CTLs, SPACE, and ":">
field-body = field-body-contents
field-body-contents = ASCII字符组成了域主体,由atom,quoted-strings,individual special characters和其他的文本联合组成域内容>
[CRLF LWSP-char field-body]词标记定义:
CHAR = <any ASCII character> ; ( 0-177, 0.-127.)
ALPHA = <any ASCII alphabetic character>
; (101-132, 65.- 90.)
; (141-172, 97.-122.)
DIGIT = <any ASCII decimal digit> ; ( 60- 71, 48.- 57.)
CTL = <any ASCII control character and DEL>
; ( 0- 37, 0.- 31.)
; ( 177, 127.)
CR = <ASCII CR, carriage return> ; ( 15, 13.)
LF = <ASCII LF, linefeed> ; ( 12, 10.)
SPACE = <ASCII SP, space> ; ( 40, 32.)
HTAB = <ASCII HT, horizontal-tab> ; ( 11, 9.)
<"> = <ASCII quote mark> ; ( 42, 34.)
CRLF = CR LFLWSP-char = SPACE / HTAB ; semantics = SPACE
linear-white-space = 1*([CRLF] LWSP-char) ; semantics = SPACE
; CRLF => foldingspecials = "(" / ")" / "<" / ">" / "@" ; Must be in quoted-
/ "," / ";" / ":" / "/" / <"> ; string, to use
/ "." / "[" / "]" ; within a word.delimiters = specials / linear-white-space / comment
text = <any CHAR, including bare ; => atoms, specials,
CR & bare LF, but NOT ; comments and
including CRLF> ; quoted-strings are
; NOT recognized.atom = 1*<any CHAR except specials, SPACE and CTLs>
quoted-string = <"> *(qtext/quoted-pair) <">; Regular qtext or
; quoted chars.qtext = <any CHAR excepting <">, ; => may be folded
domain-literal = "[" *(dtext / quoted-pair) "]"
"/" & CR, and including
linear-white-space>
以上整理,原文来自于http://blog.csdn.net/ancienttale/article/details/1815996
TODO:
RFC 2821 - 简单邮件传输协议,在2001代替了RFC 821,RFC 1869,RFC 974
RFC 2822 - Internet(比如 e-mail)消息格式,代替了RFC 822
RFC 3461 - SMTP的发送状态通知(DSN)扩展,代替了RFC 1891