You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by tn...@apache.org on 2013/02/21 13:36:33 UTC

svn commit: r1448625 - in /commons/proper/email/trunk/src: main/java/org/apache/commons/mail/Email.java test/java/org/apache/commons/mail/EmailLiveTest.java

Author: tn
Date: Thu Feb 21 12:36:32 2013
New Revision: 1448625

URL: http://svn.apache.org/r1448625
Log:
[EMAIL-124] Add sanity checks to Email.setHeaders(Map) method, add throws clauses to javadoc, add live email test for header folding.

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

Modified: commons/proper/email/trunk/src/main/java/org/apache/commons/mail/Email.java
URL: http://svn.apache.org/viewvc/commons/proper/email/trunk/src/main/java/org/apache/commons/mail/Email.java?rev=1448625&r1=1448624&r2=1448625&view=diff
==============================================================================
--- commons/proper/email/trunk/src/main/java/org/apache/commons/mail/Email.java (original)
+++ commons/proper/email/trunk/src/main/java/org/apache/commons/mail/Email.java Thu Feb 21 12:36:32 2013
@@ -1160,6 +1160,7 @@ public abstract class Email
      * Disposition-Notification-To: user@domain.net
      *
      * @param map A Map.
+     * @throws IllegalArgumentException if either of the provided header / value is null or empty
      * @since 1.0
      */
     public void setHeaders(Map<String, String> map)
@@ -1171,7 +1172,7 @@ public abstract class Email
         while (iterKeyBad.hasNext())
         {
             Map.Entry<String, String> entry = iterKeyBad.next();
-            this.headers.put(entry.getKey(), entry.getValue());
+            addHeader(entry.getKey(), entry.getValue());
         }
 
     }
@@ -1182,16 +1183,17 @@ public abstract class Email
      * @param name A String with the name.
      * @param value A String with the value.
      * @since 1.0
+     * @throws IllegalArgumentException if either {@code name} or {@code value} is null or empty
      */
     public void addHeader(String name, String value)
     {
         if (EmailUtils.isEmpty(name))
         {
-            throw new IllegalArgumentException("name can not be null");
+            throw new IllegalArgumentException("name can not be null or empty");
         }
         if (EmailUtils.isEmpty(value))
         {
-            throw new IllegalArgumentException("value can not be null");
+            throw new IllegalArgumentException("value can not be null or empty");
         }
 
         this.headers.put(name, value);

Modified: commons/proper/email/trunk/src/test/java/org/apache/commons/mail/EmailLiveTest.java
URL: http://svn.apache.org/viewvc/commons/proper/email/trunk/src/test/java/org/apache/commons/mail/EmailLiveTest.java?rev=1448625&r1=1448624&r2=1448625&view=diff
==============================================================================
--- commons/proper/email/trunk/src/test/java/org/apache/commons/mail/EmailLiveTest.java (original)
+++ commons/proper/email/trunk/src/test/java/org/apache/commons/mail/EmailLiveTest.java Thu Feb 21 12:36:32 2013
@@ -134,6 +134,21 @@ public class EmailLiveTest extends BaseE
     }
 
     /**
+     * A sanity check that a header folding works correctly.
+     *
+     * @throws Exception the test failed
+     */
+    public void testFoldedHeaderValue() throws Exception
+    {
+        SimpleEmail email = (SimpleEmail) create(SimpleEmail.class);
+        email.setSubject("TestFoldedHeaderMail");
+        email.setMsg("This is a test mail with a folded header value... :-)");
+        email.addHeader("X-TestHeader", "This is a very long header value which should be folded into two lines, hopefully");
+
+        EmailUtils.writeMimeMessage( new File("./target/test-emails/foldedheader.eml"), send(email).getMimeMessage());
+    }
+
+    /**
      * A sanity check that a simple email also works in reality.
      *
      * @throws Exception the test failed