Results 1 to 2 of 2
  1. #1
    Bootes is offline Member
    Join Date
    Oct 2010
    Posts
    1
    Rep Power
    0

    Default IMAP with Java Socket, PrinterWriter, and BufferedReader

    I'm trying to write an IMAP email client in Java without using the Java Mail API.

    Basically my problem is that I only receive * OK IMAP4 ready and
    * BYE IMAP server terminating connection in my console. For some reason the server isn't receiving my other commands or I'm not getting the responses. Anyone have any ideas? I've commented out some lines where I was trying to figure out how to receive multiple lines from the server, without knowing how many lines there would be.

    Java Code:
    Socket s;
    		try {
    			s = new Socket("imap.aol.com", 143);
    			// create an input stream and tie it to the socket
    			InputStream in;
    			in = s.getInputStream();
    			BufferedReader sin = new BufferedReader(new InputStreamReader(in));
    			PrintWriter output = new PrintWriter(new OutputStreamWriter(s.getOutputStream()));
    
    
    			//String thisLine = sin.readLine();
    			/*do
    			{ // while loop begins here
                                System.out.println(thisLine);
                            } while ((thisLine = sin.readLine()) != null);
                            output.flush();*/
                            System.out.println(sin.readLine());
    
    			output.println(". login myemail@aol.com mypass");
                            System.out.println(sin.readLine());
                            System.out.println(sin.readLine());
    			/*while ((thisLine = sin.readLine()) != null)
    			{ // while loop begins here
    		         System.out.println(thisLine);
    		       } // end while
                            output.flush();*/
    
    			output.println(". list \"\" \"*\"");
                            System.out.println(sin.readLine());
                            System.out.println(sin.readLine());
                            System.out.println(sin.readLine());
    
                            output.println(". logout");
                            System.out.println(sin.readLine());
    }
    Thanks!

  2. #2
    Horcrux7 is offline Member
    Join Date
    Sep 2010
    Posts
    33
    Rep Power
    0

    Default

    First you have a encoding problem. The using of the default encoding for the IMAP protocol seems a bad idea. You should use a specific encoding.

    If you want a non blocking call then you should call available() of the InputStream before. The Reader API does not have it. That I think a DataInputStream on a BufferedInputStream is better. You can use the readline() also if it is deprecated. It is ever a ASCII encoding what seems ok for the first step of the protocol.

    The output.flush() does not have any effect if you have not write any.
    Volker Berlin
    www.inetsoftware.de

Similar Threads

  1. Replies: 0
    Last Post: 10-16-2010, 11:03 AM
  2. Replies: 1
    Last Post: 07-02-2010, 02:18 PM
  3. Replies: 2
    Last Post: 08-20-2009, 06:34 PM
  4. append response to the request from Socket and write to another socket
    By vaibhav_singh_vs@yahoo.co in forum Networking
    Replies: 3
    Last Post: 04-17-2009, 08:02 PM
  5. Help with BufferedReader in java
    By carl in forum New To Java
    Replies: 2
    Last Post: 07-31-2007, 08:20 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •