* @param message mail message
* @return a mail delevery object
*/
// ENHANCEME: Not handling double byte (Japanese) language
public ERMailDelivery createMailDeliveryForMailMessage(ERCMailMessage message) throws MessagingException {
ERMailDelivery mail = null;
if (message.text() != null) {
mail = ERMailDeliveryHTML.newMailDelivery();
((ERMailDeliveryHTML)mail).setHTMLContent(message.text());
if (message.plainText() != null)
((ERMailDeliveryHTML)mail).setHiddenPlainTextContent(message.plainText());
} else {
mail = new ERMailDeliveryPlainText();
((ERMailDeliveryPlainText)mail).setTextContent(message.plainText());
}
// Add all of the addresses
mail.setFromAddress(message.fromAddress());
if (message.replyToAddress() != null)
mail.setReplyToAddress(message.replyToAddress());
mail.setToAddresses(message.toAddressesAsArray());
if (message.ccAddressesAsArray().count() > 0)
mail.setCCAddresses(message.ccAddressesAsArray());
if (message.bccAddressesAsArray().count() > 0)
mail.setBCCAddresses(message.bccAddressesAsArray());
// Set the xMailer if one is specified
// Note (tuscland): setXMailerHeader has a higher precedence over
// System property er.javamail.XMailerHeader
if (message.xMailer() != null)
mail.setXMailerHeader(message.xMailer());
// Set the content
mail.setSubject(messageTitlePrefix() + message.title());
if (message.hasAttachments()) {
for (Enumeration attachmentEnumerator = message.attachments().objectEnumerator(); attachmentEnumerator.hasMoreElements();) {
File fileAttachment = ((ERCMessageAttachment)attachmentEnumerator.nextElement()).file();
mail.addAttachment(new ERMailFileAttachment(fileAttachment.getName(), null, fileAttachment));
}
}
return mail;
}