protected String extractMessage(Email message) throws MessageExtractionException
{
if (message == null)
throw new MessageExtractionException("assertion failure: null message", logger);
logger.debug("extracted message {" + message + "}");
Hashtable<String,Part> att = new Hashtable<String,Part>();
Hashtable<String,String> inl = new Hashtable<String,String>();
Hashtable<String,String> imgs = new Hashtable<String,String>();
Hashtable<String,String> nonImgs = new Hashtable<String,String>();
Hashtable<String,String> ready = new Hashtable<String,String>();
ArrayList<String> mimeTypes = new ArrayList<String>();
String viewFileName;
try {
dumpPart((Part)message.getUnderlyingMessage(), att, inl, imgs, nonImgs, mimeTypes, message.getSubject());
for (String attachFileName: att.keySet()) {
Part p = (Part) att.get(attachFileName);
writeAttachment(p, attachFileName);
ready.put(attachFileName, attachFileName);
if (!imgs.containsKey(attachFileName) && !nonImgs.containsKey(attachFileName))
addAttachment(attachFileName, p.getContentType());
}
if (inl.containsKey("text/html")) {
viewFileName = prepareHTMLMessage(baseURL, inl, imgs, nonImgs, ready, mimeTypes);
} else if (inl.containsKey("text/plain")) {
viewFileName = preparePlaintextMessage(inl, imgs, nonImgs, ready, mimeTypes);
} else {
logger.debug("unable to extract message since the content type is unsupported. returning empty message body.");
return writeTempMessage("<html><head><META http-equiv=Content-Type content=\"text/html; charset="+serverEncoding+"\"></head><body></body></html>",".html");
}
} catch (Exception ex) {
throw new MessageExtractionException(ex.getMessage(),ex, logger);
}
logger.debug("message successfully extracted {filename='" + fileName + "' " + message + "}");
return viewFileName;
}