我正在尝试使用IMAP 1.4.5从IMAP帐户中获取消息,并在BODYSTRUCTURE.parseParameters方法中获得一个空指针异常。
查看parseParameters代码,我发现这一行
list.set(null, "DONE"); // XXX - hack问题是set方法试图将.toLowerCase()调用为null值!
它试图解析的响应是:
* 1 FETCH (BODYSTRUCTURE (("TEXT" "PLAIN" ("CHARSET" "us-ascii") NIL NIL "7BIT" 55 4 NIL NIL NIL NIL)(("TEXT" "HTML" ("CHARSET" "us-ascii") NIL NIL "7BIT" 410 10 NIL NIL NIL NIL)("IMAGE" "JPEG" ("NAME" "image.jpg") "<53498286-6B3E-4AC8-8CA0-481152C80968@xxxx.it>" NIL "BASE64" 536628 NIL ("inline" ("FILENAME" "image.jpg")) NIL NIL) "RELATED" ("TYPE" "text/html" "BOUNDARY" "Apple-Mail=_56FA3EC6-FB02-4882-A1C5-487652E3B4E5") NIL NIL NIL) "ALTERNATIVE" ("BOUNDARY" "Apple-Mail=_CB164992-2501-4351-94D1-61CE7C8D90DC") NIL NIL NIL))而且,启用调试时,我会得到以下消息:
DEBUG IMAP: parsing BODYSTRUCTURE
DEBUG IMAP: msgno 1
DEBUG IMAP: parsing multipart
DEBUG IMAP: parsing BODYSTRUCTURE
DEBUG IMAP: msgno 1
DEBUG IMAP: single part
DEBUG IMAP: type TEXT
DEBUG IMAP: subtype PLAIN
DEBUG IMAP: parameter name CHARSET
DEBUG IMAP: parameter value us-ascii然后是NullPointerException
Exception in thread "main" java.lang.NullPointerException
at javax.mail.internet.ParameterList.set(ParameterList.java:165)
at com.sun.mail.imap.protocol.BODYSTRUCTURE.parseParameters(BODYSTRUCTURE.java:404)
at com.sun.mail.imap.protocol.BODYSTRUCTURE.<init>(BODYSTRUCTURE.java:224)
at com.sun.mail.imap.protocol.BODYSTRUCTURE.<init>(BODYSTRUCTURE.java:109)
at com.sun.mail.imap.protocol.FetchResponse.parse(FetchResponse.java:158)
at com.sun.mail.imap.protocol.FetchResponse.<init>(FetchResponse.java:67)
at com.sun.mail.imap.protocol.IMAPResponse.readResponse(IMAPResponse.java:136)
at com.sun.mail.imap.protocol.IMAPProtocol.readResponse(IMAPProtocol.java:270)
at com.sun.mail.iap.Protocol.command(Protocol.java:313)
at com.sun.mail.imap.protocol.IMAPProtocol.fetch(IMAPProtocol.java:1529)
at com.sun.mail.imap.protocol.IMAPProtocol.fetch(IMAPProtocol.java:1521)
at com.sun.mail.imap.protocol.IMAPProtocol.fetchBodyStructure(IMAPProtocol.java:1221)
at com.sun.mail.imap.IMAPMessage.loadBODYSTRUCTURE(IMAPMessage.java:1307)
at com.sun.mail.imap.IMAPMessage.getDataHandler(IMAPMessage.java:623)
at javax.mail.internet.MimeMessage.getContent(MimeMessage.java:927感谢任何能帮助我的人!
发布于 2012-11-06 18:10:34
您可能已经从两个不同版本的JavaMail中混合了JavaMail类。检查类路径中是否有javax.mail.*类的其他实例,可能在j2ee.jar或javaee.jar中。
发布于 2012-11-07 20:49:57
我终于发现了问题的原因。
我在我的项目中包括了Apache Cxf。
Cxf包含对geronimo_1.4_spec的引用,它覆盖了一些javamail类。
不包括对geronimo的引用,一切都正常工作!
发布于 2014-11-07 13:10:20
我也有类似的问题(也许是同样的问题)。
此问题与此Oracle 这里中描述的邮件服务器错误有关。
解决办法是:
或
// Get the message object from the folder in the
// usual way, for example:
MimeMessage msg = (MimeMessage)folder.getMessage(n);
// Copy the message by writing into an byte array and
// creating a new MimeMessage object based on the contents
// of the byte array:
ByteArrayOutputStream bos = new ByteArrayOutputStream();
msg.writeTo(bos);
bos.close();
SharedByteArrayInputStream bis =
new SharedByteArrayInputStream(bos.toByteArray());
MimeMessage cmsg = new MimeMessage(session, bis);
bis.close();
// The cmsg object is disconnected from the server so
// setFlags will have no effect (for example). Use
// the original msg object for such operations. Use
// the cmsg object to access the content of the message.我发现这多亏了甲骨文论坛线程
https://stackoverflow.com/questions/13251467
复制相似问题