JavaMail,这个不知是什么问题、、、、
一调用这个判断是否包含附件的方法就出错,错误指向
“String disposition = mpart.getDisposition();”说这句有错
public boolean isContainAttach(Part part)throws Exception{
boolean attachflag = false;
String contentType = part.getContentType();
if(part.isMimeType("multipart/*")){
Multipart mp = (Multipart)part.getContent();
for(int i=0;i<mp.getCount();i++){
BodyPart mpart = mp.getBodyPart(i);
String disposition = mpart.getDisposition();
if((disposition != null) &&((disposition.equals(Part.ATTACHMENT)) ||(disposition.equals(Part.INLINE))))
attachflag = true;
else if(mpart.isMimeType("multipart/*")){
attachflag = isContainAttach((Part)mpart);
}else{
String contype = mpart.getContentType();
if(contype.toLowerCase().indexOf("application") != -1) attachflag=true;
if(contype.toLowerCase().indexOf("name") != -1) attachflag=true;
}
}
}else if(part.isMimeType("message/rfc822")){
attachflag = isContainAttach((Part)part.getContent());
}
return attachflag;
}
有时就没问题,有时就出现这种错误了!!
请高手指点
一调用这个判断是否包含附件的方法就出错,错误指向
“String disposition = mpart.getDisposition();”说这句有错
public boolean isContainAttach(Part part)throws Exception{
boolean attachflag = false;
String contentType = part.getContentType();
if(part.isMimeType("multipart/*")){
Multipart mp = (Multipart)part.getContent();
for(int i=0;i<mp.getCount();i++){
BodyPart mpart = mp.getBodyPart(i);
String disposition = mpart.getDisposition();
if((disposition != null) &&((disposition.equals(Part.ATTACHMENT)) ||(disposition.equals(Part.INLINE))))
attachflag = true;
else if(mpart.isMimeType("multipart/*")){
attachflag = isContainAttach((Part)mpart);
}else{
String contype = mpart.getContentType();
if(contype.toLowerCase().indexOf("application") != -1) attachflag=true;
if(contype.toLowerCase().indexOf("name") != -1) attachflag=true;
}
}
}else if(part.isMimeType("message/rfc822")){
attachflag = isContainAttach((Part)part.getContent());
}
return attachflag;
}
有时就没问题,有时就出现这种错误了!!
请高手指点
String disposition = mpart.getDisposition();
}
不知道你的错误是什么,大概推测了一下
我怀疑是不是编码造成的?我是用BACE64编码的
public void setAttachFile(String path, String name) throws Exception { //设置附件
BASE64Encoder enc = new BASE64Encoder();
MimeBodyPart messageBodyPart = new MimeBodyPart();
DataSource source = new FileDataSource(path);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName("=?GBK?B?"+enc.encode(name.getBytes())+"?=");
multipart.addBodyPart(messageBodyPart);
mult = true;
}
一样是指向String disposition = mpart.getDisposition();