JavaMail: MimeMessage customer headers  
Author Message
akhalil





PostPosted: 2003-9-30 22:02:00 Top

java-programmer, JavaMail: MimeMessage customer headers How to add custom headers to a MimeMessage object?
The problem I'am having is reading from POP3 account and getting the
MimeMessage object. Before I want to save the message content to disk,
I want to add a few headers.

The error I'am getting is
POP3 messages are read-only

I've open the inbox folder as READ_WRITE but still no luck.
Anyone know how to add customer headers to the MimeMessage object when
reading from a POP3 account?

Thanks
 
GaryM





PostPosted: 2003-10-1 9:29:00 Top

java-programmer >> JavaMail: MimeMessage customer headers email***@***.com (Abraham Khalil) wrote in
news:email***@***.com:

> I've open the inbox folder as READ_WRITE but still no luck.
> Anyone know how to add customer headers to the MimeMessage object
> when reading from a POP3 account?

You're working with the reference to the original Message. There are
2 ways I can think of to do it.

1. Dupe the message

FileOutputStream outstream = new FileOutputStream(filename);
MimeMessage myNewMessage = new MimeMessage(theOneIWantToChange);
myNewMessage.setHeader("My-Header","My Head Value");
myNewMessage.write(outstream);
outstream.close();


2. Insert header into output stream

FileOutputStream outstream = new FileOutputStream(filename);
PrintWriter out = new PrintWriter(outstream);
out.println("X-My-Header: My Header Value");
out.flush();
message.writeTo(outstream); // the mimemessage
outstream.flush();
out.close();
outstream.close();


HTH,

Gary
 
akhalil





PostPosted: 2003-10-1 14:23:00 Top

java-programmer >> JavaMail: MimeMessage customer headers Thanks in a million. It was a reference problem.
Was doing the first one, cloning the message object but giving two
great answers is a bonus. Number two is definately a brillant solution
as its
more efficient than cloning the whole object. Once again, thank you
for
your contribution.



GaryM <email***@***.com> wrote in message news:<email***@***.com>...
> email***@***.com (Abraham Khalil) wrote in
> news:email***@***.com:
>
> > I've open the inbox folder as READ_WRITE but still no luck.
> > Anyone know how to add customer headers to the MimeMessage object
> > when reading from a POP3 account?
>
> You're working with the reference to the original Message. There are
> 2 ways I can think of to do it.
>
> 1. Dupe the message
>
> FileOutputStream outstream = new FileOutputStream(filename);
> MimeMessage myNewMessage = new MimeMessage(theOneIWantToChange);
> myNewMessage.setHeader("My-Header","My Head Value");
> myNewMessage.write(outstream);
> outstream.close();
>
>
> 2. Insert header into output stream
>
> FileOutputStream outstream = new FileOutputStream(filename);
> PrintWriter out = new PrintWriter(outstream);
> out.println("X-My-Header: My Header Value");
> out.flush();
> message.writeTo(outstream); // the mimemessage
> outstream.flush();
> out.close();
> outstream.close();
>
>
> HTH,
>
> Gary