1 17 package org.apache.servicemix.components.email; 18 19 import java.util.Date ; 20 21 import javax.jbi.messaging.MessageExchange; 22 import javax.jbi.messaging.MessagingException; 23 import javax.jbi.messaging.NormalizedMessage; 24 import javax.mail.internet.AddressException ; 25 import javax.xml.transform.TransformerException ; 26 27 import org.springframework.mail.SimpleMailMessage; 28 29 35 public class SimpleMailMarshaler extends MailMarshalerSupport{ 36 37 45 public void prepareMessage(SimpleMailMessage mailMessage, MessageExchange exchange, NormalizedMessage normalizedMessage) throws javax.mail.MessagingException { 46 try { 47 Object to = getTo(exchange, normalizedMessage); 48 if (to != null) { 49 if (to instanceof String ) { 50 mailMessage.setTo((String ) to); 51 } 52 else { 53 mailMessage.setTo((String []) to); 54 } 55 } 56 Object cc = getCc(exchange, normalizedMessage); 57 if (cc != null) { 58 if (cc instanceof String ) { 59 mailMessage.setCc((String ) cc); 60 } 61 else { 62 mailMessage.setCc((String []) cc); 63 } 64 } 65 Object bcc = getBcc(exchange, normalizedMessage); 66 if (bcc != null) { 67 if (bcc instanceof String ) { 68 mailMessage.setBcc((String ) bcc); 69 } 70 else { 71 mailMessage.setBcc((String []) bcc); 72 } 73 } 74 String from = getFrom(exchange, normalizedMessage); 75 if (from != null) { 76 mailMessage.setFrom(from); 77 } 78 String replyTo = getReplyTo(exchange, normalizedMessage); 79 if (replyTo != null) { 80 mailMessage.setReplyTo(replyTo); 81 } 82 83 String text = getText(exchange, normalizedMessage); 84 if (text != null) { 85 mailMessage.setText(text); 86 } 87 String subject = getSubject(exchange, normalizedMessage); 88 if (subject != null) { 89 mailMessage.setSubject(subject); 90 } 91 Date sentDate = getSentDate(exchange, normalizedMessage); 92 if (sentDate != null) { 93 mailMessage.setSentDate(sentDate); 94 } 95 } 96 catch (MessagingException e) { 97 throw new javax.mail.MessagingException (e.getMessage(), e); 98 } 99 catch (TransformerException e) { 100 throw new javax.mail.MessagingException (e.getMessage(), e); 101 } 102 } 103 104 protected String getFrom(MessageExchange exchange, NormalizedMessage normalizedMessage) throws MessagingException, AddressException { 107 return asString(getFrom().evaluate(exchange, normalizedMessage)); 108 } 109 110 protected String getReplyTo(MessageExchange exchange, NormalizedMessage normalizedMessage) throws MessagingException { 111 return asString(getReplyTo().evaluate(exchange, normalizedMessage)); 112 } 113 114 protected Object getTo(MessageExchange exchange, NormalizedMessage normalizedMessage) throws MessagingException, AddressException { 115 return asStringOrStringArray(getTo().evaluate(exchange, normalizedMessage)); 116 } 117 118 protected Object getCc(MessageExchange exchange, NormalizedMessage normalizedMessage) throws MessagingException, AddressException { 119 return asStringOrStringArray(getCc().evaluate(exchange, normalizedMessage)); 120 } 121 122 protected Object getBcc(MessageExchange exchange, NormalizedMessage normalizedMessage) throws MessagingException, AddressException { 123 return asStringOrStringArray(getBcc().evaluate(exchange, normalizedMessage)); 124 } 125 126 127 } 128 | Popular Tags |