javax.mail 1.6.2版本解析含图文附件的eml文件丢失图片问题求助
javax.mail 1.6.2解析多内容EML时图片丢失问题
使用javax.mail 1.6.2版本解析同时包含文本、内嵌图片和附件的EML文件时,出现图片丢失异常:读取后的MimeMessage写入新文件(verify.eml)内容完全正确,但通过getContent()获取的MimeMultipart对象中缺失了图片部分。
验证代码
public static void main(String[] args) { //this eml file contains text, picture,attachment at the same time; String emlFilePath1 = "C:\Users\userName\Desktop\textPictureAttachment.eml"; try (InputStream is1 = new FileInputStream(emlFilePath1)) { Session session = Session.getDefaultInstance(new Properties()); MimeMessage message1 = new MimeMessage(session, is1); // accroding to the verify.eml,the message1's content is corrent at this momment; message1.writeTo(new FileOutputStream("C:\Users\userName\Desktop\verify.eml")); // multipart1's parts missed the picture MimeMultipart multipart1 = (MimeMultipart) message1.getContent(); } catch (IOException | MessagingException e) { e.printStackTrace(); }
核心现象
- 将
MimeMessage写入新文件后内容完整,说明EML文件已被正确加载到内存中 - 调用
getContent()解析得到的MimeMultipart丢失了内嵌图片组件
内容的提问来源于stack exchange,提问作者Korey
相关产品推荐
相关产品推荐

