servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bsny...@apache.org
Subject svn commit: r472747 - in /incubator/servicemix/trunk/common/servicemix-components/src: main/java/org/apache/servicemix/components/email/ test/java/org/apache/servicemix/components/email/
Date Thu, 09 Nov 2006 02:55:51 GMT
Author: bsnyder
Date: Wed Nov  8 18:55:51 2006
New Revision: 472747

URL: http://svn.apache.org/viewvc?view=rev&rev=472747
Log:
Adding suport for multiple to, cc and bcc recipients per SM-675.

Modified:
    incubator/servicemix/trunk/common/servicemix-components/src/main/java/org/apache/servicemix/components/email/MailMarshalerSupport.java
    incubator/servicemix/trunk/common/servicemix-components/src/main/java/org/apache/servicemix/components/email/MimeMailMarshaler.java
    incubator/servicemix/trunk/common/servicemix-components/src/test/java/org/apache/servicemix/components/email/MimeMailTest.java

Modified: incubator/servicemix/trunk/common/servicemix-components/src/main/java/org/apache/servicemix/components/email/MailMarshalerSupport.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/common/servicemix-components/src/main/java/org/apache/servicemix/components/email/MailMarshalerSupport.java?view=diff&rev=472747&r1=472746&r2=472747
==============================================================================
--- incubator/servicemix/trunk/common/servicemix-components/src/main/java/org/apache/servicemix/components/email/MailMarshalerSupport.java
(original)
+++ incubator/servicemix/trunk/common/servicemix-components/src/main/java/org/apache/servicemix/components/email/MailMarshalerSupport.java
Wed Nov  8 18:55:51 2006
@@ -201,6 +201,10 @@
     }
 
     protected Address[] asAddressArray(Object value) throws AddressException {
+    	if (value instanceof String) {
+    		Address[] addresses = InternetAddress.parse((String)value);
+    		return addresses;
+    	}
         if (value instanceof Address[]) {
             return (Address[]) value;
         }

Modified: incubator/servicemix/trunk/common/servicemix-components/src/main/java/org/apache/servicemix/components/email/MimeMailMarshaler.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/common/servicemix-components/src/main/java/org/apache/servicemix/components/email/MimeMailMarshaler.java?view=diff&rev=472747&r1=472746&r2=472747
==============================================================================
--- incubator/servicemix/trunk/common/servicemix-components/src/main/java/org/apache/servicemix/components/email/MimeMailMarshaler.java
(original)
+++ incubator/servicemix/trunk/common/servicemix-components/src/main/java/org/apache/servicemix/components/email/MimeMailMarshaler.java
Wed Nov  8 18:55:51 2006
@@ -153,17 +153,17 @@
      */
     public void prepareMessage(MimeMessage mimeMessage, MessageExchange exchange, NormalizedMessage
normalizedMessage) throws javax.mail.MessagingException {
         try {
-            Address to = getTo(exchange, normalizedMessage);
+            Address[] to = getTo(exchange, normalizedMessage);
             if (to != null) {
-                mimeMessage.setRecipient(Message.RecipientType.TO, to);
+                mimeMessage.setRecipients(Message.RecipientType.TO, to);
             }
-            Address cc = getCc(exchange, normalizedMessage);
+            Address[] cc = getCc(exchange, normalizedMessage);
             if (cc != null) {
-                mimeMessage.setRecipient(Message.RecipientType.CC, cc);
+                mimeMessage.setRecipients(Message.RecipientType.CC, cc);
             }
-            Address bcc = getBcc(exchange, normalizedMessage);
+            Address[] bcc = getBcc(exchange, normalizedMessage);
             if (bcc != null) {
-                mimeMessage.setRecipient(Message.RecipientType.BCC, bcc);
+                mimeMessage.setRecipients(Message.RecipientType.BCC, bcc);
             }
             Address from = getFrom(exchange, normalizedMessage);
             if (from != null) {
@@ -245,16 +245,16 @@
         return asAddress(getFrom().evaluate(exchange, normalizedMessage));
     }
 
-    protected Address getTo(MessageExchange exchange, NormalizedMessage normalizedMessage)
throws MessagingException, AddressException {
-        return asAddress(getTo().evaluate(exchange, normalizedMessage));
+    protected Address[] getTo(MessageExchange exchange, NormalizedMessage normalizedMessage)
throws MessagingException, AddressException {
+        return asAddressArray(getTo().evaluate(exchange, normalizedMessage));
     }
 
-    protected Address getCc(MessageExchange exchange, NormalizedMessage normalizedMessage)
throws MessagingException, AddressException {
-        return asAddress(getCc().evaluate(exchange, normalizedMessage));
+    protected Address[] getCc(MessageExchange exchange, NormalizedMessage normalizedMessage)
throws MessagingException, AddressException {
+        return asAddressArray(getCc().evaluate(exchange, normalizedMessage));
     }
 
-    protected Address getBcc(MessageExchange exchange, NormalizedMessage normalizedMessage)
throws MessagingException, AddressException {
-        return asAddress(getBcc().evaluate(exchange, normalizedMessage));
+    protected Address[] getBcc(MessageExchange exchange, NormalizedMessage normalizedMessage)
throws MessagingException, AddressException {
+        return asAddressArray(getBcc().evaluate(exchange, normalizedMessage));
     }
 
     protected Address[] getReplyTo(MessageExchange exchange, NormalizedMessage normalizedMessage)
throws MessagingException, AddressException {

Modified: incubator/servicemix/trunk/common/servicemix-components/src/test/java/org/apache/servicemix/components/email/MimeMailTest.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/common/servicemix-components/src/test/java/org/apache/servicemix/components/email/MimeMailTest.java?view=diff&rev=472747&r1=472746&r2=472747
==============================================================================
--- incubator/servicemix/trunk/common/servicemix-components/src/test/java/org/apache/servicemix/components/email/MimeMailTest.java
(original)
+++ incubator/servicemix/trunk/common/servicemix-components/src/test/java/org/apache/servicemix/components/email/MimeMailTest.java
Wed Nov  8 18:55:51 2006
@@ -65,6 +65,35 @@
 
         assertEquals("subject", "Hello from JUnit!", mail.getSubject());
     }
+    
+    public void testSendUsingMessagePropertiesWithMultipleRecipients() throws Exception {
+
+        // START SNIPPET: email
+        InOnly exchange = client.createInOnlyExchange();
+        NormalizedMessage message = exchange.getInMessage();
+
+        message.setProperty("org.apache.servicemix.email.to", "scm@servicemix.org,foo@servicemix.org");
+        message.setProperty("org.apache.servicemix.email.cc", "bar@servicemix.org,baz@servicemix.org");
+        message.setProperty("org.apache.servicemix.email.bcc", "guinness@servicemix.org,harper@servicemix.org");
+        message.setProperty("org.apache.servicemix.email.from", "junit@servicemix.org");
+        message.setProperty("org.apache.servicemix.email.subject", "Hello from JUnit!");
+        message.setProperty("org.apache.servicemix.email.text", "Hi from test case: " + getName()
+ " running at: " + new Date());
+
+        client.send(exchange);
+        // END SNIPPET: email
+
+        // lest find the test sender
+        StubJavaMailSender sender = (StubJavaMailSender) getBean("javaMailSender");
+        sender.assertMessagesReceived(1);
+        List messages = sender.getMessages();
+        assertEquals("message size: " + messages, 1, messages.size());
+
+        MimeMessage mail = (MimeMessage) messages.get(0);
+
+        System.out.println("Created message: " + message);
+
+        assertEquals("subject", "Hello from JUnit!", mail.getSubject());
+    }
 
     public void testUsingXPathExpressionsInEmail() throws Exception {
 



Mime
View raw message