2014-10-10 3 views
-1
try{ 
     smtpSocket= new Socket("pop.rediffmail.com",110); 
     os=new DataOutputStream(smtpSocket.getOutputStream()); 
     is=new BufferedReader(new InputStreamReader(smtpSocket.getInputStream())); 
     System.out.print("Inbox List": \n"); 
     os.writeBytes("list\r\n"); 
     System.out.println(is.readLine()); 

프로그램에서 메일의 전체 목록을 표시하지 않습니다. 그것을 해결하는 방법?POP3에서 복수 응답을 얻는 방법

답변

1

Read RFC 1939은 POP3 프로토콜을 정의합니다. 특히, 복수 회선 응답을 읽는 방법을 알려주는 section 3을 읽으십시오.

특정 명령에 대한 응답은 여러 줄로 구성됩니다. 이 경우에는 이 명확하게 아래에 표시되어 있으며 응답의 첫 번째 줄과 CRLF를 보낸 후 추가 줄이 보내지며 각 줄은으로 CRLF 쌍으로 끝납니다. 응답의 모든 회선이 전송되면 종결 옥텟 (십진 코드 046, ".")과 CRLF 쌍으로 구성된 최종 회선이 보내집니다. 멀티 회선 응답 중 임의의 회선이 종료 옥 테트로 시작하면 회선은 응답 회선에 종료 옥텟을 미리 계류하여 에 의해 "바이트 채움"됩니다. 따라서 다중 회선 응답은 "CRLF.CRLF"의 다섯 옥텟으로 끝납니다. 다중 회선 응답을 검사 할 때 클라이언트는 을 검사하여 회선이 종료 옥텟으로 시작하는지 확인합니다. 그렇다면 CRLF 이외의 8 진수가 이어지면 해당 줄의 첫 번째 옥텟 ( 종료 옥텟)이 제거됩니다. 그렇다면 CRLF가 즉시 종료 문자 다음에 다음에 오는 경우 POP 서버의 응답이 종료되고 ".CRLF"가 포함 된 줄은 복수 회선 응답의 일부로 간주되지 않습니다. 예를 들어

:

try{ 
    smtpSocket= new Socket("pop.rediffmail.com",110); 
    os=new DataOutputStream(smtpSocket.getOutputStream()); 
    is=new BufferedReader(new InputStreamReader(smtpSocket.getInputStream())); 
    string line = is.readLine(); 
    System.out.println(line); 
    if (line.startsWith("+OK")){ 
     System.out.println("Inbox List:"); 
     os.writeBytes("list\r\n"); 
     line = is.readLine(); 
     System.out.println(line); 
     if (line.startsWith("+OK")){ 
      do { 
       line = is.readLine(); 
       if (line == ".") break; 
       if (line.startsWith(".")) 
        line = line.substring(1); 
       System.out.println(line); 
      } 
      while (true); 
     } 
    }