471,306 Members | 840 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Java Mail: Is There A Simple Way to Get ALL Message Headers

I'm working with javax.mail.*. I have no problem with reading in messages.
I'm not using multi-part messages or anything, I just use this setup:

Session oSession = Session.getDefaultInstance(props, null);
try {
oStore = oSession.getStore("pop3");
oStore.connect(sInServer, sInName, sInPass);
oFolder = oStore.getFolder("INBOX");
oMessage = oFolder.getMessages();
if (oMessage.length == 0) {return;}}
} catch (Exception e)
{System.out.println("Problem with opening and getting messages: " + e);}
for (int i=0, n = oMessage.length; i < n; i++) {
try {
System.out.println(i + ": " + oMessage[i].getFrom()[0] + "\t"
} catch (Exception e)
{System.out.println("Problem printing message info: " + e);}
try {sContent = (String) oMessage[i].getContent();} catch (Exception e)
{System.out.println("Problem getting message content: " + e);}
//From here, do stuff with the message -- like saving the content

The code is still new, so I'll be using actual error handlers.

Here's the problem: There are times when I want to save a copy of the ENTIRE
message, including the headers, so I can use the headers later (possible
spam filtering and other stuff).

I've found the getHeader() and similar functions in Java Mail that return
headers as objects. Isn't there some SIMPLE and quick way to get a string
that contains all the headers? Like a "Header" version of getContent()?

I basically just want to dump the header and content to the drive. I
thought I read somewhere that there was a call to use to get the full
header and content together, but I haven't been able to re-locate it or
verify it's what I read.

Thanks for any help!

Jul 17 '05 #1
0 1996

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by pee2pee | last post: by
reply views Thread by James Hong | last post: by
1 post views Thread by Nick Chorley | last post: by
12 posts views Thread by e_matthes | last post: by
10 posts views Thread by crazycooter | last post: by
5 posts views Thread by Gordon | last post: by
reply views Thread by rosydwin | last post: by

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.