Quantcast

[mule-scm] [mule][25294] branches/mule-3.1.x/transports/email/src: MULE-6690: StringToEmailMessage doesn't encode subject correctly

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[mule-scm] [mule][25294] branches/mule-3.1.x/transports/email/src: MULE-6690: StringToEmailMessage doesn't encode subject correctly

damian.bakarcic
[mule][25294] branches/mule-3.1.x/transports/email/src: MULE-6690: StringToEmailMessage doesn't encode subject correctly
Revision
25294
Author
damian.bakarcic
Date
2013-02-21 13:17:15 -0600 (Thu, 21 Feb 2013)

Log Message

MULE-6690: StringToEmailMessage doesn't encode subject correctly

- Added the transformer output encoding to the message subject when the MimeMessage is being constructed inside the StringToEmailMessage transformer. 

Modified Paths

Diff

Modified: branches/mule-3.1.x/transports/email/src/main/java/org/mule/transport/email/transformers/StringToEmailMessage.java (25293 => 25294)


--- branches/mule-3.1.x/transports/email/src/main/java/org/mule/transport/email/transformers/StringToEmailMessage.java	2013-02-19 19:10:09 UTC (rev 25293)
+++ branches/mule-3.1.x/transports/email/src/main/java/org/mule/transport/email/transformers/StringToEmailMessage.java	2013-02-21 19:17:15 UTC (rev 25294)
@@ -112,7 +112,7 @@
 
         try
         {
-            Message email = new MimeMessage(((SmtpConnector) endpoint.getConnector()).getSessionDetails(endpoint).getSession());
+            MimeMessage email = new MimeMessage(((SmtpConnector) endpoint.getConnector()).getSessionDetails(endpoint).getSession());
 
             email.setRecipients(Message.RecipientType.TO, MailUtils.stringToInternetAddresses(to));
 
@@ -139,7 +139,7 @@
                 email.setReplyTo(MailUtils.stringToInternetAddresses(replyTo));
             }
 
-            email.setSubject(subject);
+            email.setSubject(subject, outputEncoding);
 
             for (Iterator iterator = headers.entrySet().iterator(); iterator.hasNext();)
             {

Modified: branches/mule-3.1.x/transports/email/src/test/java/org/mule/transport/email/transformers/MailMessageTransformersNonAsciiTestCase.java (25293 => 25294)


--- branches/mule-3.1.x/transports/email/src/test/java/org/mule/transport/email/transformers/MailMessageTransformersNonAsciiTestCase.java	2013-02-19 19:10:09 UTC (rev 25293)
+++ branches/mule-3.1.x/transports/email/src/test/java/org/mule/transport/email/transformers/MailMessageTransformersNonAsciiTestCase.java	2013-02-21 19:17:15 UTC (rev 25294)
@@ -10,12 +10,27 @@
 
 package org.mule.transport.email.transformers;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import org.mule.DefaultMuleMessage;
+import org.mule.api.MuleMessage;
+import org.mule.api.transformer.Transformer;
 import org.mule.config.i18n.LocaleMessageHandler;
+import org.mule.transport.email.MailProperties;
 
+import java.util.HashMap;
 import java.util.Locale;
+import java.util.Map;
 
+import javax.mail.internet.MimeMessage;
+
+import org.junit.Test;
+
 public class MailMessageTransformersNonAsciiTestCase extends MailMessageTransformersTestCase
 {
+
     @Override
     protected String getContentType() 
     {
@@ -28,4 +43,27 @@
         return LocaleMessageHandler.getString("test-data", Locale.JAPAN,
             "MailMessageTransformersNonAsciiTestCase.getResultData", new Object[] {});
     }
+
+    @Test
+    public void testNonAsciiSubjectEncodingInRoundtripTransformation() throws Exception
+    {
+        Transformer roundTripTransformer = super.getRoundTripTransformer();
+
+        // Build message setting the non-ascii message subject as a property for the transformer.
+        Map<String, Object> outboundProperties = new HashMap<String, Object>();
+        String testSubject = (String) getResultData();
+        outboundProperties.put(MailProperties.SUBJECT_PROPERTY, testSubject);
+        MuleMessage message = new DefaultMuleMessage(testSubject, outboundProperties, muleContext);
+
+        // Hack to set the default charset used by the javax.mail API to perform the mail subject encoding as iso-8859-1.
+        System.setProperty("mail.mime.charset", "iso-8859-1");
+
+        // Transform.
+        Object result = roundTripTransformer.transform(message, "iso-2022-jp");
+
+        assertNotNull("The result of the roundtrip transform shouldn't be null", result);
+        assertTrue(result instanceof MimeMessage);
+        // Assert that the mail subject has been correctly encoded in iso-2022-jp.
+        assertEquals(((MimeMessage) result).getSubject(), testSubject);
+    }
 }

To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Loading...