对于某个ISP,我一直在为每条消息遇到此异常:
Caused by: com.sun.mail.iap.BadCommandException: A33 BAD Invalid attribute list in FETCH
at com.sun.mail.iap.Protocol.handleResult(Protocol.java:353)
at com.sun.mail.imap.protocol.IMAPProtocol.fetchRFC822(IMAPProtocol.java:1378)
at com.sun.mail.imap.IMAPMessage.getHeader(IMAPMessage.java:772)
经过检查,当程序试图像这样获取Message-ID
标题时似乎会发生:
message.getHeader("Message-ID")
但出于某种原因,如果我在按名称获取标题之前这样做:
Enumeration<?> headers = m.getAllHeaders();
while (headers.hasMoreElements()) {
Header header = (Header) headers.nextElement();
}
例外情况消失了。
此外,这里是我收到的标题列表:
[Return-Path, Received, Received, **Message-Id**, X-CT-Class, X-CT-Score, X-CT-RefID, X-CT-Spam, X-Authority-Analysis, X-CM-Score, Return-Path, DKIM-Signature, Received, List-Unsubscribe, **Message-ID**, MIME-Version, Reply-To, Subject, From, To, Date, Content-Type]
此处还有debug
日志:
DEBUG: setDebug: JavaMail version 1.5.6
DEBUG: getProvider() returning javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle]
DEBUG IMAPS: mail.imap.fetchsize: 16384
DEBUG IMAPS: mail.imap.ignorebodystructuresize: false
DEBUG IMAPS: mail.imap.statuscachetimeout: 1000
DEBUG IMAPS: mail.imap.appendbuffersize: -1
DEBUG IMAPS: mail.imap.minidletime: 10
DEBUG IMAPS: closeFoldersOnStoreFailure
DEBUG IMAPS: trying to connect to host "imap.cox.net", port 993, isSSL true
* OK [CAPABILITY IMAP4 AUTH=PLAIN] Ready
DEBUG IMAPS: AUTH: PLAIN
DEBUG IMAPS: protocolConnect login, host=imap.cox.net, user=ym1abc, password=<non-null>
DEBUG IMAPS: AUTHENTICATE PLAIN command trace suppressed
DEBUG IMAPS: AUTHENTICATE PLAIN command result: A0 OK [CAPABILITY IMAP4rev1 UIDPLUS NAMESPACE QUOTA] LOGIN completed
DEBUG IMAPS: connection available -- size: 1
A1 SELECT INBOX
* 5439 EXISTS
* OK [UNSEEN 2] First unseen message
* OK [UIDVALIDITY 1339789718] UIDs valid
* OK [UIDNEXT 518252] Predicted next UID
* FLAGS (\Answered \Flagged \Deleted \Draft \Seen)
* OK [PERMANENTFLAGS (\* \Answered \Flagged \Deleted \Draft \Seen)] Permanent flags
* 0 RECENT
A1 OK [READ-WRITE] SELECT completed
2017-01-06 16:31:27,882 INFO [main] org.abc.del.ibx.main.Main - 5439
A2 FETCH 1:20 (ENVELOPE INTERNALDATE RFC822.SIZE FLAGS BODYSTRUCTURE RFC822.SIZE RFC822.HEADER.LINES (X-PVIQ X-Campid X-Vitals X-PVIQ X-Originating-IP Received Message-ID Newsgroups Received-SPF X-Header-MasterId X-Header-CompanyDBUserName))
A2 BAD Invalid attribute list in FETCH
A3 FETCH 1 (RFC822.HEADER.LINES (Message-ID))
A3 BAD Invalid attribute list in FETCH
DEBUG IMAPS: IMAPProtocol noop
A4 NOOP
A4 OK NOOP completed
2017-01-06 16:31:28,854 ERROR [main] org.abc.del.ibx.utilities.Mutator - Exception :> A3 BAD Invalid attribute list in FETCH
javax.mail.MessagingException: A3 BAD Invalid attribute list in FETCH;
nested exception is:
com.sun.mail.iap.BadCommandException: A3 BAD Invalid attribute list in FETCH
at com.sun.mail.imap.IMAPMessage.getHeader(IMAPMessage.java:893)
at org.abc.del.ibx.utilities.Mutator.parseMessage(Mutator.java:59)
at org.abc.del.ibx.main.Main.processMessages(Main.java:147)
at org.abc.del.ibx.main.Main.main(Main.java:69)
在列表中,我看到Message-Id
标题重复。
所以我有几个问题:
造成异常的原因&amp;什么是比首先获得所有标题更好的解决方案?在我的情况下,我需要逐个获取所有标题,因为我们将其记录在DB中。
导致问题的重复标题是什么?