Post Office Protocol – Version 3 阅读杂记

Post Office Protocol – Version 3 http://www.rfc-editor.org/rfc/rfc1939.txt

A POP3 session progresses through a number of states during its
lifetime. Once the TCP connection has been opened and the POP3
server has sent the greeting, the session enters the AUTHORIZATION
state. In this state, the client must identify itself to the POP3
server. Once the client has successfully done this, the server
acquires resources associated with the client’s maildrop, and the
session enters the TRANSACTION state. In this state, the client
requests actions on the part of the POP3 server. When the client has
issued the QUIT command, the session enters the UPDATE state. In
this state, the POP3 server releases any resources acquired during
the TRANSACTION state and says goodbye. The TCP connection is then
closed.

Minimal POP3 Commands:

USER name valid in the AUTHORIZATION state
PASS string
QUIT

STAT valid in the TRANSACTION state
LIST [msg]
RETR msg
DELE msg
NOOP
RSET
QUIT

Optional POP3 Commands:

APOP name digest valid in the AUTHORIZATION state

TOP msg n valid in the TRANSACTION state
UIDL [msg]

POP3 Replies:

+OK
-ERR

Example POP3 Session

S:
C:
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: S: .
C: DELE 1
S: +OK message 1 deleted
C: RETR 2
S: +OK 200 octets
S: S: .
C: DELE 2
S: +OK message 2 deleted
C: QUIT
S: +OK dewey POP3 server signing off (maildrop empty)
C:
S:

Responses to certain commands are multi-line. In these cases, which
are clearly indicated below, after sending the first line of the
response and a CRLF, any additional lines are sent, each terminated
by a CRLF pair. When all lines of the response have been sent, a
final line is sent, consisting of a termination octet (decimal code
046, “.”) and a CRLF pair. If any line of the multi-line response
begins with the termination octet, the line is “byte-stuffed” by
pre-pending the termination octet to that line of the response.
Hence a multi-line response is terminated with the five octets
“CRLF.CRLF”. When examining a multi-line response, the client checks
to see if the line begins with the termination octet. If so and if
octets other than CRLF follow, the first octet of the line (the
termination octet) is stripped away. If so and if CRLF immediately
follows the termination character, then the response from the POP
server is ended and the line containing “.CRLF” is not considered
part of the multi-line response.

POP3命令实例
telnet mail-host 110

USER hello@example.com

PASS 111111

STAT
+OK 13 332023

LIST
+OK POP3 clients that break here, they violate STD53.
1 202
2 73113
3 402
4 402
5 80267
6 13380
7 407
8 755
9 115473
10 16932
11 30343
12 169
13 178
.

LIST 2
+OK 2 73113

UIDL 3
+OK 3 uuxvo-13134583174281799

RETR 1 #应该返回第1封邮件的所有内容
+OK
Date: Mon, 15 Aug 2011 14:37:42 +0800 (CST)
From:
To: hello@example.com
Message-ID: <6879346.11.1313450262952.JavaMail.root@knight>
Subject: =?UTF-8?Q?=E6=B5=8B=E8=AF=952011=E5=B9=B48=E6=9C=881?=
=?UTF-8?Q?5=E6=97=A5=E6=98=9F=E6=9C=9F=E4=B8=8014:37?=
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary=”—-=_Part_10_343799.1313390262951″

——=_Part_10_343799.1313390262951
Content-Type: text/html;charset=gbk
Content-Transfer-Encoding: base64

PGh0bWw+PGhlYWQ+PG1ldGEgaHR0cC1lcXVpdj0iQ29udGVudC1UeXBlIiBjb250ZW50PSJ0ZXh0
L2h0bWw7IGNoYXJzZXQ9Z2JrIj48dGl0bGU+PC90aXRsZT48L2hlYWQ+PGJvZHk+suLK1DIwMTHE
6jjUwjE1yNXQx8ba0rsxNDozNzxkaXY+suLK1DIwMTHE6jjUwjE1yNXQx8ba0rsxNDozNzwvZGl2
PjwvYm9keT48L2h0bWw+
——=_Part_10_343799.1313390262951–
.

DELE 1
+OK

RSET
+OK

TOP 2 3 #应该返回第2封邮件的邮件头+前3行
+OK
Date: Tue, 16 Aug 2011 09:31:27 +0800 (CST)
From: noreply@example.com
To: hello@example.com
Message-ID: <27682895.1.1313458287431.JavaMail.root@SERVER2>
Subject: =?gbk?B?PLLiytTNy9DFMjAxMcTqONTCMTbI1dDHxtq2/jA5OjI3Ps22td3Kp7Dc?=
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary=”—-=_Part_0_31571602.1313458287431″

——=_Part_0_31571602.1313458287431
Content-Type: text/html;charset=gbk
Content-Transfer-Encoding: base64
.

TOP 1 #应该返回第1封邮件的邮件头

QUIT #断开连接