I’m modifying the Coldfusion-based interface for a listserv admin application to show snippits of recently-posted messages on a page. The messages are all stored in a SQL Server 2005 database on the listserv’s mail server, and in theory it should be easy enough to query the recent ones and display them. However, the “message” column of the table that contains the e-mail record seems to contain all of the “souce code” of the e-mail, exactly as sent to the mail server. It contains control codes, e-mail headers and markup. For example, part of the message data returned in a query might look something like this:
This is a multi-part message in MIME format.
------_=_NextPart_001_01CA9A9E.B2224293 Content-Type: text/plain;
charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
All: =20 The correct time for Tuesday's call is 3 pm ET as noted on the agenda
(line breaks added for readability, this was actually all on one line).
When I display the message on the site, I just want it to look like this:
All:
The correct time for Tuesday's call is 3 pm ET as noted on the agenda
There’s actually a lot more complicated encodings than the example I’ve given. Some messages include base-64 encoded attachments, and similar things. How can I strip away all the e-mail code and markup and just display the text of the message?
I imagine somebody must have written some public code or some custom tag that does this, but my Google-fu has failed me thus far. Thanks.
You can use JavaMail to do this. If what you have in the DB is the full email, then you should be able to parse it into its component bits using JavaMail.
Not sure what your Java level is like, but this will return you all the elements you need, most likely. It gets a bit complicated handling complex messages, and requires a bit of recursion.
myEmailString is your column from the DB containing the entire raw email.
The result is a struct with properties:
The code (should work under CF8+ Java 1.6):