POP3 protocol specification (Chinese Version)

Source: Internet
Author: User
Tags md5 digest valid email address

POP3 Post Office Protocol-Version 3

1. Introduction

For small nodes on the network, it is impractical to support the message transmission system (MTS. For example, a workstation may not have sufficient resources to allow the SMTP server and a considerable number of local email delivery systems to stay in sequence and run continuously. Similarly, the cost of connecting a personal computer to an IP network over a long period of time is considerable (the lack of resources at a node is called "connection ").

Even so, it is very useful to allow mail management on such summary points, and these nodes often support a user agent to manage mail. To solve this problem, the nodes that support MTS provide the mail storage function for those nodes that cannot be supported. The Post Office Protocol-Version 3 enables such workstations to use a more practical method to access stored mails stored on servers. Generally, this means that the workstation can get the mail from the server, and the server temporarily saves the mail for it.

In the following section, a client host refers to a host that uses the POP3 Service, and a server host refers to a host that provides the POP3 service.

2. Simple Description

This document does not specify how the client host sends messages to the transfer system. But here is a description: when the user agent needs to send the information to the transfer system, it establishes an SMTP connection on the Relay host (these can be POP3 hosts, or not ).

 

3. Basic operations

Initially, the server listens to TCP port 110 to start the POP3 service. When the customer host needs to use the service, it establishes a TCP connection with the server host. After the connection is established, POP3 sends a confirmation message. The client and POP3 server exchange commands and responses to each other (respectively). This process continues until the connection is terminated.

The POP3 command consists of a command and some parameters. All commands end with a CRLF pair. Commands and parameters are composed of printable ASCII characters separated by spaces. The command generally contains three to four letters, but each parameter can be up to 40 characters long.

A POP3 response consists of a status code and a command that may contain additional information. All responses are also ended by the CRLF pair. There are two status codes: "OK" ("+ OK") and "failed" ("-Err ").

The response to a specific command is composed of many characters. In these cases, the following statements are one by one: after the first line of response and a CRLF are sent, any additional information lines are sent, and they are also ended by the CRLF pair. When all messages are sent, the last line is sent, including an ending character (decimal code 46, that is, ".") and a CRLF pair. If any row in the Information starts with an ending character, this row is filled by Preloading and ending the row. Therefore, the multi-line response is ended by five CRLF. CRLF. When multiple lines are detected, the customer checks to confirm whether the line starts with an ending character. If yes, and the subsequent character is not CRLF, the first character (ending character) of this line will be discarded; if it is followed by CRLF, the response from the POP server will terminate, including. CRLF rows are not considered part of Multiline responses.

In the lifecycle, POP3 sessions have several different states. Once the TCP connection is enabled and the POP3 server sends a confirmation message, the process enters the "OK" status. In this status, the customer must confirm with the POP3 server that he is the customer. Once confirmed, the server obtains the resources related to the customer's email, and the process enters the "operation" status. In this status, the customer proposes a service. When the customer issues a quit command, the process enters the "Update" status. In this status, the POP3 server releases the resources obtained in the "operation" status, sends a message, and terminates the connection.

The POP3 server can have a logon logout record. This note must be recorded for at least 10 minutes. In this way, the message sent from the customer can be refreshed. When the note expires, the POP3 session does not enter the "Update" status, but closes the TCP connection, does not delete any messages, and does not send any response to the customer.

 

4. "OK" status

 

When a TCP connection is opened by a POP3 client, the POP3 server sends a single row for confirmation. This message can be any character ending with CRLF. For example, it can be:

S: + OK POP3 server ready

 

Note: This message is a POP3 response. The POP3 server should provide a "OK" response for confirmation.

The POP3 session enters the "OK" status. In this case, the customer must prove its identity to the server. This document describes two possible processing mechanisms: user and PASS commands, and APOP commands to be introduced later.

The customer must first send the USER command to confirm the process by using the user and PASS commands. If the POP3 server responds with a "OK" status code, the customer can send the PASS command to complete the confirmation, or send the quit command to terminate the POP3 session. If the POP3 server returns the "failed" status code, the customer can send the confirmation command or the quit command again.

After the customer sends the PASS Command, the server determines whether to allow access to the corresponding storage mail based on the additional information of the user and PASS commands.

Once the server decides to allow customers to access and store emails through the data, the server will add an exclusive lock to the emails to prevent changes to the emails before entering the "Update" status. If the exclusive lock is successfully obtained, the server returns a "Confirm" status code. The session enters the "operation status" and no emails are marked as deleted. If the email cannot be opened for some reason (for example, the exclusive lock cannot be obtained, the customer cannot access the corresponding email or the email cannot perform syntax analysis), the server returns the "failed" status code. After the "failed" status code is returned, the server closes the connection. If the server does not close the connection, the customer can resend the confirmation command, start again, or send the quit command.

After an email is opened on the server, it specifies a message number for each message and represents the length of each message in octal. The first message is specified as 1, the second message is specified as 2, and so on. The Nth message is specified as N. In POP3 commands and responses, the message number and length are in decimal format.

The following is a summary of the above three commands:

 

Command Format Parameters Restrictions Response Example
User Name Specifies the mailbox string, which is critical to the server Only when the user and PASS commands fail or are in the "OK" status + OK: valid email address;

-Err: invalid email address

C: User mrose

S: + OK mrose is a real hoopy frood

...

C: User frated

S:-err sorry, no mailbox for frated here

Pass string Password This command is used only after the USER command is successful in the "OK" status (because this command has only one parameter, spaces are no longer used as separators, but as part of the password) + OK: the email is locked and ready;

-The err password is invalid or the email cannot be 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)

