跳到主要内容

4.1.2. 命令语法

命令由一个命令码后接一个参数字段组成。命令码为四个字母字符。大写和小写字母字符应被同等对待。因此,以下任何一种写法都可以表示 mail 命令:

MAIL    Mail    mail    MaIl    mAIl

这同样适用于表示参数值的任何符号,例如前向路径中的 "TO" 或 "to"。命令码与参数字段之间用一个或多个空格分隔。不过,在反向路径和前向路径参数内部,大小写是有意义的。特别是在某些主机上,用户 "smith" 与用户 "Smith" 是不同的。

参数字段由以字符序列 <CRLF> 结尾的变长字符串组成。在收到该序列之前,接收方不应采取任何动作。

方括号表示可选的参数字段。如果不选用该选项,则隐含采用相应的默认值。

以下是 SMTP 命令:

HELO <SP> <host> <CRLF>

MAIL <SP> FROM:<reverse-path> <CRLF>

RCPT <SP> TO:<forward-path> <CRLF>

DATA <CRLF>

RSET <CRLF>

SEND <SP> FROM:<reverse-path> <CRLF>

SOML <SP> FROM:<reverse-path> <CRLF>

SAML <SP> FROM:<reverse-path> <CRLF>

VRFY <SP> <string> <CRLF>

EXPN <SP> <string> <CRLF>

HELP [<SP> <string>] <CRLF>

NOOP <CRLF>

QUIT <CRLF>

上述参数字段的语法(适用处采用 BNF 记法)如下。"..." 记法表示一个字段可以重复一次或多次。

<reverse-path> ::= <path>

<forward-path> ::= <path>

<path> ::= "<" ["@" <host> "," ...] <mailbox> ">"

<host> ::= <a> <string> | "#" <number> | "[" <dotnum> "]"

<mailbox> ::= <user> "@" <host>

<user> ::= <string>

<string> ::= <char> | <char> <string>

<char> ::= <c> | '\' <c> | '\' <s>

<dotnum> ::= <snum> "." <snum> "." <snum> "." <snum>

<number> ::= <d> | <d> <number>

<snum> ::= three digits representing a decimal integer value
in the range 0 through 255

<a> ::= any one of the 52 alphabetic characters A through Z
in upper case and a through z in lower case

<c> ::= any one of the 128 ASCII characters except
<specials>

<d> ::= any one of the ten digits 0 through 9

<s> ::= any one of <specials>

<specials> ::= '<', '>', '(', ')', '\', ',', ';', ':', '@',
'"', and the control characters (ASCII codes 0 through 37
octal inclusive and 177 octal)

注意,反斜杠 '\' 是引用字符,用来表示下一个字符按字面使用(而不是按其通常含义解释)。例如,"Joe\,Smith" 可用来表示一个共九个字符的用户字段,其中逗号是该字段的第四个字符。

主机通常以名称为人所知,名称会在各主机中被转换为地址。有时转换功能并不认识某台主机,通信因此受阻。为绕过这一障碍,主机的“名称”还允许使用两种数字形式。一种是以井号 "#" 为前缀的十进制整数,表示该数字是主机的地址。另一种是由点分隔并用方括号括起的四个小十进制整数,例如 "[123.255.37.2]",表示由四个 8 位字段组成的 32 位 ARPA 互联网地址。

时间戳行和返回路径行的正式定义如下:

<return-path-line> ::= "Return-Path:" <SP><reverse-path><CRLF>

<time-stamp-line> ::= "Mail-From:" <SP> <stamp> <CRLF>

<stamp> ::= [<ptcl>] <from-host> <this-host> <daytime>

<ptcl> ::= <protocol> <SP> "host" <SP>

<from-host> ::= <host> <SP>

<this-host> ::= "received by" <SP> <host> <SP>

<protocol> ::= "TCP" | "NCP" | "NITS" | "X25" | "INTERNET" |
"ARPANET"

Note: INTERNET = TCP, ARPANET = NCP, and if the <ptcl> is
not present INTERNET is assumed.

<daytime> ::= "at" <SP> <date> <SP> <time>

<date> ::= <dd> "-" <mon> "-" <yy>

<time> ::= <hh> ":" <mm> ":" <ss> "-" <zone>

<dd> ::= the one or two decimal integer day of the month in
the range 1 to 31.

<mon> ::= "JAN" | "FEB" | "MAR" | "APR" | "MAY" | "JUN" |
"JUL" | "AUG" | "SEP" | "OCT" | "NOV" | "DEC"

<yy> ::= the two decimal integer year of the century in the
range 01 to 99.

<hh> ::= the two decimal integer hour of the day in the
range 00 to 24.

<mm> ::= the two decimal integer minute of the hour in the
range 00 to 59.

<ss> ::= the two decimal integer second of the minute in the
range 00 to 59.

<zone> ::= a time zone designator (as in [2]) or "UT" for
Universal Time (the default).

返回路径示例:

Return-Path: <@CHARLIE,@BAKER,JOE@ABLE>

Mail From 示例:

Mail-From: ABC received by XYZ at 22-OCT-81 09:23:59-PDT