javamail 解析eml文件的内容部分
解析内容部分代码:
public void getMailContent(Part part,String key) throws Exception { String contenttype=part.getContentType(); System.out.println("contenttype "+contenttype); int nameindex=contenttype.indexOf("name"); boolean conname=false; if(nameindex!=-1)conname=true; if(part.isMimeType("text/plain")&&!conname){ bodytext.append((String)part.getContent()); }else if(part.isMimeType("text/html")&&!conname){ bodytext.append((String)part.getContent()); } else if(part.isMimeType("multipart/*")){ Multipart multipart=(Multipart)part.getContent(); int counts=multipart.getCount(); for(int i=0;i<counts;i++){ getMailContent(multipart.getBodyPart(i),""); } }else if(part.isMimeType("message/rfc822")){ getMailContent((Part)part.getContent(),""); } else{} System.out.println(bodytext); }
运行后报错:
java.io.IOException: Error in encoded stream, got 1 at com.sun.mail.util.BASE64DecoderStream.decode(BASE64DecoderStream.java:148) at com.sun.mail.util.BASE64DecoderStream.read(BASE64DecoderStream.java:53) at com.sun.mail.util.BASE64DecoderStream.read(BASE64DecoderStream.java:78) at sun.nio.cs.StreamDecoder$CharsetSD.readBytes(Unknown Source) at sun.nio.cs.StreamDecoder$CharsetSD.implRead(Unknown Source) at sun.nio.cs.StreamDecoder.read(Unknown Source) at java.io.InputStreamReader.read(Unknown Source) at com.sun.mail.handlers.text_plain.getContent(text_plain.java:81) at javax.activation.DataSourceDataContentHandler.getContent(DataHandler.java:745) at javax.activation.DataHandler.getContent(DataHandler.java:501) at javax.mail.internet.MimeBodyPart.getContent(MimeBodyPart.java:564) at starsino.com.module.mail.reademl.ParseEmlDAO.getMailContent(ParseEmlDAO.java:186) at starsino.com.module.mail.reademl.ParseEmlDAO.getMailContent(ParseEmlDAO.java:192) at starsino.com.module.mail.reademl.ParseEmlDAO.readEmlFile(ParseEmlDAO.java:64) at starsino.com.bean.TestEml.main(TestEml.java:263)各位大侠 求解释…… 最好有完整的解析 eml 文件源代码 UQQ 270778796@qq.com 小弟感激不尽
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
用这段代码再试试?