Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Message[ ] Backup in MAIL API  RSS feed

 
Rohan Baweja
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everyone. I am developing a javamail client. Now when I connect to the Yahoo pop server thorugh javamail API, I am able to download these mesaages in an Message Array object.
Now I want to keep a copy of this message array on the local drive and then use it later. I also want to read these messages seperately from the local file. How can it be done? Please shed some light.
thanx,
 
Joe Gilvary
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by rohan baweja:
Hi Everyone. I am developing a javamail client. Now when I connect to the Yahoo pop server thorugh javamail API, I am able to download these mesaages in an Message Array object.
Now I want to keep a copy of this message array on the local drive and then use it later. I also want to read these messages seperately from the local file. How can it be done? Please shed some light.
thanx,

Howdy,
The Java Mail FAQ at sun includes info that
might nterest you. Check:
http://java.sun.com/products/javamail/FAQ.html#serialize
Q: Why doesn't the MimeMessage class implement
Serializable so that I can serialize a
message to disk and read it back later?
A: The JavaMail API was designed to layer on
top of existing email systems, using existing
message formats. The ability to use Java
serialization was neither essential nor useful
for such implementations, and thus was not
considered a goal of the JavaMail API.
The hard part about serializing a Message is
retaining the pointers to the Folder, Store,
and Session. If you only want to save the
content of the message, and not the object
itself, the writeTo method of a message gives
you everything you need. If you want to create an
entire email system based on serialized messages,
you should be able to subclass Message et. al.
and implement Serializable in your subclass.
If you want to serialize other objects of your
own that reference MimeMessages, the writeObject
method of your object can use the writeTo method
of MimeMessage, and the readObject method of your
object can use the MimeMessage constructor that
takes an InputStream. Your class will need to
provide a Session when constructing the MimeMessage.

Hope that helps,
Joe
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!