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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Hal Vaughan

    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.getDefa ultInstance(pro ps, null);
    try {
    oStore = oSession.getSto re("pop3");
    oStore.connect( sInServer, sInName, sInPass);
    oFolder = oStore.getFolde r("INBOX");
    oFolder.open(Fo lder.READ_WRITE );
    oMessage = oFolder.getMess ages();
    if (oMessage.lengt h == 0) {return;}}
    } catch (Exception e)
    {System.out.pri ntln("Problem with opening and getting messages: " + e);}
    for (int i=0, n = oMessage.length ; i < n; i++) {
    try {
    System.out.prin tln(i + ": " + oMessage[i].getFrom()[0] + "\t"
    +oMessage[i].getSubject());
    } catch (Exception e)
    {System.out.pri ntln("Problem printing message info: " + e);}
    try {sContent = (String) oMessage[i].getContent();} catch (Exception e)
    {System.out.pri ntln("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!

    Hal
Working...