commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t.@apache.org
Subject svn commit: r1416248 - in /commons/proper/email/trunk/src: changes/changes.xml java/org/apache/commons/mail/Email.java test/org/apache/commons/mail/EmailTest.java
Date Sun, 02 Dec 2012 20:22:39 GMT
Author: tn
Date: Sun Dec  2 20:22:27 2012
New Revision: 1416248

URL: http://svn.apache.org/viewvc?rev=1416248&view=rev
Log:
[EMAIL-114] Added new methods to Email to set an array of addresses for to, cc, bcc.

Modified:
    commons/proper/email/trunk/src/changes/changes.xml
    commons/proper/email/trunk/src/java/org/apache/commons/mail/Email.java
    commons/proper/email/trunk/src/test/org/apache/commons/mail/EmailTest.java

Modified: commons/proper/email/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/email/trunk/src/changes/changes.xml?rev=1416248&r1=1416247&r2=1416248&view=diff
==============================================================================
--- commons/proper/email/trunk/src/changes/changes.xml (original)
+++ commons/proper/email/trunk/src/changes/changes.xml Sun Dec  2 20:22:27 2012
@@ -23,6 +23,9 @@
 
   <body>
     <release version="1.3" date="as in SVN">
+      <action dev="tn" type="fix" issue="EMAIL-114" date="2012-12-02" due-to="Gokul Nanthakumar
C">
+        Added new methods addTo(String[]), addCc(String[]) and addBcc(String[]) to Email.
+      </action>
       <action dev="tn" type="fix" issue="EMAIL-117" date="2012-12-02" due-to="sebb">
         Removed emulation support for nested exceptions in EmailException.
       </action>

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=1416248&r1=1416247&r2=1416248&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 Dec  2 20:22:27
2012
@@ -646,6 +646,35 @@ public abstract class Email implements E
     }
 
     /**
+     * Add a list of TO recipients to the email. The email
+     * addresses will also be used as the personal names.
+     * The names will be encoded by the charset of
+     * {@link #setCharset(java.lang.String) setCharset()}.
+     * If it is not set, it will be encoded using
+     * the Java platform's default charset (UTF-16) if it contains
+     * non-ASCII characters; otherwise, it is used as is.
+     *
+     * @param emails A String array.
+     * @throws EmailException Indicates an invalid email address.
+     * @return An Email.
+     */
+    public Email addTo(String[] emails)
+        throws EmailException
+    {
+        if(emails == null || emails.length == 0)
+        {
+            throw new EmailException("Address List provided was invalid");
+        }
+        
+        for(int i = 0; i < emails.length; i++)
+        {
+            addTo(emails[i], null);
+        }
+        
+        return this;
+    }
+
+    /**
      * Add a recipient TO to the email using the specified address and the
      * specified personal name.
      * The name will be encoded by the charset of
@@ -726,6 +755,35 @@ public abstract class Email implements E
     }
 
     /**
+     * Add an array of CC recipients to the email. The email
+     * addresses will also be used as the personal name.
+     * The names will be encoded by the charset of
+     * {@link #setCharset(java.lang.String) setCharset()}.
+     * If it is not set, it will be encoded using
+     * the Java platform's default charset (UTF-16) if it contains
+     * non-ASCII characters; otherwise, it is used as is.
+     *
+     * @param emails A String array.
+     * @return An Email.
+     * @throws EmailException Indicates an invalid email address.
+     */
+    public Email addCc(String[] emails)
+        throws EmailException
+    {
+        if(emails == null || emails.length == 0)
+        {
+            throw new EmailException("Address List provided was invalid");
+        }
+        
+        for(int i = 0; i < emails.length; i++)
+        {
+            addCc(emails[i], null);
+        }
+        
+        return this;
+    }
+
+    /**
      * Add a recipient CC to the email using the specified address and the
      * specified personal name.
      * The name will be encoded by the charset of {@link #setCharset(java.lang.String) setCharset()}.
@@ -805,6 +863,35 @@ public abstract class Email implements E
     }
 
     /**
+     * Add an array of blind BCC recipients to the email. The email
+     * addresses will also be used as the personal name.
+     * The names will be encoded by the charset of
+     * {@link #setCharset(java.lang.String) setCharset()}.
+     * If it is not set, it will be encoded using
+     * the Java platform's default charset (UTF-16) if it contains
+     * non-ASCII characters; otherwise, it is used as is.
+     *
+     * @param emails A String array.
+     * @return An Email.
+     * @throws EmailException Indicates an invalid email address
+     */
+    public Email addBcc(String[] emails)
+        throws EmailException
+    {
+        if(emails == null || emails.length == 0)
+        {
+            throw new EmailException("Address List provided was invalid");
+        }
+        
+        for(int i = 0; i < emails.length; i++)
+        {
+            addBcc(emails[i], null);
+        }
+        
+        return this;
+    }
+
+    /**
      * Add a blind BCC recipient to the email using the specified address and
      * the specified personal name.
      * The name will be encoded by the charset of {@link #setCharset(java.lang.String) setCharset()}.

Modified: commons/proper/email/trunk/src/test/org/apache/commons/mail/EmailTest.java
URL: http://svn.apache.org/viewvc/commons/proper/email/trunk/src/test/org/apache/commons/mail/EmailTest.java?rev=1416248&r1=1416247&r2=1416248&view=diff
==============================================================================
--- commons/proper/email/trunk/src/test/org/apache/commons/mail/EmailTest.java (original)
+++ commons/proper/email/trunk/src/test/org/apache/commons/mail/EmailTest.java Sun Dec  2
20:22:27 2012
@@ -423,6 +423,35 @@ public class EmailTest extends BaseEmail
      * @throws EmailException when there are problems adding an address
      * @throws UnsupportedEncodingException on bad email addresses
      */
