in common/servicemix-components/src/main/java/org/apache/servicemix/components/email/MimeMailMarshaler.java [68:145]
public void prepareExchange(MessageExchange exchange, NormalizedMessage normalizedMessage, MimeMessage mimeMessage) throws javax.mail.MessagingException {
String from = InternetAddress.toString(mimeMessage.getFrom());
String to = InternetAddress.toString(mimeMessage.getRecipients(Message.RecipientType.TO));
String cc = InternetAddress.toString(mimeMessage.getRecipients(Message.RecipientType.CC));
String replyTo = InternetAddress.toString(mimeMessage.getReplyTo());
String sentDate = getDateFormat().format(mimeMessage.getSentDate());
String text = null;
String html = null;
MimeMultipart mp = null;
Object content = null;
Object subContent = null;
MimeMultipart subMP = null;
try {
content = mimeMessage.getContent();
if (content instanceof String)
// simple mail
text = asString(content);
else if (content instanceof MimeMultipart) {
// mail with attachment
mp = (MimeMultipart)content;
int nbMP = mp.getCount();
for (int i=0; i < nbMP; i++) {
Part part = mp.getBodyPart(i);
String disposition = part.getDisposition();
if ((disposition != null) &&
((disposition.equals(Part.ATTACHMENT) ||
(disposition.equals(Part.INLINE))))) {
//Parts marked with a disposition of Part.ATTACHMENT from part.getDisposition() are clearly attachments
DataHandler att = part.getDataHandler();
normalizedMessage.addAttachment(att.getName(), att);
} else {
MimeBodyPart mbp = (MimeBodyPart)part;
if (mbp.isMimeType("text/plain")) {
// Handle plain
text = (String)mbp.getContent();
} else if (mbp.isMimeType("text/html")) {
// Handle html contents
html = (String)mbp.getContent();
} else if (mbp.isMimeType("multipart/related")){
// Special case for multipart/related message type
subContent = mbp.getContent();
if (subContent instanceof MimeMultipart) {
subMP = (MimeMultipart)subContent;
int nbsubMP = subMP.getCount();
for (int j=0; j < nbsubMP; j++) {
MimeBodyPart subMBP = (MimeBodyPart)part;
// add a property into the normalize message
normalizedMessage.setProperty("org.apache.servicemix.email.alternativeContent" + j, subMBP.getContent());
}
}
} else // strange mail...LOGGER a warning
logger.warn("Some mail contents can not be traited and is not include into message");
}
}
} else { // strange mail...LOGGER a warning
logger.warn("Some mail contents can not be traited and is not include into message");
}
} catch (MessagingException e) {
throw new javax.mail.MessagingException("Error while setting content on normalized message",e);
} catch (IOException e) {
throw new javax.mail.MessagingException("Error while fetching content",e);
}
normalizedMessage.setProperty("org.apache.servicemix.email.from", from);
normalizedMessage.setProperty("org.apache.servicemix.email.to", to);
normalizedMessage.setProperty("org.apache.servicemix.email.cc", cc);
normalizedMessage.setProperty("org.apache.servicemix.email.text", text);
normalizedMessage.setProperty("org.apache.servicemix.email.replyTo", replyTo);
normalizedMessage.setProperty("org.apache.servicemix.email.sentDate", sentDate);
normalizedMessage.setProperty("org.apache.servicemix.email.html", html);
try {
normalizedMessage.setContent(new StringSource(text));
} catch (MessagingException e) {
throw new javax.mail.MessagingException("Error while setting content on normalized message",e);
}
}