logger.trace("MIME parser extracted TEXT part: {}", (String) content);
if ((dis != null) && dis.equals(Part.ATTACHMENT)) {
// add text part as attachment
message.addPart(partId, new MimePart(part));
} else {
// if no disposition, then add to message body
if(part.isMimeType("text/html")) {
htmlBody.append((String) content);
} else {
textBody.append((String) content);
}
}
} else if (content instanceof MimeMultipart) {
MimeMultipart multipart = (MimeMultipart) content;
for (int i = 0; i < multipart.getCount(); i++)
{
// build next part id
StringBuilder nextPartId = new StringBuilder(partId);
// add period if not at root level
if (!partId.isEmpty())
nextPartId.append(".");
int localPartId = i+1; // IMAPv4 MIME part counter starts from 1
nextPartId.append(localPartId);
Part nextPart = multipart.getBodyPart(i);
parseMessagePart(nextPart, nextPartId.toString());
}
} else if ((content instanceof InputStream)
|| (content instanceof MimeMessage)) {
// binary, message/rfc822 or text attachment
message.addPart(partId, new MimePart(part));
} else {
throw new MessagingException("Unkonwn message part type " + content.getClass().getName());
}
}