Reading Emails

F

freesoft_2000

Hi everyone,

I am trying to read emails in from a stmp server without javamail api's
and i so far have only managed to read the e-mail messages but i can't
seem to read any attachments that come with it. I am not very sure as to
how i should separate the message from the attachment. This is what i have
so far

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

public class displayMail {

public static void main(String arg[]) {
//
// displayMail [mailServer] [user] [password]
try {
Socket s = new Socket(arg[0], 110);
BufferedReader in = new BufferedReader(
new InputStreamReader(s.getInputStream()));
BufferedWriter out = new BufferedWriter(
new OutputStreamWriter(s.getOutputStream()));
displayMail t = new displayMail();
String msg;
t.loginMail(in, out, arg[1], arg[2]);
int i = t.checkMyMail(in,out);
if (i==0) {
System.out.println("No mail waiting.");
}
else {
for (int j=1; j <= i; j++) {
msg = t.getMail(in, out, j);
System.out.println("*****");
System.out.println(msg);
System.out.println("*****");
}
}
}
catch (Exception e) {
e.printStackTrace();
}
}

public String getMail
(BufferedReader in, BufferedWriter out, int i)
throws IOException {
String s = "";
String t = "";
send(out, "RETR "+i);
while (((s = in.readLine()) != null)
&&(!(s.equals("."))))
t += s + "\n";
return t;
}


private void send(BufferedWriter out, String s) throws IOException {
out.write(s+"\n");
out.flush();
}

private String receive(BufferedReader in) throws IOException {
return in.readLine();
}

private void loginMail(BufferedReader in, BufferedWriter out,
String user, String pass)
throws IOException {
receive(in);
send(out, "USER " + user);
receive(in);
send(out, "PASS " + pass);
receive(in);
}

private int checkMyMail
(BufferedReader in, BufferedWriter out)
throws IOException {
return GetNumberOfMessages(in, out);
}



public int GetNumberOfMessages
(BufferedReader in, BufferedWriter out) throws IOException {
int i = 0;
String s;

send(out, "LIST");
receive(in);
while((s = receive(in)) != null) {
if (!(s.equals("."))) { i++; }
else return i;
}
return 0;
}
}

What are the necessary things that i need to do or changes to the above
code in order to read the attachments correctly??

Some codings would really be helpfull

Thank You

Yours Sincerely

Richard West
 
A

Alan Krueger

freesoft_2000 wrote:
[snip crude POP3 client]
What are the necessary things that i need to do or changes to the above
code in order to read the attachments correctly??

POP3 doesn't know anything about attachments. Attachments to emails are
part of the data returned when you RETR a message. You'll have to parse
the MIME structure of the email containing the attachment, assuming a
more primitive attachment mechanism isn't being used.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top