跳到主要内容

MTP 应答

邮件传输协议命令的应答,旨在确保邮件传输过程中请求与动作的同步,并保证发送方 MTP 始终知道接收方的状态。每条命令必须至少产生一个应答,也可以有多个。在后一种情况下,多个应答必须易于区分。此外,某些命令必须按顺序出现,例如 MRSQ T->MAIL->MRCP 或 MRSQ R->MRCP->MAIL。如果之前的所有命令都已成功,对这些序列的应答会表明存在一个中间状态。序列中任一环节失败,都必须从头重复整个序列。

命令-应答序列的细节在"状态图"一节中给出。

MTP 应答由一个三位数字(以三个字母数字字符传送)和后续的一些文本组成。数字供自动机判断下一步进入什么状态;文本则供人阅读。其意图是让这三位数字包含足够的编码信息,使发送方 MTP 无需检查文本,可以丢弃它,也可以酌情转交给用户。特别是,文本可能因接收方而异,因此每个应答码很可能对应多种不同的文本。

形式上,应答被定义为如下序列:一个三位数字代码、空格 <SP>、一行文本(最大行长为 65)和结尾的 <CRLF>。有时文本长于一行;在这种情况下,完整的文本必须加以括定,使发送方 MTP 知道何时可以停止读取应答。这需要用一种特殊的首行格式表示多行应答,并在末行用另一种格式加以标明。这两行都将包含表示事务状态的相应应答码。

因此,多行应答的格式是:第一行以所要求的确切应答码开头,紧跟连字符 "-"(也称减号),再跟文本。最后一行以相同的代码开头,紧跟空格 <SP>,可选地跟一些文本,最后是 <CRLF>。

例如:

123-First line
Second line
234 A line beginning with numbers
123 The last line

