Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2006

Tip: Looking for answers? Try searching our database.

Generic format for saving EMails

Thread view: 
aaronfude@gmail.com - 11 Jan 2006 12:27 GMT
Hi,

This is probably mostly off-topic, but since java is my tool of choice
and I am using javamail heavily, I decided to post this message here.

We have written a number of java tools for analyzing the contets of an
imap mailbox. What we would like to be able to do is save a particular
email message as a file on our hard drive. Is there a more or less
generic format for doing so and if so, can it be created in java?
(Something like the .eml)

The file should contain all information pertaining to the email (from,
to, subject, content, attatchments, etc.)

Many thanks in advance!

Aaron Fude
Boris Gorjan - 11 Jan 2006 13:19 GMT
> Hi,
>
[quoted text clipped - 13 lines]
>
> Aaron Fude

.eml is basicly headers + {plain text | mime multipart}
See javax.mail.internet.MimeMultipart
Alan Krueger - 11 Jan 2006 13:49 GMT
> We have written a number of java tools for analyzing the contets of an
> imap mailbox. What we would like to be able to do is save a particular
[quoted text clipped - 4 lines]
> The file should contain all information pertaining to the email (from,
> to, subject, content, attatchments, etc.)

Simply saving the message as a text file in the format in which it
arrived (RFC 822/2822) is the simplest way.  I believe that corresponds
to the ".eml" extension used by many email clients.

Or, you could just serialize the Java objects to a file.

Another, fairly venerable (read: old) way of storing emails is the mbox
format.  http://en.wikipedia.org/wiki/Mbox
Thomas Weidenfeller - 11 Jan 2006 14:04 GMT
> We have written a number of java tools for analyzing the contets of an
> imap mailbox. What we would like to be able to do is save a particular
> email message as a file on our hard drive. Is there a more or less
> generic format for doing so and if so, can it be created in java?
> (Something like the .eml)

(Unix) mbox format. It is extremely simple, and for a single message
almost boils down to just the messages contents as received.

An mbox file is an ASCII file, containing a sequence of e-mails. Each
entry (e-mail) in an mbox begins with a "From " line (note, no ':' in
that tag). This is *not* the "From:"-header (note the ':' here), but was
originally the UUCP path. Today the SMTP sender should go there if
possible but mail programs often place nonsense into it, or repeat the
"From:"-header.

E.g. a "From " line looks like:

    From someone@example.com Fri Mar 28 10:02:15 2006

The "From " line is followed by the mail. First the mail headers, then
the mail body, separated by an empty line. Which is the format as
specified for SMTP in RFC 2822.

At the end of the mail an empty line is perpended.

In case a line in the mail body starts with "From ", the "From " is
perpended with an '>' to avoid that this mail body line is interpreted
as the "From " line which starts a new entry. That quote is supposed to
be removed again when a program displays the mail.

A common extension is that any line in the mail body which already
starts with a quoted from (e.g. ">From ", or ">>From ") is also quoted
one more time, and that a program displaying such a mail always removes
one quote level from a line which starts with a quoted from.

The result looks something like:

    From someone@example.com Fri Mar 28 10:02:15 2006
    Subject: some subject
    Date: 28 Mar 2006 08:02:15 GMT
    From: someone@example.com
    To: someone-else@example.com

    The mail body>
    >From now on we do the following things ...
    [an empty line]
    [next mail, if any, follows here]

Some people hate the format, because it is not "database-ish" enough for
them. But it works like a charm.

> The file should contain all information pertaining to the email (from,
> to, subject, content, attatchments, etc.)

Attachments are sent inline in a mail body, so that is no problem (mails
with attachments are just MIME mails). The other stuff is in the
headers. In case you need to store additional own management
information, it is typical to invent "X" headers and just add them to
the normal mail headers:

    X-Your-App-Name-Something: a value
    X-Your-App-Name-Something-else: another value

In case you need per-mbox file information, it is typical to add a
pseudo mail to the beginning of such a file. Your program is then
supposed to know about this mail.

/Thomas
Signature

The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.