head.appendChild(sent);
}
email.appendChild(head);
// Complete the XML representation with the text part of the message
Representation content = null;
if (message.getContent() instanceof Multipart) {
// Look for the text part of the mail.
final Multipart multipart = (Multipart) message.getContent();
for (int i = 0, n = multipart.getCount(); i < n; i++) {
final Part part = multipart.getBodyPart(i);
final String disposition = part.getDisposition();
if (disposition != null) {
if (disposition.equals(Part.ATTACHMENT)
|| disposition.equals(Part.INLINE)) {
// create a representation from part.getInputStream()
}
} else {
// Check if plain text
final MimeBodyPart mimeBodyPart = (MimeBodyPart) part;
final ContentType contentType = new ContentType(
mimeBodyPart.getContentType());
if (MediaType.TEXT_PLAIN.equals(contentType.getMediaType(),
true)) {
content = new InputRepresentation(mimeBodyPart
.getInputStream(), MediaType.TEXT_PLAIN);
break;
}
// TODO Special non-attachment cases here of
// image/gif, text/html, ...
}
}
} else {
// Add the email body
if (message.getContentType() != null) {
final ContentType contentType = new ContentType(message
.getContentType());
if (MediaType.TEXT_PLAIN.equals(contentType.getMediaType(),
true)) {
content = new InputRepresentation(message.getInputStream(),
MediaType.TEXT_PLAIN);
}
}
}
if (content != null) {
final Element body = dom.createElement("body");
final CDATASection bodyContent = dom.createCDATASection(content
.getText());
body.appendChild(bodyContent);
email.appendChild(body);
}
}