javax.mail which version is 1.6.2 will have the problem of losing pictures when parsing eml files that contain text, pictures and attachments at the same time.
I wrote the following code to verify this question:
`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();
}
}`
I have solved this problem.The parts in the object which returned by message1.getContent are not lost.One of the part's content-type is 'multipart/related',this is the key to solving the problem.Due to the content-type,this part has nested content which contains my pictures.