POP3 Post Office Protocol commands

Source: Internet
Author: User
Tags md5 digest

 

POP3 is called Post Office Protocol version3, that is, Post Office Protocol version 3rd. It is used by the user agent to obtain the mail on the mail server. POP3 uses the C/S communication model, and the corresponding RFC document is RFC1939. This Protocol is very simple, so we only focus on the communication process. For some related concepts and terms, refer to the RFC documentation.

 .Communication Process

 

The typical communication process for a user to receive a mail from the mail server is as follows.

1)The user runs the user agent (such as Foxmail and Outlook Express ).

2)The user agent (hereinafter referred to as the client) establishes a TCP connection with port 110 of the mail server (hereinafter referred to as the server.

3)The client sends various commands to the server to request various services (such as querying email information and downloading an email ).

4)The server parses the user's command, performs the corresponding action, and returns a response to the client.

5)3) and 4) Alternate until all emails are received and forwarded to step 6), or the connection between the two is accidentally interrupted and directly exited.

6)The User Agent parses the emails obtained from the server and presents them to the user in an appropriate form (such as readable.

2), 3), and 4) Communicate with POP3. The communication process can be represented in Figure 1. We can see that commands and responses are the focus of POP3 communication, and we will focus on them.

Figure 1. POP3 communication process

 

 

2.2.Commands and responses

 

2.2.1.Format

There are not many POP3 commands. The general form is: COMMAND [Parameter] <CRLF>.

COMMAND: COMMAND name in ASCII format

Parameter: Corresponding Command Parameters
<CRLF>: Enter the line break (0DH, 0AH) (\ r \ n in C)

 

A server response is composed of a single command line or multiple command lines. The response starts with "+ OK" or "-ERR" and then adds some ASCII text.

+ OK: operation successful

-ERR: operation failed

2.2.2.Three statuses

The POP3 protocol has three statuses: positive status, processing status, and update status. Command Execution can change the Protocol state. For a specific command, it can only be used in a specific State. For more information, see table 1 and RFC193.

When a connection is established between the client and the server, its status is authentication. Once the client provides its identity and is successfully confirmed, the status is transferred to the processing status; after the corresponding operations are completed, the client issues the QUIT command (For details, refer to the subsequent content), then enters the update status, and then returns to the approval status. Of course, the QUIT command is executed in the approval status, releases a connection.

--- Establish connection --- | approve | -- authentication successful -- | process | -- execute QUIT -- | update |
| _______-QUIT ends _________________ |

 

2.2.3.Example

The format of commands and responses is syntax. The meaning of commands and responses is semantics. The relationship between commands and responses in time is synchronization. We still use a simple POP3 communication process to describe the three elements of the Protocol.

C: telnet pop3.126.com 110/* connect to the 126 email server via telnet */

S: + OK Welcome to coremail Mail Pop3 Server (126 coms [3adb99eb4207ae5256632eecb8f8b4855])/* + OK indicates that the command is successful, and the subsequent information varies with the Server */

C: USER bripengandre/* plaintext authentication */

S: + OK core mail

C: PASS Pop3world/* Send email password */

S: + OK 654 message (s) [30930370 byte (s)]/* authentication successful, transfer to processing status */

C: LIST 1/* display the information of the first email */

S: + OK 1 5184./* The first mail size is 5184 bytes */

C: UIDL 1/* return the unique identifier of the first email */

S: + OK 1 1tbisBsHaEX9byI9EQAAsd/* The long string after the number 1 is the unique identifier of the first mail */

C: RETR 1/* download the first email */

S: + OK 5184 octets/* the size of the first mail is 5184 bytes */

S: Receive... /* Specific content of the first email */

S :...

C: QUIT/* Transfer to update status, and then transfer to authentication status */

S: + OK

C: QUIT/* disconnect */

S: + OK core mail/* the connection is successfully exited */

For the above process, add the following content.

1)The line starting with "C:" (excluding "C:") is the input of the client, and the line starting with "S:" (excluding "S :") is the output of the server.

2)The preceding command may not succeed at one time. The server will return an error response (starting with "-ERR"). The client should follow the time sequence specified by the Protocol, to enter Subsequent commands (or re-Execute failed commands, reset sessions, or quit sessions ).

3)The above process is schematic, and the actual process may be quite different from it. For example, encryption authentication (MD5 Digest authentication) may be used in the actual process ).

4)Emails downloaded by RETR may be hard to understand, because they may use quoted-printable or base64 encoding. We can use user agent software such as Foxmail to decode them.

 

2.2.4.Common commands and responses

SMTP commands are case-insensitive, but the parameters are case-sensitive. For more information, see RFC1939. Common commands are shown in table 1.

Command

Parameters

In what status

Description

USER

Username

Authentication

If this command is successful with the following pass Command, status conversion will occur.

PASS

Password

Authentication

If this command is successful, the status is changed to update

APOP

Name, Digest

Authentication

Digest is the MD5 message Digest.

STAT

None

Processing

The request server sends back the mailbox statistics, such as the total number of mails and the total number of bytes.

UIDL

[Msg #] (email number, the same below)

Processing

The unique identifier of the returned message. Each identifier of a POP3 session will be unique.

LIST

[Msg #]

Processing

The unique identifier of the returned message. Each identifier of a POP3 session will be unique.

RETR

[Msg #]

Processing

Returns all text of a message identified by a parameter.

DELE

[Msg #]

Processing

The server marks the emails marked by parameters as deleted and is executed by the QUIT command.

TOP

[Msg #]

Processing

The server returns the mail header + the first n lines of content of the email identified by the parameter. n must be a positive integer.

NOOP

None

Processing

The server returns a positive response to test whether the connection is successful.

QUIT

None

Processing and authentication

1)If the server is in the "processing" status, it will enter the "Update" status to delete any emails marked as deleted and return to the "authentication" status.

2)If the server is in the "authenticated" status, end the session and exit the connection.

 

Table 1 Common POP3 commands

As for the response, as described in 2.2.1, the response starts with "+ OK" or "-ERR", followed by some readable descriptions and other parameters (for RETR, this parameter is the content of the email ). For more information, see RFC1939.

 

 

From the column yue7603835

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.