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 2012/12/08 20:26:16 UTC
svn commit: r1418735 - in /commons/proper/email/trunk/src:
changes/changes.xml main/java/org/apache/commons/mail/Email.java
test/java/org/apache/commons/mail/EmailTest.java
Author: tn
Date: Sat Dec 8 19:26:15 2012
New Revision: 1418735
URL: http://svn.apache.org/viewvc?rev=1418735&view=rev
Log:
[EMAIL-103] Do not automatically set the personal name of an address to the email.
Modified:
commons/proper/email/trunk/src/changes/changes.xml
commons/proper/email/trunk/src/main/java/org/apache/commons/mail/Email.java
commons/proper/email/trunk/src/test/java/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=1418735&r1=1418734&r2=1418735&view=diff
==============================================================================
--- commons/proper/email/trunk/src/changes/changes.xml (original)
+++ commons/proper/email/trunk/src/changes/changes.xml Sat Dec 8 19:26:15 2012
@@ -23,6 +23,10 @@
<body>
<release version="1.3" date="as in SVN">
+ <action dev="tn" type="fix" issue="EMAIL-103" date="2012-12-08" due-to="David Rees">
+ Do not set the personal name of an address to the email address unless it is
+ explicitly specified (affects TO, CC, BCC and FROM addresses).
+ </action>
<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>
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=1418735&r1=1418734&r2=1418735&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 Sat Dec 8 19:26:15 2012
@@ -1714,22 +1714,20 @@ public abstract class Email implements E
address = new InternetAddress(email);
// check name input
- if (EmailUtils.isEmpty(name))
+ if (EmailUtils.isNotEmpty(name))
{
- name = email;
- }
-
- // check charset input.
- if (EmailUtils.isEmpty(charsetName))
- {
- address.setPersonal(name);
- }
- else
- {
- // canonicalize the charset name and make sure
- // the current platform supports it.
- Charset set = Charset.forName(charsetName);
- address.setPersonal(name, set.name());
+ // check charset input.
+ if (EmailUtils.isEmpty(charsetName))
+ {
+ address.setPersonal(name);
+ }
+ else
+ {
+ // canonicalize the charset name and make sure
+ // the current platform supports it.
+ Charset set = Charset.forName(charsetName);
+ address.setPersonal(name, set.name());
+ }
}
// run sanity check on new InternetAddress object; if this fails
Modified: commons/proper/email/trunk/src/test/java/org/apache/commons/mail/EmailTest.java
URL: http://svn.apache.org/viewvc/commons/proper/email/trunk/src/test/java/org/apache/commons/mail/EmailTest.java?rev=1418735&r1=1418734&r2=1418735&view=diff
==============================================================================
--- commons/proper/email/trunk/src/test/java/org/apache/commons/mail/EmailTest.java (original)
+++ commons/proper/email/trunk/src/test/java/org/apache/commons/mail/EmailTest.java Sat Dec 8 19:26:15 2012
@@ -56,7 +56,7 @@ public class EmailTest extends BaseEmail
/** mock for testing */
private MockEmailConcrete email;
-
+
/**
* @param name test name
*/
@@ -393,22 +393,16 @@ public class EmailTest extends BaseEmail
* @throws EmailException when there are problems adding an address
* @throws UnsupportedEncodingException on bad email addresses
*/
- public void testAddTo() throws EmailException, UnsupportedEncodingException
+ public void testAddTo() throws EmailException, AddressException, UnsupportedEncodingException
{
// ====================================================================
// Test Success
// ====================================================================
List<InternetAddress> arrExpected = new ArrayList<InternetAddress>();
- 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"));
+ arrExpected.add(new InternetAddress("me@home.com"));
+ arrExpected.add(new InternetAddress("joe.doe@apache.org"));
+ arrExpected.add(new InternetAddress("someone_here@work-address.com.au"));
for (int i = 0; i < ARR_VALID_EMAILS.length; i++)
{
@@ -425,22 +419,16 @@ 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
+ public void testAddToArray() throws EmailException, AddressException, UnsupportedEncodingException
{
// ====================================================================
// Test Success
// ====================================================================
List<InternetAddress> arrExpected = new ArrayList<InternetAddress>();
- 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"));
+ arrExpected.add(new InternetAddress("me@home.com"));
+ arrExpected.add(new InternetAddress("joe.doe@apache.org"));
+ arrExpected.add(new InternetAddress("someone_here@work-address.com.au"));
//set To
this.email.addTo(ARR_VALID_EMAILS);
@@ -454,34 +442,27 @@ public class EmailTest extends BaseEmail
* @throws EmailException when there are problems adding an address
* @throws UnsupportedEncodingException on bad email addresses
*/
- public void testAddToWithEncoding() throws UnsupportedEncodingException, EmailException
+ public void testAddToWithEncoding() throws UnsupportedEncodingException, AddressException, EmailException
{
// ====================================================================
// Test Success
// ====================================================================
String testCharset = Email.ISO_8859_1;
+ String[] testEmailNames = {"Name1", "", null};
List<InternetAddress> arrExpected = new ArrayList<InternetAddress>();
arrExpected.add(
new InternetAddress(
"me@home.com",
- "me@home.com",
- testCharset));
- arrExpected.add(
- new InternetAddress(
- "joe.doe@apache.org",
- "joe.doe@apache.org",
- testCharset));
- arrExpected.add(
- new InternetAddress(
- "someone_here@work-address.com.au",
- "someone_here@work-address.com.au",
+ "Name1",
testCharset));
+ arrExpected.add(new InternetAddress("joe.doe@apache.org"));
+ arrExpected.add(new InternetAddress("someone_here@work-address.com.au"));
for (int i = 0; i < ARR_VALID_EMAILS.length; i++)
{
// set from
- this.email.addTo(ARR_VALID_EMAILS[i]);
+ this.email.addTo(ARR_VALID_EMAILS[i], testEmailNames[i], testCharset);
}
// retrieve and verify
@@ -493,7 +474,7 @@ public class EmailTest extends BaseEmail
* @throws EmailException when there are problems adding an address
* @throws UnsupportedEncodingException on bad email addresses
*/
- public void testAddTo2() throws UnsupportedEncodingException, EmailException
+ public void testAddTo2() throws UnsupportedEncodingException, AddressException, EmailException
{
// ====================================================================
// Test Success
@@ -503,14 +484,8 @@ public class EmailTest extends BaseEmail
List<InternetAddress> arrExpected = new ArrayList<InternetAddress>();
arrExpected.add(new InternetAddress("me@home.com", "Name1"));
- 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"));
+ arrExpected.add(new InternetAddress("joe.doe@apache.org"));
+ arrExpected.add(new InternetAddress("someone_here@work-address.com.au"));
for (int i = 0; i < ARR_VALID_EMAILS.length; i++)
{
@@ -600,22 +575,16 @@ public class EmailTest extends BaseEmail
* @throws EmailException when there are problems adding an address
* @throws UnsupportedEncodingException on bad email addresses
*/
- public void testAddCc() throws UnsupportedEncodingException, EmailException
+ public void testAddCc() throws UnsupportedEncodingException, AddressException, EmailException
{
// ====================================================================
// Test Success
// ====================================================================
List<InternetAddress> arrExpected = new ArrayList<InternetAddress>();
- 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"));
+ arrExpected.add(new InternetAddress("me@home.com"));
+ arrExpected.add(new InternetAddress("joe.doe@apache.org"));
+ arrExpected.add(new InternetAddress("someone_here@work-address.com.au"));
for (int i = 0; i < ARR_VALID_EMAILS.length; i++)
{
@@ -632,22 +601,16 @@ 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
+ public void testAddCcArray() throws UnsupportedEncodingException, AddressException, EmailException
{
// ====================================================================
// Test Success
// ====================================================================
List<InternetAddress> arrExpected = new ArrayList<InternetAddress>();
- 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"));
+ arrExpected.add(new InternetAddress("me@home.com"));
+ arrExpected.add(new InternetAddress("joe.doe@apache.org"));
+ arrExpected.add(new InternetAddress("someone_here@work-address.com.au"));
//set Cc array
this.email.addCc(ARR_VALID_EMAILS);
@@ -661,34 +624,24 @@ public class EmailTest extends BaseEmail
* @throws EmailException when there are problems adding an address
* @throws UnsupportedEncodingException on bad email addresses
*/
- public void testAddCcWithEncoding() throws UnsupportedEncodingException, EmailException
+ public void testAddCcWithEncoding() throws UnsupportedEncodingException, AddressException, EmailException
{
// ====================================================================
// Test Success
// ====================================================================
String testCharset = Email.ISO_8859_1;
+ String[] testEmailNames = {"Name1", "", null};
List<InternetAddress> arrExpected = new ArrayList<InternetAddress>();
arrExpected.add(
- new InternetAddress(
- "me@home.com",
- "me@home.com",
- testCharset));
- arrExpected.add(
- new InternetAddress(
- "joe.doe@apache.org",
- "joe.doe@apache.org",
- testCharset));
- arrExpected.add(
- new InternetAddress(
- "someone_here@work-address.com.au",
- "someone_here@work-address.com.au",
- testCharset));
+ new InternetAddress("me@home.com", "Name1", testCharset));
+ arrExpected.add(new InternetAddress("joe.doe@apache.org"));
+ arrExpected.add(new InternetAddress("someone_here@work-address.com.au"));
// add valid ccs
for (int i = 0; i < ARR_VALID_EMAILS.length; i++)
{
- this.email.addCc(ARR_VALID_EMAILS[i]);
+ this.email.addCc(ARR_VALID_EMAILS[i], testEmailNames[i], testCharset);
}
// retrieve and verify
@@ -700,7 +653,7 @@ public class EmailTest extends BaseEmail
* @throws EmailException when there are problems adding an address
* @throws UnsupportedEncodingException on bad email addresses
*/
- public void testAddCc2() throws UnsupportedEncodingException, EmailException
+ public void testAddCc2() throws UnsupportedEncodingException, AddressException, EmailException
{
// ====================================================================
// Test Success
@@ -710,14 +663,8 @@ public class EmailTest extends BaseEmail
List<InternetAddress> arrExpected = new ArrayList<InternetAddress>();
arrExpected.add(new InternetAddress("me@home.com", "Name1"));
- 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"));
+ arrExpected.add(new InternetAddress("joe.doe@apache.org"));
+ arrExpected.add(new InternetAddress("someone_here@work-address.com.au"));
for (int i = 0; i < ARR_VALID_EMAILS.length; i++)
{
@@ -796,22 +743,16 @@ public class EmailTest extends BaseEmail
* @throws EmailException when there are problems adding an address
* @throws UnsupportedEncodingException on bad email addresses
*/
- public void testAddBcc() throws UnsupportedEncodingException, EmailException
+ public void testAddBcc() throws UnsupportedEncodingException, AddressException, EmailException
{
// ====================================================================
// Test Success
// ====================================================================
List<InternetAddress> arrExpected = new ArrayList<InternetAddress>();
- 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"));
+ arrExpected.add(new InternetAddress("me@home.com"));
+ arrExpected.add(new InternetAddress("joe.doe@apache.org"));
+ arrExpected.add(new InternetAddress("someone_here@work-address.com.au"));
for (int i = 0; i < ARR_VALID_EMAILS.length; i++)
{
@@ -830,19 +771,16 @@ 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
+ public void testAddBccArray() throws UnsupportedEncodingException, AddressException, EmailException
{
// ====================================================================
// Test Success
// ====================================================================
List<InternetAddress> arrExpected = new ArrayList<InternetAddress>();
- 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"));
+ arrExpected.add(new InternetAddress("me@home.com"));
+ arrExpected.add(new InternetAddress("joe.doe@apache.org"));
+ arrExpected.add(new InternetAddress("someone_here@work-address.com.au"));
// add a valid bcc
this.email.addBcc(ARR_VALID_EMAILS);
@@ -858,34 +796,23 @@ public class EmailTest extends BaseEmail
* @throws EmailException when there are problems adding an address
* @throws UnsupportedEncodingException on bad email addresses
*/
- public void testAddBccWithEncoding() throws UnsupportedEncodingException, EmailException
+ public void testAddBccWithEncoding() throws UnsupportedEncodingException, AddressException, EmailException
{
// ====================================================================
// Test Success
// ====================================================================
String testCharset = Email.ISO_8859_1;
+ String[] testEmailNames = {"Name1", "", null};
List<InternetAddress> arrExpected = new ArrayList<InternetAddress>();
- arrExpected.add(
- new InternetAddress(
- "me@home.com",
- "me@home.com",
- testCharset));
- arrExpected.add(
- new InternetAddress(
- "joe.doe@apache.org",
- "joe.doe@apache.org",
- testCharset));
- arrExpected.add(
- new InternetAddress(
- "someone_here@work-address.com.au",
- "someone_here@work-address.com.au",
- testCharset));
+ arrExpected.add(new InternetAddress("me@home.com", "Name1", testCharset));
+ arrExpected.add(new InternetAddress("joe.doe@apache.org"));
+ arrExpected.add(new InternetAddress("someone_here@work-address.com.au"));
for (int i = 0; i < ARR_VALID_EMAILS.length; i++)
{
// set bccs
- this.email.addBcc(ARR_VALID_EMAILS[i]);
+ this.email.addBcc(ARR_VALID_EMAILS[i], testEmailNames[i], testCharset);
}
// retrieve and verify
@@ -899,7 +826,7 @@ public class EmailTest extends BaseEmail
* @throws EmailException when there are problems adding an address
* @throws UnsupportedEncodingException on bad email addresses
*/
- public void testAddBcc2() throws UnsupportedEncodingException, EmailException
+ public void testAddBcc2() throws UnsupportedEncodingException, AddressException, EmailException
{
// ====================================================================
// Test Success
@@ -910,14 +837,8 @@ public class EmailTest extends BaseEmail
List<InternetAddress> arrExpected = new ArrayList<InternetAddress>();
arrExpected.add(new InternetAddress("me@home.com", "Name1"));
- 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"));
+ arrExpected.add(new InternetAddress("joe.doe@apache.org"));
+ arrExpected.add(new InternetAddress("someone_here@work-address.com.au"));
for (int i = 0; i < ARR_VALID_EMAILS.length; i++)
{
@@ -1004,22 +925,16 @@ public class EmailTest extends BaseEmail
* @throws EmailException when there are problems adding an address
* @throws UnsupportedEncodingException on bad email addresses
*/
- public void testAddReplyTo() throws UnsupportedEncodingException, EmailException
+ public void testAddReplyTo() throws UnsupportedEncodingException, AddressException, EmailException
{
// ====================================================================
// Test Success
// ====================================================================
List<InternetAddress> arrExpected = new ArrayList<InternetAddress>();
- 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"));
+ arrExpected.add(new InternetAddress("me@home.com"));
+ arrExpected.add(new InternetAddress("joe.doe@apache.org"));
+ arrExpected.add(new InternetAddress("someone_here@work-address.com.au"));
for (int i = 0; i < ARR_VALID_EMAILS.length; i++)
{
@@ -1038,34 +953,23 @@ public class EmailTest extends BaseEmail
* @throws EmailException when there are problems adding an address
* @throws UnsupportedEncodingException on bad email addresses
*/
- public void testAddReplyToWithEncoding() throws UnsupportedEncodingException, EmailException
+ public void testAddReplyToWithEncoding() throws UnsupportedEncodingException, AddressException, EmailException
{
// ====================================================================
// Test Success
// ====================================================================
String testCharset = Email.ISO_8859_1;
+ String[] testEmailNames = {"Name1", "", null};
List<InternetAddress> arrExpected = new ArrayList<InternetAddress>();
- arrExpected.add(
- new InternetAddress(
- "me@home.com",
- "me@home.com",
- testCharset));
- arrExpected.add(
- new InternetAddress(
- "joe.doe@apache.org",
- "joe.doe@apache.org",
- testCharset));
- arrExpected.add(
- new InternetAddress(
- "someone_here@work-address.com.au",
- "someone_here@work-address.com.au",
- testCharset));
+ arrExpected.add(new InternetAddress("me@home.com", "Name1", testCharset));
+ arrExpected.add(new InternetAddress("joe.doe@apache.org"));
+ arrExpected.add(new InternetAddress("someone_here@work-address.com.au"));
for (int i = 0; i < ARR_VALID_EMAILS.length; i++)
{
// set replyTo
- this.email.addReplyTo(ARR_VALID_EMAILS[i]);
+ this.email.addReplyTo(ARR_VALID_EMAILS[i], testEmailNames[i], testCharset);
}
// retrieve and verify
@@ -1079,7 +983,7 @@ public class EmailTest extends BaseEmail
* @throws EmailException when there are problems adding an address
* @throws UnsupportedEncodingException on bad email addresses
*/
- public void testAddReplyTo2() throws UnsupportedEncodingException, EmailException
+ public void testAddReplyTo2() throws UnsupportedEncodingException, AddressException, EmailException
{
// ====================================================================
// Test Success
@@ -1089,14 +993,8 @@ public class EmailTest extends BaseEmail
List<InternetAddress> arrExpected = new ArrayList<InternetAddress>();
arrExpected.add(new InternetAddress("me@home.com", "Name1"));
- 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"));
+ arrExpected.add(new InternetAddress("joe.doe@apache.org"));
+ arrExpected.add(new InternetAddress("someone_here@work-address.com.au"));
for (int i = 0; i < ARR_VALID_EMAILS.length; i++)
{