-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());

The Program not show all the list of the mail. How to solve it?

1 Answers1

1

Read RFC 1939, which defines the POP3 protocol. In particular, read section 3, which tells you how to read multi-line responses:

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.

For example:

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);
        } 
    } 
Community
  • 1
  • 1
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770