473,395 Members | 1,968 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Java and POP3 IO (?) problem

Lo all,

I've written a simple program that connects to a POP3 server, allows me
to authenticate and then retrieves a certain message. The problem I'm
having is that when it retrives the message and prints it to the
console, I get different results depending on if I use a while loop or a
do-while loop. When I use a while loop, I get some of the headers but no
message body. When I use a do-while loop, I get some of the same
different headers (and message body), but some of the headers that I got
from using a while loop are missing. Does anyone have any idea what the
problem is?

My code as it is now:

import java.net.*;
import java.io.*;

public class mail
{
public static void main(String[] args) throws Exception
{
BufferedReader user = new BufferedReader(new
InputStreamReader(System.in));
System.out.print("Server address: ");
String host = user.readLine();
System.out.print("Port: ");
int port = Integer.parseInt(user.readLine());

// Connect to server and set up input/output streams
Socket mySocket = new Socket(host, port);
InputStream in = mySocket.getInputStream();
BufferedReader from = new BufferedReader(new
InputStreamReader(in));
OutputStream out = mySocket.getOutputStream();
PrintWriter to = new PrintWriter(new OutputStreamWriter(out));
String response = from.readLine();
System.out.println(response);

// Authenticate
System.out.print("Username: ");
String username = user.readLine();
to.println("USER " + username);
to.flush();
response = from.readLine();
System.out.println(response);
System.out.print("Password: ");
String pass = user.readLine();
to.println("PASS " + pass);
to.flush();
response = from.readLine();
System.out.println(response);

// Get message no. 5
to.println("RETR 5");
to.flush();
do
{
System.out.println(from.readLine());
}while(from.readLine() != null);

// Close streams and connection
to.println("QUIT");
to.close();
from.close();
mySocket.close();
if(mySocket.isClosed())
System.out.println("Disconnected");
}
}

Thanks.
Jul 17 '05 #1
1 1781
Nick Chorley wrote:
do
{
System.out.println(from.readLine());
}while(from.readLine() != null);


The above code will only print every other line.

HTH,
Ray

--
XML is the programmer's duct tape.
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Alexander Franksmann | last post by:
Hello, I'm going to write a anti-spam-program based on a Whitelist. "If the mail sender is found in the database, my program should move the mail into another mailbox" The mailserver fetched the...
4
by: WebRod | last post by:
Hi everybody, I just would like to download the new mails I received on my POP3 server (and keep a copy on the server) I use PHP 4.3 and IMAP functions (they are compatible with both POP3 and...
0
by: Eric McDaniel | last post by:
This may be a question for ActiveState support, but just in case anyone out there knows what the problem is... My call to Net::POP3->new() works fine when run through the perl interpreter, but...
2
by: Krzysztof Paz | last post by:
Hi, There is a Java (SUN 1.4) server which using Object Input/Output Streams at SSL/Socket to communicate with Java clients. Now there is a request for making C# Client for this server also. SSL...
2
by: Mike Brearley | last post by:
I need to write a script that will check a catch-all mailbox (pop3) and send a non delivery report back to the sender of the email. Background info: I have a domain hosted on a site that offers...
1
by: bobano | last post by:
Hi everyone, I am writing a POP3 Client program in Perl. You connect to a POP3 Server and have a running conversation with the mail server using commands from the RFC 1939 Post Office Protocol....
0
by: =?Utf-8?B?Q2hhcmxlcw==?= | last post by:
Like many people, I normally use Yahoo! Mail via the web and like to keep all my emails stored on the Yahoo! server. However sometimes I can’t get access to a PC/the web and I download my emails...
0
by: Daljeet Hanspal | last post by:
hi guys i got this code in c#.net to retrieve mails using pop3 protocal, i'm using MERCURY MAIL SERVER ........ I create a user acccount in mercury by name honey@localhost the problem is ...
3
sreekandank
by: sreekandank | last post by:
I want to implement POP3 program in java....I have written the code like... import javax.mail.*; import javax.mail.internet.*; import java.util.*; import java.io.*; public class POP3Client {...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.