How to get rid of 'Failed to load IMAP envelop

2019-02-20 10:47发布

问题:

I am trying to get the list of emails by Message msg[] = folder.getMessages();. After that I am getting the details of each message, meanwhile I am getting javax.mail.MessagingException: Failed to load IMAP envelope exception for some message.

This is protocol trace for the one message which producing error -

A7 FETCH 2 (ENVELOPE INTERNALDATE RFC822.SIZE)
* 2 FETCH (RFC822.SIZE 2567 INTERNALDATE "29-Apr-2011 13:49:01 +0000" ENVELOPE ("Fri, 29 Apr 2011 19:19:01 +0530" "I NEES YOUR ASSISANCE?????" (("Mr Leung Cheung" NIL "info" "milium.com.br")) (("Mr Leung Cheung" NIL "info" "milium.com.br")) ((NIL NIL "mr.leung_cheung" "live.hk")) () NIL NIL NIL "<20110429134718.70333732030A@mail2.milium.com.br>"))
A7 OK FETCH Completed

Stacktrace of error is-

Failed to load IMAP envelope stacktrace: javax.mail.MessagingException: Failed to load IMAP envelope
    at com.sun.mail.imap.IMAPMessage.loadEnvelope(IMAPMessage.java:1276)
    at com.sun.mail.imap.IMAPMessage.getSentDate(IMAPMessage.java:377)
    at com.my.main.model.TestMail.showAllMails(TestMail.java:95)
    at com.my.main.model.TestMail.main(TestMail.java:45)

I am using JavaMail-1.5.

How can I resolve this error, is there any way or settings to solve it and get details of message without skipping that message?

Thanks,

Neelam Sharma

回答1:

Your server is broken. Please report this error to the server vendor. What server are you using?

In the response, the message's "To" value must meet this syntax defined in the spec:

env-to      = "(" 1*address ")" / nil
address     = "(" addr-name SP addr-adl SP addr-mailbox SP addr-host ")"

Instead, the server has returned "()". It should've returned "NIL" if there is no To header.

You can work around server bugs using the technique described in the JavaMail FAQ.