Hi there
I've worked through the FAQ's and forum and based on the info available tried to construct code to deal with the whole "javax.mail.MessagingException: Missing start boundary" problem. I keep on getting a ClassCastException though and was hoping you could scan through the code and let me know if you see anything. I must be missing something ... simplified extract of code below:
Multipart mp = (Multipart)part.getContent();
try {
for (int i = 0; i < mp.getCount(); i++) {
processBodyPart(wrapper, mp.getBodyPart(i), i);
}
} catch (MessagingException e) {
// Converting Msg to a Copy (to fix boundary)
ByteArrayOutputStream bos = new ByteArrayOutputStream();
part.writeTo(bos);
byte[] bytes = bos.toByteArray();
MimeMessage newMsg = new MimeMessage(emailAccount.getSession(), new ByteArrayInputStream(bytes));
String ct = newMsg.getContentType();
newMsg.removeHeader("Content-Type");
ct = ct.substring(0, ct.indexOf(";")); // Strip out the rest, only retain the content-type
newMsg.setDataHandler(new DataHandler(newMsg.getContent(), ct));
Multipart testMp = (Multipart)newMsg.getContent(); // <<-------- ClassCastException here!!
for (int i = 0; i < testMp.getCount(); i++) {
Part bp = testMp.getBodyPart(i);
processBodyPart(bp);
}
}
Much appreciated.
Marius