/**
* Extracts the body from the Mail message
*/
public Object extractBodyFromMail(Exchange exchange, MailMessage mailMessage) {
Message message = mailMessage.getMessage();
try {
if (((MailEndpoint) exchange.getFromEndpoint()).getConfiguration().isMapMailMessage()) {
return message.getContent();
}
return message; // raw message
} catch (Exception e) {
// try to fix message in case it has an unsupported encoding in the Content-Type header
UnsupportedEncodingException uee = ObjectHelper.getException(UnsupportedEncodingException.class, e);
if (uee != null) {
LOG.debug("Unsupported encoding detected: " + uee.getMessage());
try {
String contentType = message.getContentType();
String type = ObjectHelper.before(contentType, "charset=");
if (type != null) {
// try again with fixed content type
LOG.debug("Trying to extract mail message again with fixed Content-Type: " + type);
// Since message is read-only, we need to use a copy