POP3命令详解

   服务器通过监听TCP端口110来启动POP3服务,当客户机与服务器连接后互相交换命令与响应。POP3的命令包括区分大小写的关键字,可能包括一个或多个参数。关键字与参数包括可打印的ASCII字符,之间由单个空格分开。关键字为三或四个字符长,每个参数最长为40个字符。
  POP3的响应最长512个字符,以CRLF结束。有肯定与否定两种状态,分别用+OK与+ERR来表示。某些命令的响应可能有多行,这时在最后一行用单个"."字符结束。
  一个POP3的对话在生存期经历几个状态,当连接刚建立POP3服务器发送了问候之后,对话进入了认证状态(AUTHORIZATION)。这时客户必须登录,成功完成后对话进入了事务状态(TRANSACTION)。当客户发出QUIT命令后,对话进入了更新状态(UPDATE),这时POP3服务器释放此连接所有的资源并且关闭连接。


  POP3命令概要:
    最小POP3命令集:

         USER name               在AUTHORIZATION状态下有效
         PASS string
         QUIT

         STAT                    在TRANSACTION状态下有效
         LIST [msg]
         RETR msg
         DELE msg
         NOOP
         RSET
         QUIT
    可选POP3命令:

         APOP name digest        在AUTHORIZATION状态下有效

         TOP msg n               在TRANSACTION状态下有效
         UIDL [msg]

      POP3响应:

         +OK
         -ERR

  POP3命令详解:
      USER name
         参数:
             一个标识信箱的字符串,仅对服务器有意义
         限制:
             只能用在AUTHORIZATION状态下,当得到POP3欢迎信息后或者
             在不成功的USER或者PASS命令后
         可能的响应:
             +OK name is a valid mailbox
             -ERR never heard of mailbox name
         Examples:
             C: USER frated
             S: -ERR sorry, no mailbox for frated here
                ...
             C: USER mrose
             S: +OK mrose is a real hoopy frood
      PASS string
         Arguments:
             a server/mailbox-specific password (required)
         Restrictions:
             may only be given in the AUTHORIZATION state immediately

             after a successful USER command
         Possible Responses:
             +OK maildrop locked and ready
             -ERR invalid password
             -ERR unable to lock maildrop
         Examples:
             C: USER mrose
             S: +OK mrose is a real hoopy frood
             C: PASS secret
             S: -ERR maildrop already locked
               ...
             C: USER mrose
             S: +OK mrose is a real hoopy frood
             C: PASS secret
             S: +OK mrose's maildrop has 2 messages (320 octets)
      QUIT
         Arguments: none
         Restrictions: none
         Possible Responses:
             +OK
         Examples:
             C: QUIT
             S: +OK dewey POP3 server signing off

      STAT
         Arguments: none
         Restrictions:
             may only be given in the TRANSACTION state
         Possible Responses:
             +OK nn mm
         Examples:
             C: STAT
             S: +OK 2 320
      LIST [msg]
         Arguments:
             a message-number (optional), which, if present, may NOT
             refer to a message marked as deleted
         Restrictions:
             may only be given in the TRANSACTION state
         Possible Responses:
             +OK scan listing follows
             -ERR no such message
         Examples:
             C: LIST
             S: +OK 2 messages (320 octets)
             S: 1 120
             S: 2 200
             S: .
               ...
             C: LIST 2
             S: +OK 2 200
               ...
             C: LIST 3
             S: -ERR no such message, only 2 messages in maildrop
      RETR msg
         Arguments:
             a message-number (required) which may NOT refer to a
             message marked as deleted
         Restrictions:
             may only be given in the TRANSACTION state
         Possible Responses:
             +OK message follows
             -ERR no such message
         Examples:
             C: RETR 1
             S: +OK 120 octets
             S: <the POP3 server sends the entire message here>
             S: .
      DELE msg
         Arguments:
             a message-number (required) which may NOT refer to a
             message marked as deleted
         Restrictions:
             may only be given in the TRANSACTION state
         Possible Responses:
             +OK message deleted
             -ERR no such message
         Examples:
             C: DELE 1
             S: +OK message 1 deleted
                ...
             C: DELE 2
             S: -ERR message 2 already deleted
      NOOP
         Arguments: none
         Restrictions:
             may only be given in the TRANSACTION state
         Discussion:
             The POP3 server does nothing, it merely replies with a
             positive response.
         Possible Responses:
             +OK
         Examples:
             C: NOOP
             S: +OK
      RSET
         Arguments: none
         Restrictions:
             may only be given in the TRANSACTION state
         Possible Responses:
             +OK
         Examples:
             C: RSET
             S: +OK maildrop has 2 messages (320 octets)
      QUIT
         Arguments: none
         Restrictions: none
         Possible Responses:
             +OK
             -ERR some deleted messages not removed
         Examples:
             C: QUIT
             S: +OK dewey POP3 server signing off (maildrop empty)
                ...
             C: QUIT
             S: +OK dewey POP3 server signing off (2 messages left)
                ...

      TOP msg n
         Arguments:
             a message-number (required) which may NOT refer to to a
             message marked as deleted, and a non-negative number
             of lines (required)
         Restrictions:
             may only be given in the TRANSACTION state
         Possible Responses:
             +OK top of message follows
             -ERR no such message
         Examples:
             C: TOP 1 10
             S: +OK
             S: <the POP3 server sends the headers of the
                message, a blank line, and the first 10 lines
                of the body of the message>
             S: .
                ...
             C: TOP 100 3
             S: -ERR no such message
      UIDL [msg]
      Arguments:
          a message-number (optional), which, if present, may NOT
          refer to a message marked as deleted
      Restrictions:
          may only be given in the TRANSACTION state.
      Possible Responses:
          +OK unique-id listing follows
          -ERR no such message
      Examples:
          C: UIDL
          S: +OK
          S: 1 whqtswO00WBw418f9t5JxYwZ
          S: 2 QhdPYR:00WBw1Ph7x7
          S: .
             ...
          C: UIDL 2
          S: +OK 2 QhdPYR:00WBw1Ph7x7
             ...
          C: UIDL 3
          S: -ERR no such message, only 2 messages in maildrop
      APOP name digest
         Arguments:
             a string identifying a mailbox and a MD5 digest string
             (both required)
         Restrictions:
             may only be given in the AUTHORIZATION state after the PO
