「已注销」 2015-04-09 03:30 采纳率: 0%
浏览 2767

javamail 收取邮件的附件保存,出现很奇葩的错误,各位大神快看看吧

/**

* 【保存附件】

/

public void saveAttachMent(Part part) throws Exception {

String fileName = "";

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)))) {

fileName = mpart.getFileName();

if((fileName != null)){
if (fileName.toLowerCase().indexOf("gb2312") != -1) {

fileName = MimeUtility.decodeText(fileName);

}

}
saveFile(fileName, mpart.getInputStream());

} else if (mpart.isMimeType("multipart/*")) {

saveAttachMent(mpart);

} else {

fileName = mpart.getFileName();

if ((fileName != null)

&& (fileName.toLowerCase().indexOf("GB2312") != -1)) {

fileName = MimeUtility.decodeText(fileName);

saveFile(fileName, mpart.getInputStream());

}

}

}

} else if (part.isMimeType("message/rfc822")) {

saveAttachMent((Part) part.getContent());

}

private void saveFile(String fileName, InputStream in) throws Exception {

String root = ServletActionContext.getServletContext().getRealPath("/upload");

    File file = new File(root); 
    if (!file.exists()) {
        file.mkdir();

}
System.out.println("file path: " + file.toString()+"/"+fileName);

BufferedOutputStream bos = null;

BufferedInputStream bis = null;

try {

bos = new BufferedOutputStream(new FileOutputStream(new File(root,fileName)));

bis = new BufferedInputStream(in);

int c;

byte[] buffer = new byte[500];
while ((c = bis.read()) != -1) { //到这报错了
bos.write(c);

bos.flush();

}

} catch (Exception exception) {

exception.printStackTrace();

throw new Exception("文件保存失败!");

} finally {

bos.close();

bis.close();

}

错误很奇怪:
java.io.IOException: A9 BAD Parse command error
at com.sun.mail.imap.IMAPInputStream.fill(IMAPInputStream.java:151)
at com.sun.mail.imap.IMAPInputStream.read(IMAPInputStream.java:208)
at com.sun.mail.imap.IMAPInputStream.read(IMAPInputStream.java:234)
at com.sun.mail.util.BASE64DecoderStream.getByte(BASE64DecoderStream.java:354)
at com.sun.mail.util.BASE64DecoderStream.decode(BASE64DecoderStream.java:245)
at com.sun.mail.util.BASE64DecoderStream.read(BASE64DecoderStream.java:140)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:235)
at java.io.BufferedInputStream.read(BufferedInputStream.java:254)
at ericsson.csdp.entity.ReciveOneMail.saveFile(ReciveOneMail.java:170)
at ericsson.csdp.entity.ReciveOneMail.saveAttachMent(ReciveOneMail.java:135)
at ericsson.csdp.service.hc.RecordService.updateRecordFromEmail(RecordService.java:2063)
at ericsson.csdp.service.hc.RecordService$$FastClassByCGLIB$$fd58d774.invoke()
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:698)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:51)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.aspectj.AspectJAfterThrowingAdvice.invoke(AspectJAfterThrowingAdvice.java:55)

  • 写回答

1条回答 默认 最新

  • _Bison 2015-04-09 04:30
    关注

    应该是系统的安全性能做的太好了把,苹果系统一般都 有

    评论

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?