You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Gary Gregory <ga...@gmail.com> on 2012/12/02 23:07:56 UTC

Re: 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

This should be a place to use var args...

Gary

On Dec 2, 2012, at 15:23, "tn@apache.org" <tn...@apache.org> wrote:

> 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
>     {
>         // ====================================================================
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: 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

Posted by sebb <se...@gmail.com>.
On 3 December 2012 19:16, Gary Gregory <ga...@gmail.com> wrote:
> On Mon, Dec 3, 2012 at 2:06 PM, Thomas Neidhart
> <th...@gmail.com>wrote:
>
>> On 12/03/2012 01:01 PM, sebb wrote:
>> > On 3 December 2012 11:39, Gary Gregory <ga...@gmail.com> wrote:
>> >> I think it's time to update to Java 5... it is almost 2013!
>> >
>> > Agreed - unless there is a particular reason why it should remain at
>> Java 1.4?
>>
>> fine for me too. Shall we make this visible via an issue, or is it
>> sufficient to mention it in the release notes?
>>
>
> Both. Use a JIRA so you can have a EMAIL-nnn tag in the commits for clean
> ups like generics, varargs, for each loops, and so on.
>

+1

>>
>> Do you also agree to move to a more maven compliant directory structure:
>>
>>  * src/java -> src/main/java
>>  * src/resource -> src/main/resources
>>  * src/test -> src/test/java + src/test/resources
>>
>
> +1

+1

S.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: 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

Posted by Gary Gregory <ga...@gmail.com>.
On Mon, Dec 3, 2012 at 2:06 PM, Thomas Neidhart
<th...@gmail.com>wrote:

> On 12/03/2012 01:01 PM, sebb wrote:
> > On 3 December 2012 11:39, Gary Gregory <ga...@gmail.com> wrote:
> >> I think it's time to update to Java 5... it is almost 2013!
> >
> > Agreed - unless there is a particular reason why it should remain at
> Java 1.4?
>
> fine for me too. Shall we make this visible via an issue, or is it
> sufficient to mention it in the release notes?
>

Both. Use a JIRA so you can have a EMAIL-nnn tag in the commits for clean
ups like generics, varargs, for each loops, and so on.


>
> Do you also agree to move to a more maven compliant directory structure:
>
>  * src/java -> src/main/java
>  * src/resource -> src/main/resources
>  * src/test -> src/test/java + src/test/resources
>

+1

Gary


>
> Thomas
>
> >
> >> Gary
> >>
> >> On Dec 3, 2012, at 2:37, Thomas Neidhart <th...@gmail.com>
> wrote:
> >>
> >>> On 12/02/2012 11:07 PM, Gary Gregory wrote:
> >>>> This should be a place to use var args...
> >>>
> >>> Thanks for the hint, in this case I could not use it as email still has
> >>> to be (source) compatible with jdk 1.4.
> >>>
> >>> Thomas
> >>>
> >>> ---------------------------------------------------------------------
> >>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> >>> For additional commands, e-mail: dev-help@commons.apache.org
> >>>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> >> For additional commands, e-mail: dev-help@commons.apache.org
> >>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> > For additional commands, e-mail: dev-help@commons.apache.org
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>


-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
JUnit in Action, 2nd Ed: <http://goog_1249600977>http://bit.ly/ECvg0
Spring Batch in Action: <http://s.apache.org/HOq>http://bit.ly/bqpbCK
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Re: 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

Posted by Thomas Neidhart <th...@gmail.com>.
On 12/03/2012 01:01 PM, sebb wrote:
> On 3 December 2012 11:39, Gary Gregory <ga...@gmail.com> wrote:
>> I think it's time to update to Java 5... it is almost 2013!
> 
> Agreed - unless there is a particular reason why it should remain at Java 1.4?

fine for me too. Shall we make this visible via an issue, or is it
sufficient to mention it in the release notes?

Do you also agree to move to a more maven compliant directory structure:

 * src/java -> src/main/java
 * src/resource -> src/main/resources
 * src/test -> src/test/java + src/test/resources

Thomas

> 
>> Gary
>>
>> On Dec 3, 2012, at 2:37, Thomas Neidhart <th...@gmail.com> wrote:
>>
>>> On 12/02/2012 11:07 PM, Gary Gregory wrote:
>>>> This should be a place to use var args...
>>>
>>> Thanks for the hint, in this case I could not use it as email still has
>>> to be (source) compatible with jdk 1.4.
>>>
>>> Thomas
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>>> For additional commands, e-mail: dev-help@commons.apache.org
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: 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

Posted by sebb <se...@gmail.com>.
On 3 December 2012 11:39, Gary Gregory <ga...@gmail.com> wrote:
> I think it's time to update to Java 5... it is almost 2013!

Agreed - unless there is a particular reason why it should remain at Java 1.4?

> Gary
>
> On Dec 3, 2012, at 2:37, Thomas Neidhart <th...@gmail.com> wrote:
>
>> On 12/02/2012 11:07 PM, Gary Gregory wrote:
>>> This should be a place to use var args...
>>
>> Thanks for the hint, in this case I could not use it as email still has
>> to be (source) compatible with jdk 1.4.
>>
>> Thomas
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: 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

Posted by Gary Gregory <ga...@gmail.com>.
I think it's time to update to Java 5... it is almost 2013!

Gary

On Dec 3, 2012, at 2:37, Thomas Neidhart <th...@gmail.com> wrote:

> On 12/02/2012 11:07 PM, Gary Gregory wrote:
>> This should be a place to use var args...
>
> Thanks for the hint, in this case I could not use it as email still has
> to be (source) compatible with jdk 1.4.
>
> Thomas
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: 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

Posted by Thomas Neidhart <th...@gmail.com>.
On 12/02/2012 11:07 PM, Gary Gregory wrote:
> This should be a place to use var args...

Thanks for the hint, in this case I could not use it as email still has
to be (source) compatible with jdk 1.4.

Thomas

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org