1
votes

I'm trying to read messages from IMAP folders using javax.mail, but after fetchig few messages Im getting following exception:

* 20 FETCH ()
DEBUG IMAPS: ignoring bad response, THROW: 
com.sun.mail.iap.ParsingException: error in FETCH parsing, unrecognized item at index 12, starts with ")
    at com.sun.mail.imap.protocol.FetchResponse.parse(FetchResponse.java:219)
    at com.sun.mail.imap.protocol.FetchResponse.<init>(FetchResponse.java:96)
    at com.sun.mail.imap.protocol.IMAPProtocol.readResponse(IMAPProtocol.java:392)
    at com.sun.mail.iap.Protocol.command(Protocol.java:354)
    at com.sun.mail.imap.protocol.IMAPProtocol.fetch(IMAPProtocol.java:2113)
    at com.sun.mail.imap.protocol.IMAPProtocol.fetch(IMAPProtocol.java:2094)
    at com.sun.mail.imap.IMAPFolder.fetch(IMAPFolder.java:1253)
    at app.mail.imap.ImapClient.synchronizeLocalData(ImapClient.java:563)
    at app.mail.imap.ImapClient.lambda$6(ImapClient.java:351)
    at java.lang.Thread.run(Thread.java:745)
* BYE Internal error occurred. Refer to server log for more information. [2016-11-03 21:20:44]

This is the code Im using to read messages (session, store and folder are already opened):

final Message[] messages = imapFolder.getMessagesByUID(1, IMAPFolder.LASTUID);
final FetchProfile fp = new FetchProfile();
fp.add(FetchProfile.Item.ENVELOPE);
fp.add(FetchProfile.Item.FLAGS);
imapFolder.fetch(messages, fp);

for (final Message msg : messages)
{
    final long uid = imapFolder.getUID(msg);
    final String subject = MimeUtility.decodeText(msg.getSubject());
    final Date date = msg.getReceivedDate();
    info("MESSAGE: {} -> {} on {}", uid, subject, date);
}

It seems it's happening only on very specific messages and only when fetching more informations than message UID (if Im reading only uid then code works).

As far as I know many IMAP servers implementations lack many features from IMAP protocol. Bearing that in mind, what is safest and most reliable method for fetching and reading messages from IMAP folders?

javax.mail version: 1.5.3 (provided by wildfly app server 10.0.1.Final).

1
Can you add the command that was sent that caused the IMAP server to hiccup? - Max
Please post the JavaMail debug output. What server are you using? - Bill Shannon
The server you use has excellent protocol compliance and emits that error when there's file system corruption. (Maybe in other cases too.) Check the server log. - arnt
@BillShannon I'm using public e-mail servers from wp.pl. Full log i avalable here - radzionkow
The protocol has not asked for anything weird; it really does look like there's been corruption, or a severely broken message? I'm pretty sure any IMAP client will run into this same issue based on the log. If you can delete the messages elsewhere, that may help, otherwise, you may have to report to the provider. - Max

1 Answers

0
votes

Thanks for your help. It seems it is indeed IMAP server error. When I'm opening message in web client i get:

Connection error (#022).

Also KMail do not download messages for that folder (I bet other clients too).