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!

.MessagingException - Missing start boundary when loading a mail twice

806955Oct 21 2010 — edited Oct 21 2010
Hi!

I have found a very interesting behaviour. When parsing a multipart mail twice, there is an error "javax.mail.MessagingException: Missing start boundary". This happens for every multipart mail which is fetched via POP3 and seems to be independant of both POP3 Server and the mail client the message was built with.

Environment:
debian linux, amd64, java 1.6
latest javamail from https://hg.kenai.com/hg/javamail~mercurial

Test program:
import java.io.*;
import javax.mail.*;

public class Mailtest {
private final static void loadMail(Part p) throws Exception{
Object content = p.getContent();
if (content instanceof Multipart) {
Multipart mp = (Multipart) content;
int cnt = mp.getCount();
for (int u=0;u<cnt;u++) {
loadMail(mp.getBodyPart(u));
}
}
}

public final static void main(String[] args) throws Exception {
//System.setProperty("mail.mime.cachemultipart", "true");
java.util.Properties props = new java.util.Properties();
Session mailSession = Session.getInstance(props, null);
Store store = mailSession.getStore("pop3");
store.connect("pop3srv", 110, "username", "pwd");
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_WRITE);

Message[] msgs = folder.getMessages();
for (int i=0;i<msgs.length;i++) {
/*if (msgs[i] instanceof com.sun.mail.pop3.POP3Message) {
System.out.println("inputstream");
InputStream in = msgs.getDataHandler().getInputStream();
in.close();
}*/

System.out.println("i=" + i + " try = 1");
loadMail(msgs[i]);
System.out.println("i=" + i + " try = 2");
loadMail(msgs[i]);
}
}
}

Output:
i=0 try = 1
i=0 try = 2
Exception in thread "main" javax.mail.MessagingException: Missing start boundary
at javax.mail.internet.MimeMultipart.parsebm(MimeMultipart.java:882)
at javax.mail.internet.MimeMultipart.parse(MimeMultipart.java:503)
at javax.mail.internet.MimeMultipart.getCount(MimeMultipart.java:244)
at testapp.Mailtest.loadMail(Mailtest.java:11)
at testapp.Mailtest.main(Mailtest.java:38)
Java Result: 1

I thought that the 2 code blocks which are commented might be a workaround, but nothing changed if both blocks are active.

BTW: What is "mail.mime.multipart.bmparse" supposed to do?
This post has been answered by Bill Shannon-Oracle on Oct 21 2010
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 18 2010
Added on Oct 21 2010
1 comment
1,286 views