2009年4月20日 星期一

POP3 的三章--基本作業 (Basic Operation)

在先前的POP3 == RFC 1939文中提到 "...只要看RFC 1939的第三頁到第五頁,就大致上把它主要規則的描述看完了...",但是在該文中,並沒有提及該部份詳細的內容!以下是針對該部分所做的補充,把POP3的第三章基本操作 (Basic Operation) 介紹一下。(英文斜體的部分是POP3的原文,中文的部分僅供參考) Initially, the server host starts the POP3 service by listening on TCP port 110. When a client host wishes to make use of the service, it establishes a TCP connection with the server host. When the connection is established, the POP3 server sends a greeting. The client and POP3 server then exchange commands and response (respectively) until the connection is closed or aborted.  POP3伺服器會監聽TCP的埠號第110 (這也就是POP3的預設通訊埠)。當用戶端的電腦想要使用POP3的服務時,它會透過TCP與伺服器連線。連線成功之後,伺服器會向用戶端電腦送出問候語,表示伺服器已經可以正確的提供服務。接下來,伺服器與用戶端就可進行直接的交談。 Commands in the POP3 consist of a case-insensitive keyword, possibly followed by one or more arguments. All commands are terminated by a CRLF pair. Keywords and arguments consist of printable ASCII characters. Keywords and arguments are each separated by a single SPACE character. Keywords are three or four characters long. Each argument may be up to 40 characters long. POP3所使用的命令並沒有大小寫之分,而且有可能會有一個以上的參數;所有的命令都是以CRLF (Carriage Return + Line Feed) 結束的。這些使用三到四個字元的命令關鍵字以及它的參數之間是以空格分開,同時都是可列印的ASCII字碼;至於參數可以長逹40個英文字元。 Responses in the POP3 consist of a status indicator and a keyword possibly followed by additional information. All responses are terminated by a CRLF pair. Responses may be up to 512 characters long, including the terminating CRLF. There are currently two status indicators: positive ("+OK") and negative ("-ERR"). Servers MUST send the "+OK" and "-ERR" in upper case. POP3伺服器的回應除了包含一個狀態的指示及一個關鍵字之外,可能再加上其它的資訊;整個回應的長度可以長達512個字元;同樣的,所有的回應都是以CRFL結束目前所使用的狀況指示有以下兩個:表示正常的 "+OK" 以及表示失敗的 "-ERR";它們都必須以大寫表示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. 如果伺服器的回應包含多行的話,除了最後一行是以 ".CRLF" 當結尾以外,其它每一行都是以 "CRLF" 為結尾的。此外,在多行回應的狀況下,如果是以"."為開頭,其後接的是CRLF,則它被視為是最末行;如果其後接的是CRLF以外的字元,則"."這個符號是可以被忽略的。 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. 一但用戶端電腦與伺服器建立連線,而且伺服器對用戶端電腦送出問候語之後,就進入了驗證階段。在這個階段,用戶端電腦必須表明使用者的身份。驗證成功之後,則可以進入傳輸階段;在這個階段,用戶端電腦可以對伺服器要求所需要的資訊。最後,當用戶端送出QUIT命令之後,進入更新階段;這時伺服器向用戶端道別,並結束連線。 A server MUST respond to an unrecognized, unimplemented, or syntactically invalid command by responding with a negative status indicator. A server MUST respond to a command issued when the session is in an incorrect state by responding with a negative status indicator. There is no general method for a client to distinguish between a server which does not implement an optional command and a server which is unwilling or unable to process the command. 這段的意思大概就是說,伺服器對於它沒有辦法處理的命令一概回應"-ERR";用戶端基本上沒有辦法由它的回應判斷錯誤的原因。 A POP3 server MAY have an inactivity autologout timer. Such a timer MUST be of at least 10 minutes' duration. The receipt of any command from the client during that interval should suffice to reset the autologout timer. When the timer expires, the session does NOT enter the UPDATE state--the server should close the TCP connection without removing any messages or sending any response to the client. POP3伺服器可以有一個計時器,這個計時器的設定值至少為十分鐘。在接收到用戶端的任何要求的同時,將會把這個計時器復歸;如果在這個計時器的計時結束時,尚未進入更新階段,則伺服器應自動中斷連線 ;在中斷連線時不會移除任何訊息,也不會給用戶端任何回應。

沒有留言: