【发布时间】:2015-04-17 20:01:15
【问题描述】:
我正在使用 javamail-1.4.5 从 gmail (imap) 获取消息。如果 Content-Disposition 有一个不带引号的参数,方法 getDisposition 会失败。
消息部分:
Content-Transfer-Encoding: 7bit
Content-Type: message/rfc822
Content-Disposition: attachment;
creation-date=Wed, 11 Feb 2015 10:23:48 GMT;
modification-date=Wed, 11 Feb 2015 10:23:48 GMT
例外:
javax.mail.internet.ParseException: Expected ';', got ","
at javax.mail.internet.ParameterList.<init>(ParameterList.java:289)
at javax.mail.internet.ContentDisposition.<init>(ContentDisposition.java:100)
at javax.mail.internet.MimeBodyPart.getDisposition(MimeBodyPart.java:1076)
UPD1:这是我的代码的一部分。我在方法 handlePart 中遇到错误,第 1 行
private void handleMessage(Message message) {
Object content = message.getContent();
if(content instanceof Multipart) {
handleMultipart((Multipart) content);
}
else {
handlePart(message);
}
}
private void handleMultipart(Multipart mp) {
for(int i = 0; i < mp.getCount(); i++) {
Part part = mp.getBodyPart(i);
Object content = part.getContent();
if(content instanceof Multipart) {
handleMultipart((Multipart) content);
}
else {
handlePart(part);
}
}
}
private void handlePart(Part part) {
String disposition = part.getDisposition(); //GETTING ERROR
String contentType = part.getContentType();
if(disposition == null) {
if(contentType.toLowerCase().startsWith("text/html")) {
html = (String) part.getContent();
}
else if(contentType.toLowerCase().startsWith("text/plain")) {
text = (String) part.getContent();
}
else {
handleAttachment(part);
}
}
else if(disposition.equalsIgnoreCase(Part.ATTACHMENT)) {
handleAttachment(part);
}
else if(disposition.equalsIgnoreCase(Part.INLINE)) {
handleAttachment(part);
}
}
【问题讨论】:
-
请添加您的代码。
标签: java gmail jakarta-mail imap