Hi,
I want to save all inline images into a certain directory and all attachments into another directory.
I use the following code to do this:
Multipart multipart = (Multipart) message.getContent();
for (int x = 0; x < multipart.getCount(); x++) {
BodyPart bodyPart = multipart.getBodyPart(x);
String disposition = bodyPart.getDisposition();
if(disposition != null){
log.debug("Disposition: " + disposition);
if (disposition.equals(BodyPart.ATTACHMENT)) {
log.debug("Mail has attachment: ");
DataHandler handler = bodyPart.getDataHandler();
log.debug("FILENAME: " + handler.getName());
saveAttachment(session, bodyPart, emailData);
}
else if(disposition.equals(BodyPart.INLINE)){
log.debug("Mail has inline attachment: ");
DataHandler handler = bodyPart.getDataHandler();
log.debug("Inline FILENAME: " + handler.getName());
saveInlineAttachment(session, bodyPart, emailData);
}
}
else {
log.debug(bodyPart.getContent());
}
}
This approach works when the email has inline images only or attachments only.
It does not work when the email has both inline images and attachments. (Only the attachments are saved).
Come someone please help me correct my solution so that it can process an email that has both inline images and attachments and save them in different directories.
Thank you