...

C: User mrose

S: + OK mrose is a real hoopy frood

C: pass secret

S:-err maildrop already locked

Quit (None) (None) + OK C: Quit

S: + OK Dewey POP3 server signing off

 

 

5. "operation" status

 

Once the customer successfully confirms his identity to the server, the server will lock and open the corresponding email. Then, the POP3 session enters the "operation" status. Now, the customer can repeat the following POP3 command and return a response for each command server. Finally, the customer sends the quit command and the session enters the "Update" status.

The following commands are available in the "operation" status:

Command Parameters Restrictions Description Response Example
Stat (None) Available only in the "operation" status. The server uses the response containing the email information as "Confirmation ". To simplify syntax analysis, all servers require a specific format of the mail list. The "Confirm" response consists of a space, which indicates the number of emails in octal format, a space, and the mail size. This is the minimum implementation. The advanced implementation also requires additional information.

Note: emails marked as deleted are not listed in this column.

+ OK: NN mm C: stat

S: + OK 2 320

List [MSG] Number of letters (Optional). If yes, it does not include letters marked as deleted. Available only in the "operation" status. If a parameter is provided and the POP3 server returns a "Confirm" containing the preceding information, this row is called the "Scan table" of the information ".

If no parameter exists, the server returns a "OK" response, which is given in multiple rows. After the initial + OK, the server will respond to each letter accordingly.

To simplify syntax analysis, all servers require the specific format of the scan table. It contains spaces and the exact size of each email. This is the minimum implementation. The advanced implementation also requires additional information.

Note: emails marked as deleted are not listed in this column.

+ OK: followed by the scan table;

-Err: No scan.

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 Does not include the number of emails marked as deleted. Available only in the "operation" status. If the server returns "OK", the response is multiline. After the initial + OK, the server sends the information corresponding to the given information number. For multi-row response, note that the termination character is filled in byte. + OK: After the message;

-Err: no message is sent later.

C: RETR 1

S: + OK 120 octets

S: <the POP3 server sends the entire message here>

S :.

Dele msg Does not include the number of emails marked as deleted. Available only in the "operation" status. The server marks this letter as deleted, and any subsequent operations on this letter will produce errors. The server does not delete this letter before the session enters the "Update" status. + OK: the email is deleted;

-Err: this letter is not found.

C: DELE 1

S: + OK message 1 deleted

...

C: DELE 2

S:-err Message 2 already deleted

Noop (None) Available only in the "operation" status. The server only returns "OK ". + OK C: Noop

S: + OK

Rset (None) Available only in the "operation" status. All emails marked as deleted are reset, and the server returns "OK ". + OK C: rset

S: + OK maildrop has 2 messages (320 characters)

 

 

6. "Update" status

 

When the customer sends the quit command in the "operation" status, the session enters the "Update" status. (Note: If the user sends quit in the "OK" status, the session does not enter the "Update" status .)

If a session is interrupted due to reasons other than the quit command, the session does not enter the "Update" status or delete any emails from the server.

Command Parameters Restrictions Description Response Example
Quit (None) (None) The server deletes all emails marked as deleted, releases the exclusive lock, and returns the status code of these operations. The TCP connection is interrupted. + OK C: Quit

S: + OK Dewey POP3 server signing off (clear the marked email)

...

C: Quit

S: + OK Dewey POP3 server signing off

 

 

7. Optional POP3 commands

 

The commands discussed above are the minimum implementation of the POP3 service. The optional commands described below allow the customer to process mails more conveniently. This is a common POP3 Service implementation.

Command Parameters Restrictions Description Response Example
Top MSG n One is the number of letters not marked as deleted, and the other is not negative (required) It is only used in the "operation" status. If the server returns "OK", the response is multiline. After the initial + OK, the server sends the mail header. An empty line separates the mail header and the letter body. For multi-line response, note that the termination character is filled in byte.

