?????? 找一個開源項目來學習Java代碼,自己先讀一下,然后按自己的思路來重復實現其中一些功能!
一.POP3
協議

1.?????? 目前的電子郵件基本上都是通過 POP3 網絡協議接收的。建立雙向的傳輸通道以后, pop3 服務程序會發送一系列基于 ASCII 字符的命令,下面的圖大概說明了一下!
通常在學習的過程中,都是去寫 email 客戶端,其實一個方面是去寫一些處理的 function ;另一方面基本上就是寫一個實現 pop3 協議的包。

?? 常用的命令 USER,PASS,STAT,RETR,DELE QUIT. POP3 中只有兩種回應碼 ”+OK” ”-ERR” 。詳細?
?????? 的東西可以找RFC文檔來仔細定義.

2.?????? package org.columba.ristretto.pop3 該包實現了 RFC1939 所指定的 POP3 協議( Post Office Protocol Version3

3.?????? 在分析這個包之前,我們必須意識到一個完整的軟件通常都會自己去實現一些輔助的功能,該開源項目里自己實現了一些 I/O 功能。(不過這里有個疑問啊,這樣去實現一些東西,對于自己的一些應用是方便了,可是對于其他想復用這些代碼的人來說,就需要更多的學習時間)

?? 接口 Source 繼承自 CharSequence

?? 接口 Steamable 只有一個函數可以返回數據庫結構的 InputStream?
?4.? 有一個可以大概實現pop3client的例子(從別處抄來)很簡單不過可以實現基本的pop3client功能,對協議的理解也小有幫助!
???? import java.io.*;
import java.net.*;

class POP3Demo
{
?public static void main (String[] args)
?{
??String POP3Server = "server address";
??int POP3Port = 110;
??Socket clientsocket = null;
??try
??{
???clientsocket = new Socket(POP3Server, POP3Port);
???BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
???
???InputStream is =clientsocket.getInputStream();
???BufferedReader sockin = new BufferedReader(new InputStreamReader(is));
???
???OutputStream os = clientsocket.getOutputStream();
???PrintWriter sockout = new PrintWriter(os,true);
???
???System.out.println("S:"+sockin.readLine());
???while(true)
???{
????System.out.print("C:");
????String cmd = stdin.readLine();
????sockout.println(cmd);
????
????String reply = sockin.readLine();
????System.out.println("S:" + reply);
????
????if(cmd.toLowerCase().startsWith("retr")&&reply.charAt(0)=='+')
????do
????{
?????reply = sockin.readLine();
?????System.out.println("S:"+reply);
?????if(reply!=null && reply.length() > 0)
?????if(reply.charAt(0) == '.')
?????break;
????}
????while(true);
????
????if(cmd.toLowerCase().startsWith("quit"))
????break;
????
???}
??}
??catch(IOException e)
??{
???System.out.println(e.toString());
??}
??finally
??{
???try
???{
????if(clientsocket!=null)
????clientsocket.close();
???}
???catch(IOException e)
???{
???}
??}??
?}
}