I want to parse email messages directly from the filesystem using java (1.6) the email messages will be in a filesystem folder like
abc-12345.msg qwe-23456.msg
and will be in a standard format: for example:
MIME-Version: 1.0
Sender: mr.sender@gmail.com
Received: by 10.239.173.80 with HTTP; Thu, 12 Aug 2010 11:30:50 -0700 (PDT)
Date: Thu, 12 Aug 2010 15:30:50 -0300
Delivered-To: mr.recipient@gmail.com
Message-ID: <AANLkTikA-RbE_revkimBCWC2fUrG=t4T47AXq5FTx0vd@mail.gmail.com>
Subject: =?ISO-8859-1?Q?Hello_With_Acc=E9=F1ts?=
From: Mr Sender <mr.sender@gmail.com>
To: Mr Recipient <mr.recipient@gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
This is a testing one
Accent characters:
=E9=F3=FA=F1
Email End
I want to parse this file or use an existing library to parse the file to give me access to the headers / from / to / subject / body and so forth.
The files are all held on a local filesystem. I am no connecting to a message store through pop / imap. What is the easiest, most straightforward way for me to do this. The files may contain attachments.
Any suggestions are very welcome. If there is an existing api (perhaps javamail) that can do this could you please provide examples or references to examples.
Cheers Simon
You can use JavaMail immediatly for accessing IMAP and POP3-Stores, not for filesystem storage.
In JavaMail the access to email is organzied via implementations of javax.mail.Store. You can check JavaMail API - Third Party Products for implementations of javax.mail.Store for your special file format. Maybe you will implement javax.mail.Store by yourself, if you cannot find something appropriate. With using your Store, you can use all of the features of JavaMail eg attachment handling, all weird MIME stuff etc.
If you have the email text (that is the whole MIME payload) than I would use Mime4J.
The library is much easier to use, faster, and smaller footprint than "javax.mail".
use the javamail api:
for example: