我有一个使用来自 Postfix 邮件服务器的电子邮件的 java 服务。它每秒处理大约 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;
}
}
如您所见,在尝试获取主题之前,我正在检查文件夹是否已打开,因此我怀疑是其他原因导致了此失败。一旦它抛出了对卡住消息的期望,它就会使用完全相同的文件夹和连接成功地进行。
有人对此有任何想法吗?
谢谢!
编辑:
比尔要求的调试信息:
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