Raymond said:
well - i have found some documentation from sun that there are third party
products which allow one to used the javamail api with mbox. i've tried a
few with no luck yet. i can get as far as reading the mail when it throws
an 'unable to lock file' exception. i thought somebody out in the community
might know of a product so that i could use the javamail api instead of
having to write some kind of mailbox class myself - probably using the
commons lib - which it is looking like i'm going to have to do ...
mstor (which I found through the JavaMail third party products works
just fine. Here's how I make the connection:
1)get a Session instance
2)get a store instance:
Store store session.getStore(new URLName("mstor:" + directory));
store.connect();
where "directory" is the pathname of the directory containing
the mbox file.
3)now open the folder:
Folder folder = store.getDefaultFolder();
folder = folder.getFolder(mbox);
folder.open(Folder.READ_ONLY);
where "mbox" contains the name of the mbox file. Of course, this just
shows the method calling sequence that works for me. Many of these
methods throw exceptions. I leave exception handling as an exercise
for you because your program structure will probably not match mine.
I started by modifying the JavaMail mail reading example, but have since
rearranged it into a set of classes: the code I'm quoted from is in my
InputQueue class which hides the Store and Folder instants from the rest
of the application. InputQueue can read messages from mbox and from
servers via any of the standard connection protocols. Apart from a
constructor that reads system properties and sets up debug tracing, the
methods are:
connect
openInBox
hasMessages
getNextMessage
close
I still have to add a method for deleting messages (not for use with
mstor in my application).
HTH