Note: If the number of lines requested by the customer is greater than the number of lines in the mail body, the server will send the entire letter.

+ OK: There is a mail header;

-Err: there is no similar message afterwards.

C: Top 1 10

S: + OK

S: <the server sends the message header, and the first 10 lines of an empty line and a letter>

S :.

...

C: Top 100 3

S:-err no such message

UIDL [MSG] Number of letters (optional ). If the number of letters is given, it does not include the letters marked as deleted. It is only used in the "operation" status. If a parameter is provided and the POP3 server returns "OK" containing the preceding information, this row is called the "independent-ID table" of the information ".

If no parameter exists, the server returns a "OK" response, which is given in multiple rows. After the initial + OK, the server will respond to each letter accordingly. This row is called the independent-ID table of the letter ".

To simplify syntax analysis, all servers require the specific format of the independent-ID table. It includes spaces and independent-IDs of letters.

The letter's independent-ID consists of 0x21 to 0x7e characters, which are not repeated in the given stored mail.

Note: emails do not include those marked as deleted.

+ OK: The table is an independent-ID table;

-Err: there are no similar emails.

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 Specifies the mailbox string and MD5 Digest string. It is only used in the "Confirm" status after POP3 confirmation. Generally, each POP3 session starts with user/pass interchange. This causes explicit transmission of user names and passwords over the network, which is not dangerous. However, many customers often connect to service check letters. Generally, the interval is relatively short, which increases the possibility of leaks.

Another way to provide the "validation" process is to use the APOP command.

The server that implements the APOP command includes a timestamp marked for confirmation. For example, on UNIX, the syntax for using the APOP command is: process-ID.clock @ hostname, where process-ID is the number of the Process in decimal notation, the clock is the system clock in decimal notation, the host name is the same as that of the POP3 server.

The customer records the timestamp and sends the APOP command. The name syntax is consistent with the USER command. Digest is a string generated by using the MD5 algorithm, including the timestamp and shared key. This key is shared between the customer and the server. You should protect it. If it is disclosed, anyone can access the server as a user.

If the server receives the APOP command, it verifies digest. If it is correct, the server returns "OK" and enters the "operation" status; otherwise, the server returns "failed" and stays in the "OK" status.

Note: the length of the shared key increases, and the difficulty of interpreting it increases accordingly. The key should be a long string.

+ OK: the email is locked and ready;

-Err: the request is rejected.

S: + OK POP3 Server Ready <1896.697170952@dbc.mtview.ca.us>

C: APOP mrose c4c9334bac560ecc979e58001b3e22fb

S: + OK maildrop has 1 message (369 octets)

In this example, the shared key <1896.697170952@dbc.mtview.ca.us> tanstaaf is generated by the MD5 algorithm, which generates the digest value, c4c9334bac560ecc979e58001b3e22fb

 

 

8. POP3 command Summary

 

Basic POP3 commands:

 

The user name is valid in the "OK" status.

Pass string

Quit

 

Stat is valid in "operation" status

List [MSG]

RETR msg

Dele msg

Noop

Rset

 

Quit is valid in the "Update" status

 

Optional POP3 commands:

 

APOP name digest is valid in "OK" status

 

Top msg n is valid in "operation" status

UIDL [MSG]

 

POP3 response:

 

+ OK

-Err

 

Note: Except for the stat, list, And UIDL responses, the responses of other commands are "+ OK" and "-Err ". All the text after the response will be omitted by the customer.

 

9. POP3 session instance

S: <waiting to connect to 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: <server sends mail 1>

S :.

C: DELE 1

S: + OK message 1 deleted

C: RETR 2

S: + OK 200 octets

S: <server sends mail 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: <waiting for next connection>

 

10. Message format

 

The message format during the session is assumed to be consistent with the Internet Text Message format standard. It should be noted that the count is not necessarily the same because different servers have different line breaks. Generally, in the "Confirm" status, the server can calculate the mail size in octal. For example, if the server determines that a line break represents one character when opening a stored mail, the server generally calculates it as two characters. Note that the message lines starting with the terminator are not counted twice, because the customer will delete all byte fills after receiving the multi-row response.

 

11. security considerations

It can be inferred that the APOP command can provide protection during the session. Correspondingly, the server that implements the pass and APOP commands at the same time only allows users to access them in one way. That is to say, either the user/pass combination or the APOP command cannot be used at the same time.

Note that as the length of the shared key increases, the difficulty of interpretation increases. The server does not give any response when providing the user name, and does not give any suggestion that the user name is correct. The password is explicitly transmitted over the network, and the RETR and top commands are used to explicitly send emails over the network.

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.