P3
             greeting or after an unsuccessful USER or PASS command
         Possible Responses:
             +OK maildrop locked and ready
             -ERR permission denied
         Examples:
             S: +OK POP3 server ready <1896.697170952@dbc.mtview.ca.us
>
             C: APOP mrose c4c9334bac560ecc979e58001b3e22fb
             S: +OK maildrop has 1 message (369 octets)

  POP3对话举例:

      S: <wait for connection on TCP port 110>
      C: <open connection>
      S:    +OK POP3 server ready <1896.697170952@dbc.mtview.ca.us>
      C:    APOP mrose c4c9334bac560ecc979e58001b3e22fb
      S:    +OK mrose's maildrop has 2 messages (320 octets)
      C:    STAT
      S:    +OK 2 320
      C:    LIST
      S:    +OK 2 messages (320 octets)
      S:    1 120
      S:    2 200
      S:    .
      C:    RETR 1
      S:    +OK 120 octets
      S:    <the POP3 server sends message 1>
      S:    .
      C:    DELE 1
      S:    +OK message 1 deleted
      C:    RETR 2
      S:    +OK 200 octets
      S:    <the POP3 server sends message 2>
      S:    .
      C:    DELE 2
      S:    +OK message 2 deleted
      C:    QUIT
      S:    +OK dewey POP3 server signing off (maildrop empty)
      C:  <close connection>
      S:  <wait for next connection>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值