Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Missing start boundary exception, caused by an empty Part, how to handle?

843834Feb 22 2008 — edited Apr 2 2008
Hello,

i wrote an application that automatically handles mails from laboratories. The only essential part of the mail is the attachment, where chemical analyses are submitted (from permitted addresses, recognized by whitelist and fileheader of the attachment). Other ways to submit data weren't allowed.

Currently a mail was received that can't be parsed. It's from a laboratory, that
use its provider's (a german internet suplier named Arcor) webmail, a browser-based mailing portal. It always worked fine, because they wrote some greetings. But this time they sent a blank message. The result is following structure of the mail:

MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_Part_50112_10709369.1203586767396"

//Some X-Flags

------=_Part_50112_10709369.1203586767396
Content-Type: multipart/alternative;
boundary="*----=_Part_50111_24141780.1203586767396*"

------=_Part_50111_24141780.1203586767396--

------=_Part_50112_10709369.1203586767396
Content-Type: application/octet-stream
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=somefile.bin

ABCDEF.... //Some binary data
------=_Part_50112_10709369.1203586767396--

It seems the webmailer creates an empty mailpart and only writes the end boundary (Line: ------=_Part_50111_24141780.1203586767396--).

I know, the start boundary is really missing.

I checked it out by getting a mailaccount from Arcor, and it always creates this structure when sending a message without a text. By the way, the Message-ID (header) generated from Arcor's server seems to be from javamail. (.....1234.567890.....JavaMail.ngmail@....).
I don't know how many mailclients create "empty" parts, but impossible is nothing (e.g. other or future webmailer services).

But how to handle?

The error occures when calling MimeMultipart.getCount(), which causes to parse the mail if not parsed. All actions, which cause the mail to be parsed, will end in this exception (for this mail).
I looked at the javamail source and found out, that the line of the empty part is not recognized as a boundary, because of its ending delimiters:

if (line.equals(boundary))
break;

So the boundary is added to the preamble. It goes on with reading lines from the stream, until line == null.

if (line == null)
throw new MessagingException("Missing start boundary");

Because there is no test, if the line matches the end boundary, it's not recognized. Wouldn't it be better in this case, to add an empty bodypart and set a variable to false (e.g. complete) instead of throwing an exception? Because MimeMultipart.parse() is called by other methods, like getCount, getBodyPart and writeTo, I can't nearly do anything automatically with the mail. How should i walk through the bodyparts and fetch the parts I'm interested in?

Subclassing seems to be difficult to me:

Object content = message.getContent();
//javax.mail.Message, won't return a subclassed multipart

if (content instanceof Multipart) {
//recursive method!
handleMultipart((Multipart) content); //collecting parts from multipart
}

Of course, I could ask the laboratory: "please send me a greeting!" ;-)

Greetings,
cliff
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 30 2008
Added on Feb 22 2008
4 comments
3,295 views