What version of JavaMail are you using?
You might be running into one of the Gmail bugs described here.
Вопрос
We have an application that accesses an Gmail account (IMAP) using Java Mail API. Works fine for all types of emails except for a message that contains an .eml file as attachment and the message is sent using Thunderbird.
Here is the exception stack trace when trying to retrieve that message . Please advise.
Caused by: com.google.code.javax.mail.MessagingException: Unable to load BODYSTRUCTURE
at com.google.code.com.sun.mail.imap.IMAPMessage.loadBODYSTRUCTURE(IMAPMessage.java:1377)
at com.google.code.com.sun.mail.imap.IMAPMessage.getContentType(IMAPMessage.java:492)
Решение 2
What version of JavaMail are you using?
You might be running into one of the Gmail bugs described here.
Другие советы
I had success using this method. In short, if your Message
is of type MimeMessage
and if you are having this exception, create a new instance of MimeMessage from the original MimeMessage and work on it instead. For example, I was getting this error when I called getContent()
method of the Message, so I wrote this method to get content:
private Object getEmailContent(Message email) throws IOException, MessagingException {
try {
return email.getContent();
} catch (MessagingException e) {
// handling the bug
if (email instanceof MimeMessage && "Unable to load BODYSTRUCTURE".equalsIgnoreCase(e.getMessage())) {
return new MimeMessage((MimeMessage) email).getContent();
} else {
throw e;
}
}
}
GMail is known to produce malformed BODYSTRUCTURE
responses, see e.g. this message from their representative. Last time I checked (mid-2012), it remained unfixed.
Another possibility is that the file representing the emails are deleted from the mail server manually which result in the index(index file) created by the email server being wrong. This can cause the same error.
I was using Mail Enable and the solution is to delete the index file(_index.xml in my case)