发送方 MTP 只需查找行首第二次出现的、后跟 <SP>(空格>的同一应答码,并忽略所有中间行。如果某个中间行以三位数字开头,接收方必须在其前面填充内容以免混淆。

这一方案允许使用标准系统例程生成应答信息,只需在前后加上"人为的"首行和末行。在这些例程偶尔能在任何一行开头生成三位数字加一个空格的少数情况下,每个文本行的开头应以某些中性文本(如空格)作偏移。

这一方案假定多行应答不得嵌套。一般而言,除随机的系统消息(也称自发应答)可能打断另一个应答外,不会出现应答嵌套。系统消息(即不由接收方 MTP 处理的消息)不带应答码,可以出现在命令-应答序列的任何位置。发送方 MTP 可以忽略它们,因为它们只是给用户看的信息。

应答的三位数字各有特殊含义。这样设计是为了让发送方 MTP 能够做出从极简单到极复杂的各种响应。第一位数字表明响应是好、坏还是未完成。(参照状态图)不太复杂的发送方 MTP 只需检查这第一位数字,就能确定下一步动作(按计划继续、重做、收缩等)。若发送方 MTP 想大致了解发生了哪类错误(例如邮件系统错误、命令语法错误),可以检查第二位数字,而把第三位数字留给最精细的信息分级。

应答码的第一位数字有五个取值:

1yz 肯定的预备应答(Positive Preliminary reply)

所请求的动作正在启动;在继续发送新命令之前,应期待另一个应答。(发送方 MTP 在完成应答之前发送另一条命令,就违反了协议。不过,接收方 MTP 进程应当把前一条命令进行期间到达的任何命令排入队列。)

2yz 肯定的完成应答(Positive Completion reply)

所请求的动作已成功完成。可以发起新的请求。

3yz 肯定的中间应答(Positive Intermediate reply)

命令已被接受,但所请求的动作被搁置,等待接收更多信息。发送方 MTP 应发送另一条命令来指明这些信息。此应答用于命令序列组。

4yz 暂时性否定完成应答(Transient Negative Completion reply)

命令未被接受,所请求的动作未发生。但是,该错误状况是暂时的,可以再次请求该动作。发送方应回到命令序列(若有)的开头。当两个不同站点(接收方 MTP 和发送方 MTP)必须就解释达成一致时,很难为"暂时性"赋予确切含义。此类别中的每个应答可能有不同的时间值,但鼓励发送方 MTP 重试。判断某个应答属于 4yz 还是 5yz 类别(见下文)的经验法则是:如果无需改变命令形式,也无需改变发送方或接收方的属性就能重复,则该应答为 4yz。(例如,命令原样重复;接收方不会推出新的实现。)

5yz 永久性否定完成应答(Permanent Negative Completion reply)

命令未被接受,所请求的动作未发生。不鼓励发送方 MTP 重复完全相同的请求(在同一序列中)。即使某些"永久性"错误状况也是可以纠正的,因此用户可能希望在将来某个时刻,通过直接操作指示发送方 MTP 重新发起命令序列(例如,在拼写修改之后,或用户更改了其目录状态之后)。

第二位数字对特定类别的响应进行编码:

x0z   Syntax -- These replies refer to syntax errors,
syntactically correct commands that don't fit any
functional category, and unimplemented or superfluous
commands.

x1z Information -- These are replies to requests for
information, such as status or help.

x2z Connections -- These are replies referring to the control
connection.

x3z Unspecified as yet.

x4z Unspecified as yet.

x5z Mail system -- These replies indicate the status of the
receiver mail system vis-a-vis the requested transfer or
other mail system action.

第三位数字在第二位数字所规定的每个类别内给出更精细的含义分级。下面的应答列表将说明这一点。每条应答文本是推荐的而非强制的,甚至可以随其关联的命令而变化。另一方面,应答码必须严格遵守本节的规定。接收方的实现不应为与此处所述略有不同的情形发明新代码,而应调整使用已经定义的代码。

像 NOOP 这样成功执行后不向发送方 MTP 提供任何新信息的命令,将返回 200 应答。当命令请求的是未实现的、与具体站点无关的动作时,响应为 502。对此的细化是 504 应答,用于已实现但请求了未实现参数的命令。

按功能分组的应答码​

200 Command okay
500 Syntax error, command unrecognized
[This may include errors such as command line too long]
501 Syntax error in parameters or arguments
502 Command not implemented
503 Bad sequence of commands

211 System status, or system help reply
214 Help message
[Information on how to use the receiver or the meaning of a
particular non-standard command; this reply is useful only to
the human user]
215 <scheme> is the preferred scheme

120 <host> Service ready in nnn minutes
220 <host> Service ready for new user
221 <host> Service closing control connection
421 <host> Service not available, closing control connection
[This may be a reply to any command if the service knows it
must shut down]

151 User not local; will forward to <user>@<host>
152 User unknown; mail will be forwarded by the operator
250 Requested mail action okay, completed
450 Requested mail action not taken: mailbox unavailable
[E.g., mailbox busy]
550 Requested action not taken: mailbox unavailable
[E.g., mailbox not found, no access]
451 Requested action aborted: local error in processing
452 Requested action not taken: insufficient system storage space
552 Requested mail action aborted: exceeded storage allocation
[For current mailbox location]
553 Requested action not taken: mailbox name not allowed
354 Start mail input; end with <CR><LF>.<CR><LF>

应答码的数字顺序列表​

120 <host> Service ready in nnn minutes
151 User not local; will forward to <user>@<host>
152 User unknown; mail will be forwarded by the operator
200 Command okay
211 System status, or system help reply
214 Help message
[Information on how to use the receiver or the meaning of a
particular non-standard command; this reply is useful only to
the human user]
215 <scheme> is the preferred scheme
220 <host> Service ready for new user
221 <host> Service closing control connection
250 Requested mail action okay, completed
354 Start mail input; end with <CR><LF>.<CR><LF>
421 <host> Service not available, closing control connection
[This may be a reply to any command if the service knows it
must shut down]
450 Requested mail action not taken: mailbox unavailable
[E.g., mailbox busy]
451 Requested action aborted: local error in processing
452 Requested action not taken: insufficient system storage space
500 Syntax error, command unrecognized
[This may include errors such as command line too long]
501 Syntax error in parameters or arguments
502 Command not implemented
503 Bad sequence of commands
550 Requested action not taken: mailbox unavailable
[E.g., mailbox not found, no access]
552 Requested mail action aborted: exceeded storage allocation
[For current mailbox location]
553 Requested action not taken: mailbox name not allowed