Author: dion Date: Thu Feb 22 15:47:33 2007 New Revision: 510715 URL: http://svn.apache.org/viewvc?view=rev&rev=510715 Log: EMAIL-54 Charset support
Modified: jakarta/commons/proper/email/trunk/src/java/org/apache/commons/mail/Email.java jakarta/commons/proper/email/trunk/src/test/org/apache/commons/mail/EmailTest.java Modified: jakarta/commons/proper/email/trunk/src/java/org/apache/commons/mail/Email.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/email/trunk/src/java/org/apache/commons/mail/Email.java?view=diff&rev=510715&r1=510714&r2=510715 ============================================================================== --- jakarta/commons/proper/email/trunk/src/java/org/apache/commons/mail/Email.java (original) +++ jakarta/commons/proper/email/trunk/src/java/org/apache/commons/mail/Email.java Thu Feb 22 15:47:33 2007 @@ -16,6 +16,10 @@ */ package org.apache.commons.mail; +import java.nio.charset.Charset; +import java.nio.charset.IllegalCharsetNameException; +import java.nio.charset.UnsupportedCharsetException; + import java.util.ArrayList; import java.util.Collection; import java.util.Date; @@ -166,10 +170,10 @@ * Defaults to the standard port ( 25 ). */ protected String smtpPort = "25"; - + /** * The port number of the SSL enabled SMTP server; - * defaults to the standard port, 465. + * defaults to the standard port, 465. */ protected String sslSmtpPort = "465"; @@ -220,7 +224,7 @@ protected boolean tls = false; /** does the current transport use SSL encryption? */ protected boolean ssl = false; - + /** * Setting to true will enable the display of debug information. * @@ -271,11 +275,15 @@ * Set the charset of the message. * * @param newCharset A String. + * @throws IllegalCharsetNameException if the charset name is invalid + * @throws UnsupportedCharsetException if no support for the named charset + * exists in the current JVM * @since 1.0 */ public void setCharset(String newCharset) { - this.charset = newCharset; + Charset set = Charset.forName(newCharset); + this.charset = set.name(); } /** @@ -344,7 +352,7 @@ } /** - * Set or disable the TLS encryption + * Set or disable the TLS encryption * * @param withTLS true if TLS needed, false otherwise * @since 1.1 @@ -461,7 +469,7 @@ properties.setProperty(MAIL_PORT, sslSmtpPort); properties.setProperty(MAIL_SMTP_SOCKET_FACTORY_PORT, sslSmtpPort); properties.setProperty(MAIL_SMTP_SOCKET_FACTORY_CLASS, "javax.net.ssl.SSLSocketFactory"); - properties.setProperty(MAIL_SMTP_SOCKET_FACTORY_FALLBACK, "false"); + properties.setProperty(MAIL_SMTP_SOCKET_FACTORY_FALLBACK, "false"); } if (this.bounceAddress != null) @@ -482,34 +490,41 @@ * * @param email An email address. * @param name A name. + * @param charsetName The name of the charset to encode the name with. * @return An internet address. - * @throws EmailException Thrown when the address supplied or name were invalid. + * @throws EmailException Thrown when the supplied address, name or charset were invalid. */ - private InternetAddress createInternetAddress(String email, String name) + private InternetAddress createInternetAddress(String email, String name, String charsetName) throws EmailException { InternetAddress address = null; try { + address = new InternetAddress(email); + // check name input if (EmailUtils.isEmpty(name)) { name = email; } - // Using this instead of new InternetAddress(email, name, [charset]) makes - // commons-email usable with javamail 1.2 / J2EE 1.3 - address = new InternetAddress(email); - - if (EmailUtils.isNotEmpty(this.charset)) + // check charset input. + if (EmailUtils.isEmpty(charsetName)) { - address.setPersonal(name, this.charset); + address.setPersonal(name); } else { - address.setPersonal(name); + // 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 + // it will throw AddressException. + address.validate(); } catch (Exception e) { @@ -520,7 +535,10 @@ /** - * Set the FROM field of the email. + * Set the FROM field of the email to use the specified address. The email + * address will also be used as the personal name. The name 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 email A String. * @return An Email. @@ -534,7 +552,10 @@ } /** - * Set the FROM field of the email. + * Set the FROM field of the email to use the specified address and the + * specified personal name. The name 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 email A String. * @param name A String. @@ -545,13 +566,32 @@ public Email setFrom(String email, String name) throws EmailException { - this.fromAddress = createInternetAddress(email, name); + return setFrom(email, name, null); + } + /** + * Set the FROM field of the email to use the specified address, personal + * name, and charset encoding for the name. + * + * @param email A String. + * @param name A String. + * @param charset The charset to encode the name with. + * @throws EmailException Indicates an invalid email address or charset. + * @return An Email. + * @since 1.1 + */ + public Email setFrom(String email, String name, String charset) + throws EmailException + { + this.fromAddress = createInternetAddress(email, name, charset); return this; } /** - * Add a recipient TO to the email. + * Add a recipient TO to the email. The email + * address will also be used as the personal name. The name 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 email A String. * @throws EmailException Indicates an invalid email address. @@ -565,7 +605,10 @@ } /** - * Add a recipient TO to the email. + * Add a recipient TO to the email using the specified address and the + * specified personal name. The name 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 email A String. * @param name A String. @@ -576,16 +619,36 @@ public Email addTo(String email, String name) throws EmailException { - this.toList.add(createInternetAddress(email, name)); + return addTo(email, name, null); + } + + /** + * Add a recipient TO to the email using the specified address, personal + * name, and charset encoding for the name. + * + * @param email A String. + * @param name A String. + * @param charset The charset to encode the name with. + * @throws EmailException Indicates an invalid email address or charset. + * @return An Email. + * @since 1.1 + */ + public Email addTo(String email, String name, String charset) + throws EmailException + { + this.toList.add(createInternetAddress(email, name, charset)); return this; } /** - * Set a list of "TO" addresses. + * Set a list of "TO" addresses. All elements in the specified + * <code>Collection</code> are expected to be of type + * <code>java.mail.internet.InternetAddress</code>. * - * @param aCollection collection of InternetAddress objects. + * @param aCollection collection of <code>InternetAddress</code> objects. * @throws EmailException Indicates an invalid email address. * @return An Email. + * @see javax.mail.internet.InternetAddress * @since 1.0 */ public Email setTo(Collection aCollection) throws EmailException @@ -600,7 +663,10 @@ } /** - * Add a recipient CC to the email. + * Add a recipient CC to the email. The email + * address will also be used as the personal name. The name 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 email A String. * @return An Email. @@ -614,7 +680,10 @@ } /** - * Add a recipient CC to the email. + * Add a recipient CC to the email using the specified address and the + * specified personal name. The name 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 email A String. * @param name A String. @@ -625,17 +694,37 @@ public Email addCc(String email, String name) throws EmailException { - this.ccList.add(createInternetAddress(email, name)); + return addCc(email, name, null); + } + + /** + * Add a recipient CC to the email using the specified address, personal + * name, and charset encoding for the name. + * + * @param email A String. + * @param name A String. + * @param charset The charset to encode the name with. + * @throws EmailException Indicates an invalid email address or charset. + * @return An Email. + * @since 1.1 + */ + public Email addCc(String email, String name, String charset) + throws EmailException + { + this.ccList.add(createInternetAddress(email, name, charset)); return this; } /** - * Set a list of "CC" addresses. + * Set a list of "CC" addresses. All elements in the specified + * <code>Collection</code> are expected to be of type + * <code>java.mail.internet.InternetAddress</code>. * - * @param aCollection collection of InternetAddress objects. + * @param aCollection collection of <code>InternetAddress</code> objects. * @return An Email. - * @throws EmailException Indicates an invalid email address - * @since 1.0. + * @throws EmailException Indicates an invalid email address. + * @see javax.mail.internet.InternetAddress + * @since 1.0 */ public Email setCc(Collection aCollection) throws EmailException { @@ -649,7 +738,10 @@ } /** - * Add a blind BCC recipient to the email. + * Add a blind BCC recipient to the email. The email + * address will also be used as the personal name. The name 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 email A String. * @return An Email. @@ -663,7 +755,10 @@ } /** - * Add a blind BCC recipient to the email. + * Add a blind BCC recipient to the email using the specified address and + * the specified personal name. The name 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 email A String. * @param name A String. @@ -674,16 +769,36 @@ public Email addBcc(String email, String name) throws EmailException { - this.bccList.add(createInternetAddress(email, name)); + return addBcc(email, name, null); + } + + /** + * Add a blind BCC recipient to the email using the specified address, + * personal name, and charset encoding for the name. + * + * @param email A String. + * @param name A String. + * @param charset The charset to encode the name with. + * @return An Email. + * @throws EmailException Indicates an invalid email address + * @since 1.1 + */ + public Email addBcc(String email, String name, String charset) + throws EmailException + { + this.bccList.add(createInternetAddress(email, name, charset)); return this; } /** - * Set a list of "BCC" addresses + * Set a list of "BCC" addresses. All elements in the specified + * <code>Collection</code> are expected to be of type + * <code>java.mail.internet.InternetAddress</code>. * - * @param aCollection collection of InternetAddress objects + * @param aCollection collection of <code>InternetAddress</code> objects * @return An Email. * @throws EmailException Indicates an invalid email address + * @see javax.mail.internet.InternetAddress * @since 1.0 */ public Email setBcc(Collection aCollection) throws EmailException @@ -698,7 +813,10 @@ } /** - * Add a reply to address to the email. + * Add a reply to address to the email. The email + * address will also be used as the personal name. The name 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 email A String. * @return An Email. @@ -712,7 +830,10 @@ } /** - * Add a reply to address to the email. + * Add a reply to address to the email using the specified address and + * the specified personal name. The name 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 email A String. * @param name A String. @@ -723,16 +844,36 @@ public Email addReplyTo(String email, String name) throws EmailException { - this.replyList.add(createInternetAddress(email, name)); + return addReplyTo(email, name, null); + } + + /** + * Add a reply to address to the email using the specified address, + * personal name, and charset encoding for the name. + * + * @param email A String. + * @param name A String. + * @param charset The charset to encode the name with. + * @return An Email. + * @throws EmailException Indicates an invalid email address or charset. + * @since 1.1 + */ + public Email addReplyTo(String email, String name, String charset) + throws EmailException + { + this.replyList.add(createInternetAddress(email, name, charset)); return this; } /** - * Set a list of reply addresses + * Set a list of reply to addresses. All elements in the specified + * <code>Collection</code> are expected to be of type + * <code>java.mail.internet.InternetAddress</code>. * - * @param aCollection collection of InternetAddress objects + * @param aCollection collection of <code>InternetAddress</code> objects * @return An Email. * @throws EmailException Indicates an invalid email address + * @see javax.mail.internet.InternetAddress * @since 1.1 */ public Email setReplyTo(Collection aCollection) throws EmailException Modified: jakarta/commons/proper/email/trunk/src/test/org/apache/commons/mail/EmailTest.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/email/trunk/src/test/org/apache/commons/mail/EmailTest.java?view=diff&rev=510715&r1=510714&r2=510715 ============================================================================== --- jakarta/commons/proper/email/trunk/src/test/org/apache/commons/mail/EmailTest.java (original) +++ jakarta/commons/proper/email/trunk/src/test/org/apache/commons/mail/EmailTest.java Thu Feb 22 15:47:33 2007 @@ -17,6 +17,8 @@ package org.apache.commons.mail; import java.io.UnsupportedEncodingException; +import java.nio.charset.Charset; +import java.nio.charset.IllegalCharsetNameException; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; @@ -157,11 +159,15 @@ /** */ public void testGetSetCharset() { - for (int i = 0; i < testCharsValid.length; i++) - { - this.email.setCharset(testCharsValid[i]); - assertEquals(testCharsValid[i], this.email.getCharset()); - } + // test ASCII and UTF-8 charsets; since every JVM is required + // to support these, testing them should always succeed. + Charset set = Charset.forName("US-ASCII"); + this.email.setCharset(set.name()); + assertEquals(set.name(), this.email.getCharset()); + + set = Charset.forName("UTF-8"); + this.email.setCharset(set.name()); + assertEquals(set.name(), this.email.getCharset()); } /** */ @@ -304,7 +310,7 @@ * * @throws Exception Exception */ - public void testSetFromWithEnconding() throws Exception + public void testSetFromWithEncoding() throws Exception { // ==================================================================== // Test Success (with charset set) @@ -312,11 +318,10 @@ String testValidEmail = "[EMAIL PROTECTED]"; InternetAddress inetExpected = - new InternetAddress("[EMAIL PROTECTED]", "[EMAIL PROTECTED]"); + new InternetAddress("[EMAIL PROTECTED]", "[EMAIL PROTECTED]", Email.ISO_8859_1); // set from - this.email.setCharset(Email.ISO_8859_1); - this.email.setFrom(testValidEmail); + this.email.setFrom(testValidEmail, testValidEmail, Email.ISO_8859_1); // retrieve and verify assertEquals(inetExpected, this.email.getFromAddress()); @@ -336,7 +341,7 @@ { "[EMAIL PROTECTED]", "[EMAIL PROTECTED]", - "[EMAIL PROTECTED]" + "[EMAIL PROTECTED]" }; String[] testEmailNames = { "Name1", "", null }; ArrayList arrExpected = new ArrayList(); @@ -363,27 +368,25 @@ // ==================================================================== // Test Exceptions // ==================================================================== + // reset the mail class + MockEmailConcrete anotherEmail = new MockEmailConcrete(); + // bad encoding try { - // reset the mail class - MockEmailConcrete anotherEmail = new MockEmailConcrete(); // set a dodgy encoding scheme - anotherEmail.setCharset("bad.encoding\uc5ec\n"); - // set a valid address but bad personal name - anotherEmail.setFrom( - "[EMAIL PROTECTED]", - "\t.bad.personal.name.\uc5ec\n"); - fail("Should have thrown an exception"); + anotherEmail.setFrom("[EMAIL PROTECTED]", "[EMAIL PROTECTED]", "bad.encoding\uc5ec\n"); + fail("setting invalid charset should have failed!"); } catch (EmailException e) { - assertTrue(true); + // expected runtime exception. + assertTrue(e.getCause() instanceof IllegalCharsetNameException); } } /** - * @throws EmailException + * @throws EmailException * @throws UnsupportedEncodingException */ public void testAddTo() throws EmailException, UnsupportedEncodingException { @@ -414,25 +417,31 @@ } /** - * @throws UnsupportedEncodingException + * @throws UnsupportedEncodingException * @throws EmailException */ public void testAddToWithEncoding() throws UnsupportedEncodingException, EmailException { // ==================================================================== // Test Success // ==================================================================== - this.email.charset = Email.US_ASCII; + String testCharset = Email.ISO_8859_1; ArrayList arrExpected = new ArrayList(); - arrExpected.add(new InternetAddress("[EMAIL PROTECTED]", "[EMAIL PROTECTED]")); + arrExpected.add( + new InternetAddress( + "[EMAIL PROTECTED]", + "[EMAIL PROTECTED]", + testCharset)); arrExpected.add( new InternetAddress( "[EMAIL PROTECTED]", - "[EMAIL PROTECTED]")); + "[EMAIL PROTECTED]", + testCharset)); arrExpected.add( new InternetAddress( "[EMAIL PROTECTED]", - "[EMAIL PROTECTED]")); + "[EMAIL PROTECTED]", + testCharset)); for (int i = 0; i < ARR_VALID_EMAILS.length; i++) { @@ -446,7 +455,7 @@ } /** - * @throws UnsupportedEncodingException + * @throws UnsupportedEncodingException * @throws EmailException */ public void testAddTo2() throws UnsupportedEncodingException, EmailException { @@ -480,26 +489,26 @@ // ==================================================================== // Test Exceptions // ==================================================================== + // reset the mail class + MockEmailConcrete anotherEmail = new MockEmailConcrete(); + // bad encoding try { - // reset the mail class - MockEmailConcrete anotherEmail = new MockEmailConcrete(); // set a dodgy encoding scheme - anotherEmail.setCharset("bad.encoding\uc5ec\n"); - // set a valid address but bad personal name - anotherEmail.addTo("[EMAIL PROTECTED]", "\t.bad.name.\uc5ec\n"); - fail("Should have thrown an exception"); + anotherEmail.addTo("[EMAIL PROTECTED]", "[EMAIL PROTECTED]", "bad.encoding\uc5ec\n"); + fail("setting invalid charset should have failed!"); } catch (EmailException e) { - assertTrue(true); + // expected runtime exception. + assertTrue(e.getCause() instanceof IllegalCharsetNameException); } } /** - * @throws UnsupportedEncodingException - * @throws EmailException + * @throws UnsupportedEncodingException + * @throws EmailException */ public void testSetTo() throws UnsupportedEncodingException, EmailException { @@ -553,7 +562,7 @@ } /** - * @throws UnsupportedEncodingException + * @throws UnsupportedEncodingException * @throws EmailException */ public void testAddCc() throws UnsupportedEncodingException, EmailException { @@ -584,25 +593,31 @@ } /** - * @throws UnsupportedEncodingException + * @throws UnsupportedEncodingException * @throws EmailException */ public void testAddCcWithEncoding() throws UnsupportedEncodingException, EmailException { // ==================================================================== // Test Success // ==================================================================== - this.email.charset = Email.US_ASCII; + String testCharset = Email.ISO_8859_1; ArrayList arrExpected = new ArrayList(); - arrExpected.add(new InternetAddress("[EMAIL PROTECTED]", "[EMAIL PROTECTED]")); + arrExpected.add( + new InternetAddress( + "[EMAIL PROTECTED]", + "[EMAIL PROTECTED]", + testCharset)); arrExpected.add( new InternetAddress( "[EMAIL PROTECTED]", - "[EMAIL PROTECTED]")); + "[EMAIL PROTECTED]", + testCharset)); arrExpected.add( new InternetAddress( "[EMAIL PROTECTED]", - "[EMAIL PROTECTED]")); + "[EMAIL PROTECTED]", + testCharset)); // add valid ccs for (int i = 0; i < ARR_VALID_EMAILS.length; i++) @@ -616,7 +631,7 @@ } /** - * @throws UnsupportedEncodingException + * @throws UnsupportedEncodingException * @throws EmailException */ public void testAddCc2() throws UnsupportedEncodingException, EmailException { @@ -650,20 +665,20 @@ // ==================================================================== // Test Exceptions // ==================================================================== + // reset the mail class + MockEmailConcrete anotherEmail = new MockEmailConcrete(); + // bad encoding try { - // reset the mail class - MockEmailConcrete anotherEmail = new MockEmailConcrete(); // set a dodgy encoding scheme - anotherEmail.setCharset("bad.encoding\uc5ec\n"); - // set a valid address but bad personal name - anotherEmail.addCc("[EMAIL PROTECTED]", "\t.bad.name.\uc5ec\n"); - fail("Should have thrown an exception"); + anotherEmail.addCc("[EMAIL PROTECTED]", "[EMAIL PROTECTED]", "bad.encoding\uc5ec\n"); + fail("setting invalid charset should have failed!"); } catch (EmailException e) { - assertTrue(true); + // expected runtime exception. + assertTrue(e.getCause() instanceof IllegalCharsetNameException); } } @@ -711,7 +726,7 @@ } /** - * @throws UnsupportedEncodingException + * @throws UnsupportedEncodingException * @throws EmailException */ public void testAddBcc() throws UnsupportedEncodingException, EmailException { @@ -744,25 +759,31 @@ } /** - * @throws UnsupportedEncodingException + * @throws UnsupportedEncodingException * @throws EmailException */ public void testAddBccWithEncoding() throws UnsupportedEncodingException, EmailException { // ==================================================================== // Test Success // ==================================================================== - this.email.charset = Email.US_ASCII; + String testCharset = Email.ISO_8859_1; ArrayList arrExpected = new ArrayList(); - arrExpected.add(new InternetAddress("[EMAIL PROTECTED]", "[EMAIL PROTECTED]")); + arrExpected.add( + new InternetAddress( + "[EMAIL PROTECTED]", + "[EMAIL PROTECTED]", + testCharset)); arrExpected.add( new InternetAddress( "[EMAIL PROTECTED]", - "[EMAIL PROTECTED]")); + "[EMAIL PROTECTED]", + testCharset)); arrExpected.add( new InternetAddress( "[EMAIL PROTECTED]", - "[EMAIL PROTECTED]")); + "[EMAIL PROTECTED]", + testCharset)); for (int i = 0; i < ARR_VALID_EMAILS.length; i++) { @@ -778,7 +799,7 @@ } /** - * @throws UnsupportedEncodingException + * @throws UnsupportedEncodingException * @throws EmailException */ public void testAddBcc2() throws UnsupportedEncodingException, EmailException { @@ -814,25 +835,25 @@ // ==================================================================== // Test Exceptions // ==================================================================== + // reset the mail class + MockEmailConcrete anotherEmail = new MockEmailConcrete(); + // bad encoding try { - // reset the mail class - MockEmailConcrete anotherEmail = new MockEmailConcrete(); // set a dodgy encoding scheme - anotherEmail.setCharset("bad.encoding\uc5ec\n"); - // set a valid address but bad personal name - anotherEmail.addBcc("[EMAIL PROTECTED]", "\t.bad.name.\uc5ec\n"); - fail("Should have thrown an exception"); + anotherEmail.addBcc("[EMAIL PROTECTED]", "[EMAIL PROTECTED]", "bad.encoding\uc5ec\n"); + fail("setting invalid charset should have failed!"); } catch (EmailException e) { - assertTrue(true); + // expected runtime exception. + assertTrue(e.getCause() instanceof IllegalCharsetNameException); } } /** - * @throws UnsupportedEncodingException + * @throws UnsupportedEncodingException * @throws EmailException */ public void testSetBcc() throws UnsupportedEncodingException, EmailException { @@ -881,7 +902,7 @@ } /** - * @throws UnsupportedEncodingException + * @throws UnsupportedEncodingException * @throws EmailException */ public void testAddReplyTo() throws UnsupportedEncodingException, EmailException { @@ -914,25 +935,31 @@ } /** - * @throws UnsupportedEncodingException + * @throws UnsupportedEncodingException * @throws EmailException */ public void testAddReplyToWithEncoding() throws UnsupportedEncodingException, EmailException { // ==================================================================== // Test Success // ==================================================================== - this.email.charset = Email.US_ASCII; + String testCharset = Email.ISO_8859_1; ArrayList arrExpected = new ArrayList(); - arrExpected.add(new InternetAddress("[EMAIL PROTECTED]", "[EMAIL PROTECTED]")); + arrExpected.add( + new InternetAddress( + "[EMAIL PROTECTED]", + "[EMAIL PROTECTED]", + testCharset)); arrExpected.add( new InternetAddress( "[EMAIL PROTECTED]", - "[EMAIL PROTECTED]")); + "[EMAIL PROTECTED]", + testCharset)); arrExpected.add( new InternetAddress( "[EMAIL PROTECTED]", - "[EMAIL PROTECTED]")); + "[EMAIL PROTECTED]", + testCharset)); for (int i = 0; i < ARR_VALID_EMAILS.length; i++) { @@ -948,7 +975,7 @@ } /** - * @throws UnsupportedEncodingException + * @throws UnsupportedEncodingException * @throws EmailException */ public void testAddReplyTo2() throws UnsupportedEncodingException, EmailException { @@ -984,20 +1011,20 @@ // ==================================================================== // Test Exceptions // ==================================================================== + // reset the mail class + MockEmailConcrete anotherEmail = new MockEmailConcrete(); + // bad encoding try { - // reset the mail class - MockEmailConcrete anotherEmail = new MockEmailConcrete(); // set a dodgy encoding scheme - anotherEmail.setCharset("bad.encoding\uc5ec\n"); - // set a valid address but bad personal name - anotherEmail.addReplyTo("[EMAIL PROTECTED]", "\t.bad.name.\uc5ec\n"); - fail("Should have thrown an exception"); + anotherEmail.addReplyTo("[EMAIL PROTECTED]", "[EMAIL PROTECTED]", "bad.encoding\uc5ec\n"); + fail("setting invalid charset should have failed!"); } catch (EmailException e) { - assertTrue(true); + // expected runtime exception. + assertTrue(e.getCause() instanceof IllegalCharsetNameException); } } @@ -1269,7 +1296,7 @@ } /** - * @throws EmailException + * @throws EmailException * @throws UnsupportedEncodingException */ public void testToInternetAddressArray() throws EmailException, UnsupportedEncodingException { --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]