JavaMail间歇性地在IMAPMessage.loadEnvelope()上抛出FolderClosedExcpetion

时间:2013-01-03 11:34:34

标签: java imap javamail

我有一个java服务,它使用来自Postfix邮件服务器的电子邮件。它每秒处理大约1封电子邮件并处理电子邮件的内容。

然而,非常间歇性地我得到了这个例外:

javax.mail.FolderClosedException : * BYE [ALERT] Fatal error: Invalid argument - javax.mail.FolderClosedException: * BYE [ALERT] Fatal error: Invalid argument
        at com.sun.mail.imap.IMAPMessage.loadEnvelope(IMAPMessage.java:1256)
        at com.sun.mail.imap.IMAPMessage.getSubject(IMAPMessage.java:335)
        at com.mailparser.data.MessageParser.parse(MessageParser.java:33)

如果我退出进程并再次重新启动它,它将始终在相同的消息上抛出相同的异常,因此它们会卡在收件箱中。

这是一个失败的代码片段:

if (!message.getFolder().isOpen()) {
    message.getFolder().open(Folder.READ_WRITE);
    Logger.log("Tried to reopen folder"); //This is never hit
}
ReceivedEmail incomingMessage = new ReceivedEmail();
try {
    incomingMessage.setSubject(message.getSubject()); // Exception happens here
    [...]
} catch {
    catch (FolderClosedException ex) {
        message.getFolder().open(Folder.READ_WRITE); 
        Logger.log("Reopened", LogType.debug);
        return null;
    }
}

正如您所看到的,我在尝试获取主题之前检查文件夹是否已打开,因此我怀疑还有其他因素导致此失败。一旦它推出了卡住消息的预期,它就会成功地使用完全相同的文件夹和连接。

有没有人对此有任何想法?

谢谢!

编辑:

Bill要求的调试信息:

   DEBUG IMAP: LOGIN command trace suppressed
    DEBUG IMAP: LOGIN command result: A0 OK LOGIN Ok.
    A1 CAPABILITY
    * CAPABILITY IMAP4rev1 UIDPLUS CHILDREN NAMESPACE THREAD=ORDEREDSUBJECT THREAD=REFERENCES SORT QUOTA IDLE ACL ACL2=UNION
    A1 OK CAPABILITY completed
    A2 LIST INBOX ""
    * LIST (\Marked \HasChildren) "." ""
    A2 OK LIST completed
    A3 LIST "" INBOX.TEST
    * LIST (\HasChildren) "." "INBOX.TEST"
    A3 OK LIST completed
    DEBUG: connection available -- size: 1
    A4 SELECT INBOX.TEST
    * FLAGS (\Draft \Answered \Flagged \Deleted \Seen \Recent)
    * OK [PERMANENTFLAGS (\* \Draft \Answered \Flagged \Deleted \Seen)] Limited
    * 1 EXISTS
    * 0 RECENT
    * OK [UIDVALIDITY 1351176418] Ok
    * OK [MYRIGHTS "acdilrsw"] ACL
    A4 OK [READ-WRITE] Ok

DEBUG IMAP: IMAPProtocol noop
A7 NOOP
A7 OK NOOP completed
A8 FETCH 1 (FLAGS)
* 1 FETCH (FLAGS (\Answered \Seen))
A8 OK FETCH completed.
A9 FETCH 1 (ENVELOPE INTERNALDATE RFC822.SIZE)
* BYE [ALERT] Fatal error: Invalid argument

0 个答案:

没有答案