+    public void testAddToArray() throws EmailException, UnsupportedEncodingException
+    {
+        // ====================================================================
+        // Test Success
+        // ====================================================================
+
+        List arrExpected = new ArrayList();
+        arrExpected.add(new InternetAddress("me@home.com", "me@home.com"));
+        arrExpected.add(
+            new InternetAddress(
+                "joe.doe@apache.org",
+                "joe.doe@apache.org"));
+        arrExpected.add(
+            new InternetAddress(
+                "someone_here@work-address.com.au",
+                "someone_here@work-address.com.au"));
+
+        //set To
+        this.email.addTo(ARR_VALID_EMAILS);
+
+        // retrieve and verify
+        assertEquals(arrExpected.size(), this.email.getToAddresses().size());
+        assertEquals(arrExpected.toString(), this.email.getToAddresses().toString());
+    }
+
+    /**
+     * @throws EmailException when there are problems adding an address
+     * @throws UnsupportedEncodingException on bad email addresses
+     */
     public void testAddToWithEncoding() throws UnsupportedEncodingException, EmailException
     {
         // ====================================================================
@@ -601,6 +630,35 @@ public class EmailTest extends BaseEmail
      * @throws EmailException when there are problems adding an address
      * @throws UnsupportedEncodingException on bad email addresses
      */
+    public void testAddCcArray() throws UnsupportedEncodingException, EmailException
+    {
+        // ====================================================================
+        // Test Success
+        // ====================================================================
+
+        List arrExpected = new ArrayList();
+        arrExpected.add(new InternetAddress("me@home.com", "me@home.com"));
+        arrExpected.add(
+            new InternetAddress(
+                "joe.doe@apache.org",
+                "joe.doe@apache.org"));
+        arrExpected.add(
+            new InternetAddress(
+                "someone_here@work-address.com.au",
+                "someone_here@work-address.com.au"));
+
+        //set Cc array
+        this.email.addCc(ARR_VALID_EMAILS);
+
+        // retrieve and verify
+        assertEquals(arrExpected.size(), this.email.getCcAddresses().size());
+        assertEquals(arrExpected.toString(), this.email.getCcAddresses().toString());
+    }
+
+    /**
+     * @throws EmailException when there are problems adding an address
+     * @throws UnsupportedEncodingException on bad email addresses
+     */
     public void testAddCcWithEncoding() throws UnsupportedEncodingException, EmailException
     {
         // ====================================================================
@@ -770,6 +828,34 @@ public class EmailTest extends BaseEmail
      * @throws EmailException when there are problems adding an address
      * @throws UnsupportedEncodingException on bad email addresses
      */
+    public void testAddBccArray() throws UnsupportedEncodingException, EmailException
+    {
+        // ====================================================================
+        // Test Success
+        // ====================================================================
+
+        List arrExpected = new ArrayList();
+        arrExpected.add(new InternetAddress("me@home.com", "me@home.com"));
+        arrExpected.add(
+            new InternetAddress("joe.doe@apache.org", "joe.doe@apache.org"));
+        arrExpected.add(
+            new InternetAddress("someone_here@work-address.com.au",
+                                "someone_here@work-address.com.au"));
+
+        // add a valid bcc
+        this.email.addBcc(ARR_VALID_EMAILS);
+
+        // retrieve and verify
+        assertEquals(arrExpected.size(), this.email.getBccAddresses().size());
+        assertEquals(
+            arrExpected.toString(),
+            this.email.getBccAddresses().toString());
+    }
+
+    /**
+     * @throws EmailException when there are problems adding an address
+     * @throws UnsupportedEncodingException on bad email addresses
+     */
     public void testAddBccWithEncoding() throws UnsupportedEncodingException, EmailException
     {
         // ====================================================================



Mime
View raw message