Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > javamail and mbox

Reply
Thread Tools

javamail and mbox

 
 
Raymond Kososki
Guest
Posts: n/a
 
      01-31-2007
i'm finding all kinds of examples to read mail - with the email server
running pop or imap - but - i cannot find anything about using javamail to
read just plain old unix (SunOS or Solaris) mbox mail. anybody have some
sample code to do this?


 
Reply With Quote
 
 
 
 
Juan Singh
Guest
Posts: n/a
 
      01-31-2007
JavaMail is used to communicate with POP or IMAP server to fetch email
and AFAIK mbox is just a file used by UNIX/Linux hosts to store your
messages. You cannot use JavaMail to read an mbox file. See if POP or
IMAP is open on your Solaris box.





Raymond Kososki wrote:
> i'm finding all kinds of examples to read mail - with the email server
> running pop or imap - but - i cannot find anything about using javamail to
> read just plain old unix (SunOS or Solaris) mbox mail. anybody have some
> sample code to do this?
>
>

 
Reply With Quote
 
 
 
 
Raymond Kososki
Guest
Posts: n/a
 
      01-31-2007
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 ...

"Juan Singh" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed). ..
> JavaMail is used to communicate with POP or IMAP server to fetch email and
> AFAIK mbox is just a file used by UNIX/Linux hosts to store your messages.
> You cannot use JavaMail to read an mbox file. See if POP or IMAP is open
> on your Solaris box.
>
>
>
>
>
> Raymond Kososki wrote:
>> i'm finding all kinds of examples to read mail - with the email server
>> running pop or imap - but - i cannot find anything about using javamail
>> to read just plain old unix (SunOS or Solaris) mbox mail. anybody have
>> some sample code to do this?



 
Reply With Quote
 
Martin Gregorie
Guest
Posts: n/a
 
      02-01-2007
Raymond Kososki wrote:
> 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


--
martin@ | Martin Gregorie
gregorie. | Essex, UK
org |
 
Reply With Quote
 
Raymond Kososki
Guest
Posts: n/a
 
      02-07-2007
Many thanks Martin! I downloaded mstor and with the little program below
was able to successfully browse through my emails. the jars mbox.jar,
activation.jar and mail.jar are needed. This code runs on my sun box, which
is running SunOS 5.9. I am off and running - thanks!

package com.xxx.yyy.mstore;
import java.io.*;
import java.util.*;
import javax.mail.*;
public class Mstor {
public static void main(String[] args) {
Session session = Session.getDefaultInstance(new Properties());
try {
Store store = session.getStore(new URLName("mstor:/var/mail"));
store.connect();
//
// read messages from Inbox..
Folder inbox = store.getDefaultFolder().getFolder("user01");
inbox.open(Folder.READ_ONLY);
Message[] messages = inbox.getMessages();
System.out.println(messages.length);
try {
for (int i=0, n=messages.length; i<n; i++){
System.out.println(i + ": " + messages[i].getFrom()[0] +
"\t" + messages[i].getSubject());
messages[i].writeTo(System.out);
}
} catch (IOException ioe) {
ioe.printStackTrace();
}
inbox.close(false); // expunges all deleted messages if this
flag is true
store.close();
} catch (MessagingException me) {
me.printStackTrace();
}
}
}

"Martin Gregorie" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Raymond Kososki wrote:
>> 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
>
>
> --
> martin@ | Martin Gregorie
> gregorie. | Essex, UK
> org |



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
mailbox.mbox not locking mbox properly tinnews@isbd.co.uk Python 3 08-27-2010 08:09 PM
mailbox.mbox.add() appears to set both access and modification times tinnews@isbd.co.uk Python 0 12-19-2008 04:23 PM
mbox files steph Java 1 11-03-2004 06:22 PM
python, mbox files and forwarding messages Brad Tilley Python 2 10-28-2004 06:16 PM
Breaking apart MBOX MJackson Perl 1 02-19-2004 08:50 PM



Advertisments