throw new IllegalStateException("Error while retrieving the number of enclosed BodyPart objects.", e);
}
for (int i = 0; i < count; i++) {
final BodyPart bp;
try {
bp = multipart.getBodyPart(i);
}
catch (MessagingException e) {
throw new IllegalStateException("Error while retrieving body part.", e);
}
final String contentType;
String filename;
final String disposition;
final String subject;
try {
contentType = bp.getContentType();
filename = bp.getFileName();
disposition = bp.getDisposition();
subject = mailMessage.getSubject();
if (filename == null && bp instanceof MimeBodyPart) {
filename = ((MimeBodyPart) bp).getContentID();
}
}
catch (MessagingException e) {
throw new IllegalStateException("Unable to retrieve body part meta data.", e);
}
if (LOGGER.isInfoEnabled()) {
LOGGER.info(String.format("BodyPart - Content Type: '%s', filename: '%s', disposition: '%s', subject: '%s'",
new Object[]{contentType, filename, disposition, subject}));
}
if (Part.ATTACHMENT.equalsIgnoreCase(disposition)) {
LOGGER.info(String.format("Handdling attachment '%s', type: '%s'", filename, contentType));
}
final Object content;
try {
content = bp.getContent();
}
catch (IOException e) {
throw new IllegalStateException("Error while retrieving the email contents.", e);
}
catch (MessagingException e) {