commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sgoes...@apache.org
Subject svn commit: r762147 - in /commons/proper/email/trunk/src: java/org/apache/commons/mail/Email.java test/org/apache/commons/mail/EmailLiveTest.java
Date Sun, 05 Apr 2009 20:14:13 GMT
Author: sgoeschl
Date: Sun Apr  5 20:14:13 2009
New Revision: 762147

URL: http://svn.apache.org/viewvc?rev=762147&view=rev
Log:
[EMAIL-79] SimpleEmail#setMsg() with UTF-8 content honors correct charset in header and encode
the content correctly.

Modified:
    commons/proper/email/trunk/src/java/org/apache/commons/mail/Email.java
    commons/proper/email/trunk/src/test/org/apache/commons/mail/EmailLiveTest.java

Modified: commons/proper/email/trunk/src/java/org/apache/commons/mail/Email.java
URL: http://svn.apache.org/viewvc/commons/proper/email/trunk/src/java/org/apache/commons/mail/Email.java?rev=762147&r1=762146&r2=762147&view=diff
==============================================================================
--- commons/proper/email/trunk/src/java/org/apache/commons/mail/Email.java (original)
+++ commons/proper/email/trunk/src/java/org/apache/commons/mail/Email.java Sun Apr  5 20:14:13
2009
@@ -325,6 +325,18 @@
     public void setContent(Object aObject, String aContentType)
     {
         this.content = aObject;
+        this.updateContentType(aContentType);
+    }
+
+
+    /**
+     * Update the contentType.
+     *
+     * @param   aContentType aContentType
+     * @since 1.2
+     */
+    public void updateContentType(final String aContentType)
+    {
         if (EmailUtils.isEmpty(aContentType))
         {
             this.contentType = null;
@@ -1070,17 +1082,23 @@
                 }
             }
 
-            // ========================================================
-            // Start of replacement code
+            // update content type (and encoding)
+            this.updateContentType(this.contentType);
+            
             if (this.content != null)
             {
                 this.message.setContent(this.content, this.contentType);
             }
-            // end of replacement code
-            // ========================================================
             else if (this.emailBody != null)
             {
-                this.message.setContent(this.emailBody);
+                if (this.contentType == null)
+                {
+                    this.message.setContent(this.emailBody);
+                }
+                else
+                {
+                    this.message.setContent(this.emailBody, this.contentType);
+                }
             }
             else
             {

Modified: commons/proper/email/trunk/src/test/org/apache/commons/mail/EmailLiveTest.java
URL: http://svn.apache.org/viewvc/commons/proper/email/trunk/src/test/org/apache/commons/mail/EmailLiveTest.java?rev=762147&r1=762146&r2=762147&view=diff
==============================================================================
--- commons/proper/email/trunk/src/test/org/apache/commons/mail/EmailLiveTest.java (original)
+++ commons/proper/email/trunk/src/test/org/apache/commons/mail/EmailLiveTest.java Sun Apr
 5 20:14:13 2009
@@ -26,12 +26,6 @@
 import javax.mail.internet.InternetAddress;
 
 import org.apache.commons.mail.settings.EmailConfiguration;
-import org.apache.commons.mail.BaseEmailTestCase;
-import org.apache.commons.mail.HtmlEmail;
-import org.apache.commons.mail.EmailAttachment;
-import org.apache.commons.mail.Email;
-import org.apache.commons.mail.DefaultAuthenticator;
-import org.apache.commons.mail.EmailUtils;
 
 /**
  * This are regression test sending REAL email to REAL mail
@@ -148,7 +142,7 @@
         textMsg = "Your email client does not support HTML messages";
         cid = htmlEmail3.embed(imageUrl, "Apache Logo");
         htmlMsg = "<html><b>This is a HTML message with an inline image - <img
src=\"cid:"
-            + cid + "\"> ...</b><html>";
+            + cid + "\"> and NO attachment</b><html>";
 
         htmlEmail3.setSubject( "[email] 3.Test: text + html content + inline image");
         htmlEmail3.setFrom(EmailConfiguration.TEST_FROM);
@@ -193,7 +187,7 @@
 
     /**
      * This test checks the correct character encoding when sending
-     * non-ASCII content.
+     * non-ASCII content using SimpleEmail.
      *
      * https://issues.apache.org/jira/browse/EMAIL-79
      *
@@ -205,8 +199,8 @@
         // U+03B2 : GREEK SMALL LETTER BETA
         // U+03B3 : GREEK SMALL LETTER GAMMA
 
-        final String subject = "My test subject with three greek UTF-8 characters : \u03B1\u03B2\u03B3";
-        final String content = "My body with with three greek UTF-8 characters : \u03B1\u03B2\u03B3";
+        final String subject = "[email] 5.Test: Subject with three greek UTF-8 characters
: \u03B1\u03B2\u03B3";
+        final String textMsg = "My test body with with three greek UTF-8 characters : \u03B1\u03B2\u03B3";
 
         SimpleEmail email = new SimpleEmail();
         email.setDebug(true);
@@ -216,7 +210,7 @@
         email.addTo(EmailConfiguration.TEST_TO);
         email.setFrom(EmailConfiguration.TEST_FROM);
         email.setSubject(subject);
-        email.setMsg(content);
+        email.setMsg(textMsg);
         email.setCharset("utf-8");
 
         if( EmailConfiguration.MAIL_FORCE_SEND ) {
@@ -229,13 +223,12 @@
         EmailUtils.writeMimeMessage( new File("./target/test-emails/correct-encoding.eml"),
email.getMimeMessage());
 
         System.out.println("Encoding: " + email.getMimeMessage().getEncoding());
-        System.out.println("Type: " + email.getMimeMessage().getContentType());    
-        
+        System.out.println("Type: " + email.getMimeMessage().getContentType());
+
         if( EmailConfiguration.MAIL_FORCE_SEND ) {
           // the encoding is only set when sending the email
-          // the patch is currently broken ....
-          // assertEquals(email.getMimeMessage().getEncoding(), "quoted-printable");
-          // assertEquals(email.getMimeMessage().getContentType(), "text/plain; charset=UTF-8");
+          assertEquals(email.getMimeMessage().getEncoding(), "quoted-printable");
+          assertEquals(email.getMimeMessage().getContentType(), "text/plain; charset=UTF-8");
         }
-    }    
+    }
 }
\ No newline at end of file



Mime
View raw message