You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by cm...@apache.org on 2012/01/22 23:04:14 UTC

svn commit: r1234628 - in /camel/branches/camel-2.9.x/components/camel-mail/src: main/java/org/apache/camel/component/mail/MailBinding.java test/java/org/apache/camel/component/mail/MailReplyToTest.java

Author: cmueller
Date: Sun Jan 22 22:04:13 2012
New Revision: 1234628

URL: http://svn.apache.org/viewvc?rev=1234628&view=rev
Log:
CAMEL-4804: Add replyTo option to camel mail component

Modified:
    camel/branches/camel-2.9.x/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java
    camel/branches/camel-2.9.x/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailReplyToTest.java

Modified: camel/branches/camel-2.9.x/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java?rev=1234628&r1=1234627&r2=1234628&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java (original)
+++ camel/branches/camel-2.9.x/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java Sun Jan 22 22:04:13 2012
@@ -20,6 +20,7 @@ import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.nio.charset.Charset;
 import java.nio.charset.IllegalCharsetNameException;
+import java.util.ArrayList;
 import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -90,7 +91,11 @@ public class MailBinding {
             replyTo = endpoint.getConfiguration().getReplyTo();
         }
         if (replyTo != null) {
-            mimeMessage.setReplyTo(new InternetAddress[]{new InternetAddress(replyTo)});
+            ArrayList<InternetAddress> replyToAddresses = new ArrayList<InternetAddress>();
+            for (String reply : splitRecipients(replyTo)) {
+                replyToAddresses.add(new InternetAddress(reply.trim()));
+            }
+            mimeMessage.setReplyTo(replyToAddresses.toArray(new InternetAddress[replyToAddresses.size()]));
         }
         
         // must have at least one recipients otherwise we do not know where to send the mail
@@ -554,16 +559,16 @@ public class MailBinding {
         return answer;
     }
 
-    private static void appendRecipientToMimeMessage(MimeMessage mimeMessage, String type, String recipient)
-        throws MessagingException {
-
+    private static void appendRecipientToMimeMessage(MimeMessage mimeMessage, String type, String recipient) throws MessagingException {
+        for (String line : splitRecipients(recipient)) {
+            mimeMessage.addRecipients(asRecipientType(type), line.trim());
+        }
+    }
+    
+    private static String[] splitRecipients(String recipients) {
         // we support that multi recipient can be given as a string separated by comma or semicolon
         // regex ignores comma and semicolon inside of double quotes
-        String[] lines = recipient.split("[,;]++(?=(?:(?:[^\\\"]*+\\\"){2})*+[^\\\"]*+$)");
-        for (String line : lines) {
-            line = line.trim();
-            mimeMessage.addRecipients(asRecipientType(type), line);
-        }
+        return recipients.split("[,;]++(?=(?:(?:[^\\\"]*+\\\"){2})*+[^\\\"]*+$)");
     }
 
     /**

Modified: camel/branches/camel-2.9.x/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailReplyToTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailReplyToTest.java?rev=1234628&r1=1234627&r2=1234628&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailReplyToTest.java (original)
+++ camel/branches/camel-2.9.x/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailReplyToTest.java Sun Jan 22 22:04:13 2012
@@ -37,16 +37,17 @@ public class MailReplyToTest extends Cam
 
         MockEndpoint mock = getMockEndpoint("mock:result");
         mock.expectedMessageCount(1);
-        mock.expectedHeaderReceived("Reply-To", "noReply@localhost");
+        mock.expectedHeaderReceived("Reply-To", "noReply1@localhost,noReply2@localhost");
         mock.expectedBodiesReceived(body);
 
-        template.sendBodyAndHeader("direct:a", body, "Reply-To", "noReply@localhost");
+        template.sendBodyAndHeader("direct:a", body, "Reply-To", "noReply1@localhost,noReply2@localhost");
 
         mock.assertIsSatisfied();
 
         Mailbox mailbox = Mailbox.get("christian@localhost");
         assertEquals(1, mailbox.size());
-        assertEquals("noReply@localhost", ((InternetAddress) mailbox.get(0).getReplyTo()[0]).getAddress());
+        assertEquals("noReply1@localhost", ((InternetAddress) mailbox.get(0).getReplyTo()[0]).getAddress());
+        assertEquals("noReply2@localhost", ((InternetAddress) mailbox.get(0).getReplyTo()[1]).getAddress());
         assertEquals(body, mailbox.get(0).getContent());
     }
     
@@ -58,7 +59,7 @@ public class MailReplyToTest extends Cam
 
         MockEndpoint mock = getMockEndpoint("mock:result");
         mock.expectedMessageCount(1);
-        mock.expectedHeaderReceived("Reply-To", "noReply@localhost");
+        mock.expectedHeaderReceived("Reply-To", "noReply1@localhost, noReply2@localhost");
         mock.expectedBodiesReceived(body);
 
         template.sendBody("direct:b", body);
@@ -67,7 +68,8 @@ public class MailReplyToTest extends Cam
 
         Mailbox mailbox = Mailbox.get("christian@localhost");
         assertEquals(1, mailbox.size());
-        assertEquals("noReply@localhost", ((InternetAddress) mailbox.get(0).getReplyTo()[0]).getAddress());
+        assertEquals("noReply1@localhost", ((InternetAddress) mailbox.get(0).getReplyTo()[0]).getAddress());
+        assertEquals("noReply2@localhost", ((InternetAddress) mailbox.get(0).getReplyTo()[1]).getAddress());
         assertEquals(body, mailbox.get(0).getContent());
     }
 
@@ -78,7 +80,7 @@ public class MailReplyToTest extends Cam
                     .to("smtp://christian@localhost?subject=Camel");
                 
                 from("direct:b")
-                    .to("smtp://christian@localhost?subject=Camel&replyTo=noReply@localhost");
+                    .to("smtp://christian@localhost?subject=Camel&replyTo=noReply1@localhost,noReply2@localhost");
 
                 from("pop3://localhost?username=christian&password=secret&consumer.delay=1000")
                     .to("mock:result");