The Protocol
The POP2 protocol is a sequence of commands and replies. The design draws from many previous protocols of the ARPA-Internet community.
The server must be listening for a connection. When a connection is opened the server sends a greeting message and waits for commands. When commands are received the server acts on them and responds with replies.
The client opens a connection, waits for the greeting, then sends the HELO command with the user name and password arguments to establish authorization to access mailboxes. The server returns the number of messages in the default mailbox.
The client may read the default mailbox associated with the user name or may select another mailbox by using the FOLD command. The server returns the number of messages in the mailbox selected.
The client begins a message reading transaction with a READ command. The read command may optionally indicate which message number to read, the default is the current message (incremented when a message is read and set to one when a new folder is selected). The server returns the number of characters in the message.
The client asks for the content of the message to be sent with the RETR command. The server sends the message data.
When all the data has been received the client sends an acknowledgment command. This is one of ACKS, ACKD, and NACK.
ACKS means "I've received the message successfully and please keep it in the mailbox".
ACKD means "I've received the message successfully and please delete it from the mailbox".
NACK means "I did not receive the message and please keep it in the mailbox".
In the case of ACKS or ACKD the server increments the current message indicator. In the case of NACK the current message indicator stays the same.
In all cases the server returns the number of characters in the (now) current message.
The client terminates the session with the QUIT command. The server returns an ok.
The Normal Scenario
Client Server
------ ------
Wait for Connection
Open Connection -->
<-- + POP2 Server Ready
Wait for Command
HELO Fred Secret -->
<-- #13 messages for you
Wait for Command
READ 13 -->
<-- =537 characters in that message
Wait for Command
RETR -->
<-- (send the message data)
Wait for Command
ACKS -->
<-- =0 no more messages
Wait for Command
QUIT -->
<-- + OK
Close connection --> <-- Close connection
Wait for Connection (go back to start)