You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2010/06/25 10:32:39 UTC

svn commit: r957842 - in /camel/trunk/components/camel-mail/src: main/java/org/apache/camel/component/mail/MailBinding.java test/java/org/apache/camel/component/mail/MailRouteTest.java

Author: ningjiang
Date: Fri Jun 25 08:32:38 2010
New Revision: 957842

URL: http://svn.apache.org/viewvc?rev=957842&view=rev
Log:
CAMEL-2857 Not using the UTF-8 as the default charset for camel-mail subject header

Modified:
    camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java
    camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailRouteTest.java

Modified: camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java?rev=957842&r1=957841&r2=957842&view=diff
==============================================================================
--- camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java (original)
+++ camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java Fri Jun 25 08:32:38 2010
@@ -92,7 +92,7 @@ public class MailBinding {
         // and headers the headers win.
         String subject = endpoint.getConfiguration().getSubject();
         if (subject != null) {
-            mimeMessage.setSubject(subject, IOConverter.getCharsetName(exchange));
+            mimeMessage.setSubject(subject, IOConverter.getCharsetName(exchange, false));
         }
 
         // append the rest of the headers (no recipients) that could be subject, reply-to etc.
@@ -325,7 +325,7 @@ public class MailBinding {
                 if (headerFilterStrategy != null
                         && !headerFilterStrategy.applyFilterToCamelHeaders(headerName, headerValue, exchange)) {
                     if (headerName.equalsIgnoreCase("subject")) {
-                        mimeMessage.setSubject(asString(exchange, headerValue), IOConverter.getCharsetName(exchange));
+                        mimeMessage.setSubject(asString(exchange, headerValue), IOConverter.getCharsetName(exchange, false));
                         continue;
                     }
                     if (isRecipientHeader(headerName)) {

Modified: camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailRouteTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailRouteTest.java?rev=957842&r1=957841&r2=957842&view=diff
==============================================================================
--- camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailRouteTest.java (original)
+++ camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailRouteTest.java Fri Jun 25 08:32:38 2010
@@ -24,8 +24,8 @@ import javax.mail.Message;
 import javax.mail.Message.RecipientType;
 import javax.mail.MessagingException;
 
-
 import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.test.junit4.CamelTestSupport;
@@ -51,7 +51,8 @@ public class MailRouteTest extends Camel
         // lets test the first sent worked
         assertMailboxReceivedMessages("route-test-james@localhost");
 
-        // lets sleep to check that the mail poll does not redeliver duplicate mails
+        // lets sleep to check that the mail poll does not redeliver duplicate
+        // mails
         Thread.sleep(3000);
 
         // lets test the receive worked
@@ -64,36 +65,35 @@ public class MailRouteTest extends Camel
 
         assertMailboxReceivedMessages("route-test-copy@localhost");
     }
-    
+
     @Test
     public void testMailSubjectWithUnicode() throws Exception {
         Mailbox.clearAll();
 
-        String body = "Hello Camel Riders!";
-        String subject = "My Camel \u2122";
-        
-        System.setProperty(Exchange.DEFAULT_CHARSET_PROPERTY, "US-ASCII");
-
-        try {
-            MockEndpoint mock = getMockEndpoint("mock:result");
-        
-            mock.expectedMessageCount(1);
-            // now we don't use the UTF-8 encoding
-            mock.expectedHeaderReceived("subject", "=?US-ASCII?Q?My_Camel_=3F?=");
-            mock.expectedBodiesReceived(body);
-    
-            template.sendBodyAndHeader("direct:a", body, "subject", subject);
-    
-            mock.assertIsSatisfied();
-    
-            assertFalse("Should not have attachements",
-                        mock.getExchanges().get(0).getIn().hasAttachments());
-        } finally {
-            System.clearProperty(Exchange.DEFAULT_CHARSET_PROPERTY);
-        }
-        
-    }
+        final String body = "Hello Camel Riders!";
+        final String subject = "My Camel \u2122";
+
+        MockEndpoint mock = getMockEndpoint("mock:result");
 
+        mock.expectedMessageCount(1);
+        // now we don't use the UTF-8 encoding
+        mock.expectedHeaderReceived("subject", "=?US-ASCII?Q?My_Camel_=3F?=");
+        mock.expectedBodiesReceived(body);
+
+        template.send("direct:a", new Processor() {
+
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setBody(body);
+                exchange.getIn().setHeader("subject", subject);
+                exchange.setProperty(Exchange.CHARSET_NAME, "US-ASCII");
+            }
+        });
+
+        mock.assertIsSatisfied();
+
+        assertFalse("Should not have attachements", mock.getExchanges().get(0).getIn().hasAttachments());
+
+    }
 
     protected void assertMailboxReceivedMessages(String name) throws IOException, MessagingException {
         Mailbox mailbox = Mailbox.get(name);
@@ -116,19 +116,21 @@ public class MailRouteTest extends Camel
     protected RouteBuilder createRouteBuilder() {
         return new RouteBuilder() {
             public void configure() {
-                from("pop3://route-test-james@localhost?consumer.delay=1000")
-                    .to("direct:a");
+                from("pop3://route-test-james@localhost?consumer.delay=1000").to("direct:a");
 
-                // must use fixed to option to send the mail to the given reciever, as we have polled
-                // a mail from a mailbox where it already has the 'old' To as header value
-                // here we send the mail to 2 recievers. notice we can use a plain string with semi colon
+                // must use fixed to option to send the mail to the given
+                // reciever, as we have polled
+                // a mail from a mailbox where it already has the 'old' To as
+                // header value
+                // here we send the mail to 2 recievers. notice we can use a
+                // plain string with semi colon
                 // to seperate the mail addresses
                 from("direct:a")
                     .setHeader("to", constant("route-test-result@localhost; route-test-copy@localhost"))
                     .to("smtp://localhost");
 
-                from("pop3://route-test-result@localhost?consumer.delay=1000")
-                    .convertBodyTo(String.class).to("mock:result");
+                from("pop3://route-test-result@localhost?consumer.delay=1000").convertBodyTo(String.class)
+                    .to("mock:result");
             }
         };
     }