geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1620683 [16/17] - in /geronimo/specs/trunk: ./ geronimo-javamail_1.5_spec/ geronimo-javamail_1.5_spec/src/ geronimo-javamail_1.5_spec/src/main/ geronimo-javamail_1.5_spec/src/main/java/ geronimo-javamail_1.5_spec/src/main/java/javax/ geron...
Date Tue, 26 Aug 2014 18:17:09 GMT
Added: geronimo/specs/trunk/geronimo-javamail_1.5_spec/src/test/java/javax/mail/internet/ContentDispositionTest.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-javamail_1.5_spec/src/test/java/javax/mail/internet/ContentDispositionTest.java?rev=1620683&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-javamail_1.5_spec/src/test/java/javax/mail/internet/ContentDispositionTest.java (added)
+++ geronimo/specs/trunk/geronimo-javamail_1.5_spec/src/test/java/javax/mail/internet/ContentDispositionTest.java Tue Aug 26 18:17:06 2014
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package javax.mail.internet;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ContentDispositionTest extends TestCase {
+
+    public ContentDispositionTest(final String name) {
+        super(name);
+    }
+
+    public void testContentDisposition() throws ParseException {
+        ContentDisposition c;
+        c = new ContentDisposition();
+        assertNotNull(c.getParameterList());
+        assertNull(c.getParameterList().get("nothing"));
+        assertNull(c.getDisposition());
+        assertEquals("", c.toString());
+        c.setDisposition("inline");
+        assertEquals("inline",c.getDisposition());
+        c.setParameter("file","file.txt");
+        assertEquals("file.txt",c.getParameterList().get("file"));
+        assertEquals("inline; file=file.txt",c.toString());
+        c = new ContentDisposition("inline");
+        assertNotNull(c.getParameterList());
+        assertEquals(0,c.getParameterList().size());
+        assertEquals("inline",c.getDisposition());
+        c = new ContentDisposition("inline",new ParameterList(";charset=us-ascii;content-type=\"text/plain\""));
+        assertEquals("inline",c.getDisposition());
+        assertEquals("us-ascii",c.getParameter("charset"));
+        assertEquals("text/plain",c.getParameter("content-type"));
+        c = new ContentDisposition("attachment;content-type=\"text/html\";charset=UTF-8");
+        assertEquals("attachment",c.getDisposition());
+        assertEquals("UTF-8",c.getParameter("charset"));
+        assertEquals("text/html",c.getParameter("content-type"));
+    }
+
+}

Added: geronimo/specs/trunk/geronimo-javamail_1.5_spec/src/test/java/javax/mail/internet/ContentTypeTest.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-javamail_1.5_spec/src/test/java/javax/mail/internet/ContentTypeTest.java?rev=1620683&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-javamail_1.5_spec/src/test/java/javax/mail/internet/ContentTypeTest.java (added)
+++ geronimo/specs/trunk/geronimo-javamail_1.5_spec/src/test/java/javax/mail/internet/ContentTypeTest.java Tue Aug 26 18:17:06 2014
@@ -0,0 +1,158 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package javax.mail.internet;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ContentTypeTest extends TestCase {
+    public ContentTypeTest(final String arg0) {
+        super(arg0);
+    }
+    public void testContentType() throws ParseException {
+        final ContentType type = new ContentType();
+        assertNull(type.getPrimaryType());
+        assertNull(type.getSubType());
+        assertNull(type.getParameter("charset"));
+    }
+
+    public void testContentTypeStringStringParameterList() throws ParseException {
+        ContentType type;
+        final ParameterList list = new ParameterList(";charset=us-ascii");
+        type = new ContentType("text", "plain", list);
+        assertEquals("text", type.getPrimaryType());
+        assertEquals("plain", type.getSubType());
+        assertEquals("text/plain", type.getBaseType());
+        final ParameterList parameterList = type.getParameterList();
+        assertEquals("us-ascii", parameterList.get("charset"));
+        assertEquals("us-ascii", type.getParameter("charset"));
+
+    }
+
+    public void testContentTypeString() throws ParseException {
+        ContentType type;
+        type = new ContentType("text/plain");
+        assertEquals("text", type.getPrimaryType());
+        assertEquals("plain", type.getSubType());
+        assertEquals("text/plain", type.getBaseType());
+        assertNotNull(type.getParameterList());
+        assertNull(type.getParameter("charset"));
+        type = new ContentType("image/audio;charset=us-ascii");
+        final ParameterList parameterList = type.getParameterList();
+        assertEquals("image", type.getPrimaryType());
+        assertEquals("audio", type.getSubType());
+        assertEquals("image/audio", type.getBaseType());
+        assertEquals("us-ascii", parameterList.get("charset"));
+        assertEquals("us-ascii", type.getParameter("charset"));
+    }
+    public void testGetPrimaryType() throws ParseException {
+    }
+    public void testGetSubType() throws ParseException {
+    }
+    public void testGetBaseType() throws ParseException {
+    }
+    public void testGetParameter() throws ParseException {
+    }
+    public void testGetParameterList() throws ParseException {
+    }
+    public void testSetPrimaryType() throws ParseException {
+        final ContentType type = new ContentType("text/plain");
+        type.setPrimaryType("binary");
+        assertEquals("binary", type.getPrimaryType());
+        assertEquals("plain", type.getSubType());
+        assertEquals("binary/plain", type.getBaseType());
+    }
+    public void testSetSubType() throws ParseException {
+        final ContentType type = new ContentType("text/plain");
+        type.setSubType("html");
+        assertEquals("text", type.getPrimaryType());
+        assertEquals("html", type.getSubType());
+        assertEquals("text/html", type.getBaseType());
+    }
+    public void testSetParameter() throws ParseException {
+    }
+    public void testSetParameterList() throws ParseException {
+    }
+    public void testToString() throws ParseException {
+        final ContentType type = new ContentType("text/plain");
+        assertEquals("text/plain", type.toString());
+        type.setParameter("foo", "bar");
+        assertEquals("text/plain; foo=bar", type.toString());
+        type.setParameter("bar", "me@apache.org");
+        assertEquals("text/plain; foo=bar; bar=\"me@apache.org\"", type.toString());
+    }
+    public void testMatchContentType() throws ParseException {
+        final ContentType type = new ContentType("text/plain");
+
+        ContentType test = new ContentType("text/plain");
+
+        assertTrue(type.match(test));
+
+        test = new ContentType("TEXT/plain");
+        assertTrue(type.match(test));
+        assertTrue(test.match(type));
+
+        test = new ContentType("text/PLAIN");
+        assertTrue(type.match(test));
+        assertTrue(test.match(type));
+
+        test = new ContentType("text/*");
+        assertTrue(type.match(test));
+        assertTrue(test.match(type));
+
+        test = new ContentType("text/xml");
+        assertFalse(type.match(test));
+        assertFalse(test.match(type));
+
+        test = new ContentType("binary/plain");
+        assertFalse(type.match(test));
+        assertFalse(test.match(type));
+
+        test = new ContentType("*/plain");
+        assertFalse(type.match(test));
+        assertFalse(test.match(type));
+    }
+    public void testMatchString() throws ParseException {
+        final ContentType type = new ContentType("text/plain");
+        assertTrue(type.match("text/plain"));
+        assertTrue(type.match("TEXT/plain"));
+        assertTrue(type.match("text/PLAIN"));
+        assertTrue(type.match("TEXT/PLAIN"));
+        assertTrue(type.match("TEXT/*"));
+
+        assertFalse(type.match("text/xml"));
+        assertFalse(type.match("binary/plain"));
+        assertFalse(type.match("*/plain"));
+        assertFalse(type.match(""));
+        assertFalse(type.match("text/plain/yada"));
+    }
+    
+    public void testSOAP12ContentType() throws ParseException {
+        final ContentType type = new ContentType("multipart/related; type=\"application/xop+xml\"; start=\"<rootpart@soapui.org>\"; start-info=\"application/soap+xml; action=\\\"urn:upload\\\"\"; boundary=\"----=_Part_10_5804917.1223557742343\"");
+        assertEquals("multipart/related", type.getBaseType());
+        assertEquals("application/xop+xml", type.getParameter("type"));
+        assertEquals("<rootpart@soapui.org>", type.getParameter("start"));
+        assertEquals("application/soap+xml; action=\"urn:upload\"", type.getParameter("start-info"));
+        assertEquals("----=_Part_10_5804917.1223557742343", type.getParameter("boundary"));
+    }
+
+}

Added: geronimo/specs/trunk/geronimo-javamail_1.5_spec/src/test/java/javax/mail/internet/HeaderTokenizerTest.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-javamail_1.5_spec/src/test/java/javax/mail/internet/HeaderTokenizerTest.java?rev=1620683&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-javamail_1.5_spec/src/test/java/javax/mail/internet/HeaderTokenizerTest.java (added)
+++ geronimo/specs/trunk/geronimo-javamail_1.5_spec/src/test/java/javax/mail/internet/HeaderTokenizerTest.java Tue Aug 26 18:17:06 2014
@@ -0,0 +1,197 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package javax.mail.internet;
+
+import javax.mail.internet.HeaderTokenizer.Token;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class HeaderTokenizerTest extends TestCase {
+    public void testTokenizer() throws ParseException {
+        final Token t;
+        HeaderTokenizer ht;
+        ht =
+            new HeaderTokenizer("To: \"Geronimo List\" <geronimo-dev@apache.org>, \n\r Geronimo User <geronimo-user@apache.org>");
+        validateToken(ht.peek(), Token.ATOM, "To");
+        validateToken(ht.next(), Token.ATOM, "To");
+        validateToken(ht.peek(), ':', ":");
+        validateToken(ht.next(), ':', ":");
+        validateToken(ht.next(), Token.QUOTEDSTRING, "Geronimo List");
+        validateToken(ht.next(), '<', "<");
+        validateToken(ht.next(), Token.ATOM, "geronimo-dev");
+        validateToken(ht.next(), '@', "@");
+        validateToken(ht.next(), Token.ATOM, "apache");
+        validateToken(ht.next(), '.', ".");
+        validateToken(ht.next(), Token.ATOM, "org");
+        validateToken(ht.next(), '>', ">");
+        validateToken(ht.next(), ',', ",");
+        validateToken(ht.next(), Token.ATOM, "Geronimo");
+        validateToken(ht.next(), Token.ATOM, "User");
+        validateToken(ht.next(), '<', "<");
+        validateToken(ht.next(), Token.ATOM, "geronimo-user");
+        validateToken(ht.next(), '@', "@");
+        validateToken(ht.next(), Token.ATOM, "apache");
+        validateToken(ht.next(), '.', ".");
+        assertEquals("org>", ht.getRemainder());
+        validateToken(ht.peek(), Token.ATOM, "org");
+        validateToken(ht.next(), Token.ATOM, "org");
+        validateToken(ht.next(), '>', ">");
+        assertEquals(Token.EOF, ht.next().getType());
+        ht = new HeaderTokenizer("   ");
+        assertEquals(Token.EOF, ht.next().getType());
+        ht = new HeaderTokenizer("J2EE");
+        validateToken(ht.next(), Token.ATOM, "J2EE");
+        assertEquals(Token.EOF, ht.next().getType());
+        // test comments
+        doComment(true);
+        doComment(false);
+    }
+
+    public void testErrors() throws ParseException {
+        checkParseError("(Geronimo");
+        checkParseError("((Geronimo)");
+        checkParseError("\"Geronimo");
+        checkParseError("\"Geronimo\\");
+    }
+
+
+    public void testQuotedLiteral() throws ParseException {
+        checkTokenParse("\"\"", Token.QUOTEDSTRING, "");
+        checkTokenParse("\"\\\"\"", Token.QUOTEDSTRING, "\"");
+        checkTokenParse("\"\\\"\"", Token.QUOTEDSTRING, "\"");
+        checkTokenParse("\"A\r\nB\"", Token.QUOTEDSTRING, "AB");
+        checkTokenParse("\"A\nB\"", Token.QUOTEDSTRING, "A\nB");
+    }
+
+
+    public void testComment() throws ParseException {
+        checkTokenParse("()", Token.COMMENT, "");
+        checkTokenParse("(())", Token.COMMENT, "()");
+        checkTokenParse("(Foo () Bar)", Token.COMMENT, "Foo () Bar");
+        checkTokenParse("(\"Foo () Bar)", Token.COMMENT, "\"Foo () Bar");
+        checkTokenParse("(\\()", Token.COMMENT, "(");
+        checkTokenParse("(Foo \r\n Bar)", Token.COMMENT, "Foo  Bar");
+        checkTokenParse("(Foo \n Bar)", Token.COMMENT, "Foo \n Bar");
+    }
+    
+    public void testJavaMail15NextMethod() throws ParseException{
+        HeaderTokenizer ht;
+        ht =
+            new HeaderTokenizer("To: \"Geronimo List\\\" <geronimo-dev@apache.org>, \n\r Geronimo User <geronimo-user@apache.org>");
+        validateToken(ht.next('>', false), Token.QUOTEDSTRING, "To: \"Geronimo List\" <geronimo-dev@apache.org");
+    }
+    
+    public void testJavaMail15NextMethodEscapes() throws ParseException{
+        HeaderTokenizer ht;
+        ht =
+            new HeaderTokenizer("To: \"Geronimo List\\\" <geronimo-dev@apache.org>, \n\r Geronimo User <geronimo-user@apache.org>");
+        validateToken(ht.next('<', true), Token.QUOTEDSTRING, "To: \"Geronimo List\\\" ");
+    }
+    
+    public void testJavaMail15NextMethodEscapes2() throws ParseException{
+        HeaderTokenizer ht;
+        ht =
+            new HeaderTokenizer("To: \"Geronimo List\" <geronimo-dev@apac\\he.org>, \n\r Geronimo User <geronimo-user@apache.org>");
+        ht.next();
+        ht.next();
+        ht.next();
+        validateToken(ht.next(',', false), Token.QUOTEDSTRING, "<geronimo-dev@apache.org>");
+    }
+    
+    public void testJavaMail15NextMethodEscapes3() throws ParseException{
+        HeaderTokenizer ht;
+        ht =
+            new HeaderTokenizer("To: \"Geronimo List\" <geronimo-dev@apac\\he.org>, \n\r Geronimo User <geronimo-user@apache.org>");
+        ht.next();
+        ht.next();
+        ht.next();
+        validateToken(ht.next(',', true), Token.QUOTEDSTRING, "<geronimo-dev@apac\\he.org>");
+    }
+
+    public void checkTokenParse(final String text, final int type, final String value) throws ParseException {
+        HeaderTokenizer ht;
+        ht = new HeaderTokenizer(text, HeaderTokenizer.RFC822, false);
+        validateToken(ht.next(), type, value);
+    }
+
+
+    public void checkParseError(final String text) throws ParseException {
+        final Token t;
+        HeaderTokenizer ht;
+
+        ht = new HeaderTokenizer(text);
+        doNextError(ht);
+        ht = new HeaderTokenizer(text);
+        doPeekError(ht);
+    }
+
+    public void doNextError(final HeaderTokenizer ht) {
+        try {
+            ht.next();
+            fail("Expected ParseException");
+        } catch (final ParseException e) {
+        }
+    }
+
+    public void doPeekError(final HeaderTokenizer ht) {
+        try {
+            ht.peek();
+            fail("Expected ParseException");
+        } catch (final ParseException e) {
+        }
+    }
+
+
+    public void doComment(final boolean ignore) throws ParseException {
+        HeaderTokenizer ht;
+        final Token t;
+        ht =
+            new HeaderTokenizer(
+                "Apache(Geronimo)J2EE",
+                HeaderTokenizer.RFC822,
+                ignore);
+        validateToken(ht.next(), Token.ATOM, "Apache");
+        if (!ignore) {
+            validateToken(ht.next(), Token.COMMENT, "Geronimo");
+        }
+        validateToken(ht.next(), Token.ATOM, "J2EE");
+        assertEquals(Token.EOF, ht.next().getType());
+
+        ht =
+            new HeaderTokenizer(
+                "Apache(Geronimo (Project))J2EE",
+                HeaderTokenizer.RFC822,
+                ignore);
+        validateToken(ht.next(), Token.ATOM, "Apache");
+        if (!ignore) {
+            validateToken(ht.next(), Token.COMMENT, "Geronimo (Project)");
+        }
+        validateToken(ht.next(), Token.ATOM, "J2EE");
+        assertEquals(Token.EOF, ht.next().getType());
+    }
+
+    private void validateToken(final HeaderTokenizer.Token token, final int type, final String value) {
+        assertEquals(type, token.getType());
+        assertEquals(value, token.getValue());
+    }
+}

Added: geronimo/specs/trunk/geronimo-javamail_1.5_spec/src/test/java/javax/mail/internet/InternetAddressTest.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-javamail_1.5_spec/src/test/java/javax/mail/internet/InternetAddressTest.java?rev=1620683&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-javamail_1.5_spec/src/test/java/javax/mail/internet/InternetAddressTest.java (added)
+++ geronimo/specs/trunk/geronimo-javamail_1.5_spec/src/test/java/javax/mail/internet/InternetAddressTest.java Tue Aug 26 18:17:06 2014
@@ -0,0 +1,553 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package javax.mail.internet;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.Properties;
+
+import javax.mail.Session;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class InternetAddressTest extends TestCase {
+    private InternetAddress address;
+
+    public void testQuotedLiterals() throws Exception {
+        parseHeaderTest("\"Foo\t\n\\\\\\\"\" <foo@apache.org>", true, "foo@apache.org", "Foo\t\n\\\"", "\"Foo\t\n\\\\\\\"\" <foo@apache.org>", false);
+        parseHeaderTest("<\"@,:;<>.[]()\"@apache.org>", true, "\"@,:;<>.[]()\"@apache.org", null, "<\"@,:;<>.[]()\"@apache.org>", false);
+        parseHeaderTest("<\"\\F\\o\\o\"@apache.org>", true, "\"Foo\"@apache.org", null, "<\"Foo\"@apache.org>", false);
+        parseHeaderErrorTest("\"Foo <foo@apache.org>", true);
+        parseHeaderErrorTest("\"Foo\r\" <foo@apache.org>", true);
+    }
+
+    public void testDomainLiterals() throws Exception {
+        parseHeaderTest("<foo@[apache].org>", true, "foo@[apache].org", null, "<foo@[apache].org>", false);
+        parseHeaderTest("<foo@[@()<>.,:;\"\\\\].org>", true, "foo@[@()<>.,:;\"\\\\].org", null, "<foo@[@()<>.,:;\"\\\\].org>", false);
+        parseHeaderTest("<foo@[\\[\\]].org>", true, "foo@[\\[\\]].org", null, "<foo@[\\[\\]].org>", false);
+        parseHeaderErrorTest("<foo@[[].org>", true);
+        parseHeaderErrorTest("<foo@[foo.org>", true);
+        parseHeaderErrorTest("<foo@[\r].org>", true);
+    }
+
+    public void testComments() throws Exception {
+        parseHeaderTest("Foo Bar (Fred) <foo@apache.org>", true, "foo@apache.org", "Foo Bar (Fred)", "\"Foo Bar (Fred)\" <foo@apache.org>", false);
+        parseHeaderTest("(Fred) foo@apache.org", true, "foo@apache.org", "Fred", "Fred <foo@apache.org>", false);
+        parseHeaderTest("(\\(Fred\\)) foo@apache.org", true, "foo@apache.org", "(Fred)", "\"(Fred)\" <foo@apache.org>", false);
+        parseHeaderTest("(Fred (Jones)) foo@apache.org", true, "foo@apache.org", "Fred (Jones)", "\"Fred (Jones)\" <foo@apache.org>", false);
+        parseHeaderErrorTest("(Fred foo@apache.org", true);
+        parseHeaderErrorTest("(Fred\r) foo@apache.org", true);
+    }
+
+    public void testParseHeader() throws Exception {
+        parseHeaderTest("<@apache.org,@apache.net:foo@apache.org>", false, "@apache.org,@apache.net:foo@apache.org", null, "<@apache.org,@apache.net:foo@apache.org>", false);
+        parseHeaderTest("<@apache.org:foo@apache.org>", false, "@apache.org:foo@apache.org", null, "<@apache.org:foo@apache.org>", false);
+        parseHeaderTest("Foo Bar:;", false, "Foo Bar:;", null, "Foo Bar:;", true);
+        parseHeaderTest("\"\\\"Foo Bar\" <foo.bar@apache.org>", false, "foo.bar@apache.org", "\"Foo Bar", "\"\\\"Foo Bar\" <foo.bar@apache.org>", false);
+        parseHeaderTest("\"Foo Bar\" <foo.bar@apache.org>", false, "foo.bar@apache.org", "Foo Bar",  "Foo Bar <foo.bar@apache.org>", false);
+        parseHeaderTest("(Foo) (Bar) foo.bar@apache.org", false, "foo.bar@apache.org", "Foo", "Foo <foo.bar@apache.org>", false);
+        parseHeaderTest("<foo@apache.org>", false, "foo@apache.org", null, "foo@apache.org", false);
+        parseHeaderTest("Foo Bar <foo.bar@apache.org>", false, "foo.bar@apache.org", "Foo Bar", "Foo Bar <foo.bar@apache.org>", false);
+        parseHeaderTest("foo", false, "foo", null, "foo", false);
+        parseHeaderTest("\"foo\"", false, "\"foo\"", null, "<\"foo\">", false);
+        parseHeaderTest("foo@apache.org", false, "foo@apache.org", null, "foo@apache.org", false);
+        parseHeaderTest("\"foo\"@apache.org", false, "\"foo\"@apache.org", null, "<\"foo\"@apache.org>", false);
+        parseHeaderTest("foo@[apache].org", false, "foo@[apache].org", null, "<foo@[apache].org>", false);
+        parseHeaderTest("foo@[apache].[org]", false, "foo@[apache].[org]", null, "<foo@[apache].[org]>", false);
+        parseHeaderTest("foo.bar@apache.org", false, "foo.bar@apache.org", null, "foo.bar@apache.org", false);
+        parseHeaderTest("(Foo Bar) <foo.bar@apache.org>", false, "foo.bar@apache.org", null, "foo.bar@apache.org", false);
+        parseHeaderTest("(Foo) (Bar) <foo.bar@apache.org>", false, "foo.bar@apache.org", null, "foo.bar@apache.org", false);
+        parseHeaderTest("\"Foo\" Bar <foo.bar@apache.org>", false, "foo.bar@apache.org", "\"Foo\" Bar", "\"\\\"Foo\\\" Bar\" <foo.bar@apache.org>", false);
+        parseHeaderTest("(Foo Bar) foo.bar@apache.org", false, "foo.bar@apache.org", "Foo Bar", "Foo Bar <foo.bar@apache.org>", false);
+        parseHeaderTest("apache.org", false, "apache.org", null, "apache.org", false);
+    }
+
+    public void testValidate() throws Exception {
+        validateTest("@apache.org,@apache.net:foo@apache.org");
+        validateTest("@apache.org:foo@apache.org");
+        validateTest("Foo Bar:;");
+        validateTest("foo.bar@apache.org");
+        validateTest("bar@apache.org");
+        validateTest("foo");
+        validateTest("foo.bar");
+        validateTest("\"foo\"");
+        validateTest("\"foo\"@apache.org");
+        validateTest("foo@[apache].org");
+        validateTest("foo@[apache].[org]");
+    }
+
+    public void testStrictParseHeader() throws Exception {
+        parseHeaderTest("<@apache.org,@apache.net:foo@apache.org>", true, "@apache.org,@apache.net:foo@apache.org", null, "<@apache.org,@apache.net:foo@apache.org>", false);
+        parseHeaderTest("<@apache.org:foo@apache.org>", true, "@apache.org:foo@apache.org", null, "<@apache.org:foo@apache.org>", false);
+        parseHeaderTest("Foo Bar:;", true, "Foo Bar:;", null, "Foo Bar:;", true);
+        parseHeaderTest("\"\\\"Foo Bar\" <foo.bar@apache.org>", true, "foo.bar@apache.org", "\"Foo Bar", "\"\\\"Foo Bar\" <foo.bar@apache.org>", false);
+        parseHeaderTest("\"Foo Bar\" <foo.bar@apache.org>", true, "foo.bar@apache.org", "Foo Bar",  "Foo Bar <foo.bar@apache.org>", false);
+        parseHeaderTest("(Foo) (Bar) foo.bar@apache.org", true, "foo.bar@apache.org", "Foo", "Foo <foo.bar@apache.org>", false);
+        parseHeaderTest("<foo@apache.org>", true, "foo@apache.org", null, "foo@apache.org", false);
+        parseHeaderTest("Foo Bar <foo.bar@apache.org>", true, "foo.bar@apache.org", "Foo Bar", "Foo Bar <foo.bar@apache.org>", false);
+        parseHeaderTest("foo", true, "foo", null, "foo", false);
+        parseHeaderTest("\"foo\"", true, "\"foo\"", null, "<\"foo\">", false);
+        parseHeaderTest("foo@apache.org", true, "foo@apache.org", null, "foo@apache.org", false);
+        parseHeaderTest("\"foo\"@apache.org", true, "\"foo\"@apache.org", null, "<\"foo\"@apache.org>", false);
+        parseHeaderTest("foo@[apache].org", true, "foo@[apache].org", null, "<foo@[apache].org>", false);
+        parseHeaderTest("foo@[apache].[org]", true, "foo@[apache].[org]", null, "<foo@[apache].[org]>", false);
+        parseHeaderTest("foo.bar@apache.org", true, "foo.bar@apache.org", null, "foo.bar@apache.org", false);
+        parseHeaderTest("(Foo Bar) <foo.bar@apache.org>", true, "foo.bar@apache.org", null, "foo.bar@apache.org", false);
+        parseHeaderTest("(Foo) (Bar) <foo.bar@apache.org>", true, "foo.bar@apache.org", null, "foo.bar@apache.org", false);
+        parseHeaderTest("\"Foo\" Bar <foo.bar@apache.org>", true, "foo.bar@apache.org", "\"Foo\" Bar", "\"\\\"Foo\\\" Bar\" <foo.bar@apache.org>", false);
+        parseHeaderTest("(Foo Bar) foo.bar@apache.org", true, "foo.bar@apache.org", "Foo Bar", "Foo Bar <foo.bar@apache.org>", false);
+        parseHeaderTest("apache.org", true, "apache.org", null, "apache.org", false);
+    }
+
+    public void testParse() throws Exception {
+        parseTest("<@apache.org,@apache.net:foo@apache.org>", false, "@apache.org,@apache.net:foo@apache.org", null, "<@apache.org,@apache.net:foo@apache.org>", false);
+        parseTest("<@apache.org:foo@apache.org>", false, "@apache.org:foo@apache.org", null, "<@apache.org:foo@apache.org>", false);
+        parseTest("Foo Bar:;", false, "Foo Bar:;", null, "Foo Bar:;", true);
+        parseTest("\"\\\"Foo Bar\" <foo.bar@apache.org>", false, "foo.bar@apache.org", "\"Foo Bar", "\"\\\"Foo Bar\" <foo.bar@apache.org>", false);
+        parseTest("\"Foo Bar\" <foo.bar@apache.org>", false, "foo.bar@apache.org", "Foo Bar",  "Foo Bar <foo.bar@apache.org>", false);
+        parseTest("(Foo) (Bar) foo.bar@apache.org", false, "foo.bar@apache.org", "Foo", "Foo <foo.bar@apache.org>", false);
+        parseTest("<foo@apache.org>", false, "foo@apache.org", null, "foo@apache.org", false);
+        parseTest("Foo Bar <foo.bar@apache.org>", false, "foo.bar@apache.org", "Foo Bar", "Foo Bar <foo.bar@apache.org>", false);
+        parseTest("foo", false, "foo", null, "foo", false);
+        parseTest("\"foo\"", false, "\"foo\"", null, "<\"foo\">", false);
+        parseTest("foo@apache.org", false, "foo@apache.org", null, "foo@apache.org", false);
+        parseTest("\"foo\"@apache.org", false, "\"foo\"@apache.org", null, "<\"foo\"@apache.org>", false);
+        parseTest("foo@[apache].org", false, "foo@[apache].org", null, "<foo@[apache].org>", false);
+        parseTest("foo@[apache].[org]", false, "foo@[apache].[org]", null, "<foo@[apache].[org]>", false);
+        parseTest("foo.bar@apache.org", false, "foo.bar@apache.org", null, "foo.bar@apache.org", false);
+        parseTest("(Foo Bar) <foo.bar@apache.org>", false, "foo.bar@apache.org", null, "foo.bar@apache.org", false);
+        parseTest("(Foo) (Bar) <foo.bar@apache.org>", false, "foo.bar@apache.org", null, "foo.bar@apache.org", false);
+        parseTest("\"Foo\" Bar <foo.bar@apache.org>", false, "foo.bar@apache.org", "\"Foo\" Bar", "\"\\\"Foo\\\" Bar\" <foo.bar@apache.org>", false);
+        parseTest("(Foo Bar) foo.bar@apache.org", false, "foo.bar@apache.org", "Foo Bar", "Foo Bar <foo.bar@apache.org>", false);
+        parseTest("apache.org", false, "apache.org", null, "apache.org", false);
+    }
+
+    public void testDefaultParse() throws Exception {
+        parseDefaultTest("<@apache.org,@apache.net:foo@apache.org>", "@apache.org,@apache.net:foo@apache.org", null, "<@apache.org,@apache.net:foo@apache.org>", false);
+        parseDefaultTest("<@apache.org:foo@apache.org>", "@apache.org:foo@apache.org", null, "<@apache.org:foo@apache.org>", false);
+        parseDefaultTest("Foo Bar:;", "Foo Bar:;", null, "Foo Bar:;", true);
+        parseDefaultTest("\"\\\"Foo Bar\" <foo.bar@apache.org>", "foo.bar@apache.org", "\"Foo Bar", "\"\\\"Foo Bar\" <foo.bar@apache.org>", false);
+        parseDefaultTest("\"Foo Bar\" <foo.bar@apache.org>", "foo.bar@apache.org", "Foo Bar",  "Foo Bar <foo.bar@apache.org>", false);
+        parseDefaultTest("(Foo) (Bar) foo.bar@apache.org", "foo.bar@apache.org", "Foo", "Foo <foo.bar@apache.org>", false);
+        parseDefaultTest("<foo@apache.org>", "foo@apache.org", null, "foo@apache.org", false);
+        parseDefaultTest("Foo Bar <foo.bar@apache.org>", "foo.bar@apache.org", "Foo Bar", "Foo Bar <foo.bar@apache.org>", false);
+        parseDefaultTest("foo", "foo", null, "foo", false);
+        parseDefaultTest("\"foo\"", "\"foo\"", null, "<\"foo\">", false);
+        parseDefaultTest("foo@apache.org", "foo@apache.org", null, "foo@apache.org", false);
+        parseDefaultTest("\"foo\"@apache.org", "\"foo\"@apache.org", null, "<\"foo\"@apache.org>", false);
+        parseDefaultTest("foo@[apache].org", "foo@[apache].org", null, "<foo@[apache].org>", false);
+        parseDefaultTest("foo@[apache].[org]", "foo@[apache].[org]", null, "<foo@[apache].[org]>", false);
+        parseDefaultTest("foo.bar@apache.org", "foo.bar@apache.org", null, "foo.bar@apache.org", false);
+        parseDefaultTest("(Foo Bar) <foo.bar@apache.org>", "foo.bar@apache.org", null, "foo.bar@apache.org", false);
+        parseDefaultTest("(Foo) (Bar) <foo.bar@apache.org>", "foo.bar@apache.org", null, "foo.bar@apache.org", false);
+        parseDefaultTest("\"Foo\" Bar <foo.bar@apache.org>", "foo.bar@apache.org", "\"Foo\" Bar", "\"\\\"Foo\\\" Bar\" <foo.bar@apache.org>", false);
+        parseDefaultTest("(Foo Bar) foo.bar@apache.org", "foo.bar@apache.org", "Foo Bar", "Foo Bar <foo.bar@apache.org>", false);
+        parseDefaultTest("apache.org", "apache.org", null, "apache.org", false);
+    }
+
+    public void testStrictParse() throws Exception {
+        parseTest("<@apache.org,@apache.net:foo@apache.org>", true, "@apache.org,@apache.net:foo@apache.org", null, "<@apache.org,@apache.net:foo@apache.org>", false);
+        parseTest("<@apache.org:foo@apache.org>", true, "@apache.org:foo@apache.org", null, "<@apache.org:foo@apache.org>", false);
+        parseTest("Foo Bar:;", true, "Foo Bar:;", null, "Foo Bar:;", true);
+        parseTest("\"\\\"Foo Bar\" <foo.bar@apache.org>", true, "foo.bar@apache.org", "\"Foo Bar", "\"\\\"Foo Bar\" <foo.bar@apache.org>", false);
+        parseTest("\"Foo Bar\" <foo.bar@apache.org>", true, "foo.bar@apache.org", "Foo Bar",  "Foo Bar <foo.bar@apache.org>", false);
+        parseTest("(Foo) (Bar) foo.bar@apache.org", true, "foo.bar@apache.org", "Foo", "Foo <foo.bar@apache.org>", false);
+        parseTest("<foo@apache.org>", true, "foo@apache.org", null, "foo@apache.org", false);
+        parseTest("Foo Bar <foo.bar@apache.org>", true, "foo.bar@apache.org", "Foo Bar", "Foo Bar <foo.bar@apache.org>", false);
+        parseTest("foo", true, "foo", null, "foo", false);
+        parseTest("\"foo\"", true, "\"foo\"", null, "<\"foo\">", false);
+        parseTest("foo@apache.org", true, "foo@apache.org", null, "foo@apache.org", false);
+        parseTest("\"foo\"@apache.org", true, "\"foo\"@apache.org", null, "<\"foo\"@apache.org>", false);
+        parseTest("foo@[apache].org", true, "foo@[apache].org", null, "<foo@[apache].org>", false);
+        parseTest("foo@[apache].[org]", true, "foo@[apache].[org]", null, "<foo@[apache].[org]>", false);
+        parseTest("foo.bar@apache.org", true, "foo.bar@apache.org", null, "foo.bar@apache.org", false);
+        parseTest("(Foo Bar) <foo.bar@apache.org>", true, "foo.bar@apache.org", null, "foo.bar@apache.org", false);
+        parseTest("(Foo) (Bar) <foo.bar@apache.org>", true, "foo.bar@apache.org", null, "foo.bar@apache.org", false);
+        parseTest("\"Foo\" Bar <foo.bar@apache.org>", true, "foo.bar@apache.org", "\"Foo\" Bar", "\"\\\"Foo\\\" Bar\" <foo.bar@apache.org>", false);
+        parseTest("(Foo Bar) foo.bar@apache.org", true, "foo.bar@apache.org", "Foo Bar", "Foo Bar <foo.bar@apache.org>", false);
+        parseTest("apache.org", true, "apache.org", null, "apache.org", false);
+    }
+
+    public void testConstructor() throws Exception {
+        constructorTest("(Foo) (Bar) foo.bar@apache.org", false, "foo.bar@apache.org", "Foo", "Foo <foo.bar@apache.org>", false);
+        constructorTest("<@apache.org,@apache.net:foo@apache.org>", false, "@apache.org,@apache.net:foo@apache.org", null, "<@apache.org,@apache.net:foo@apache.org>", false);
+        constructorTest("<@apache.org:foo@apache.org>", false, "@apache.org:foo@apache.org", null, "<@apache.org:foo@apache.org>", false);
+        constructorTest("Foo Bar:;", false, "Foo Bar:;", null, "Foo Bar:;", true);
+        constructorTest("\"\\\"Foo Bar\" <foo.bar@apache.org>", false, "foo.bar@apache.org", "\"Foo Bar", "\"\\\"Foo Bar\" <foo.bar@apache.org>", false);
+        constructorTest("\"Foo Bar\" <foo.bar@apache.org>", false, "foo.bar@apache.org", "Foo Bar",  "Foo Bar <foo.bar@apache.org>", false);
+        constructorTest("<foo@apache.org>", false, "foo@apache.org", null, "foo@apache.org", false);
+        constructorTest("Foo Bar <foo.bar@apache.org>", false, "foo.bar@apache.org", "Foo Bar", "Foo Bar <foo.bar@apache.org>", false);
+        constructorTest("foo", false, "foo", null, "foo", false);
+        constructorTest("\"foo\"", false, "\"foo\"", null, "<\"foo\">", false);
+        constructorTest("foo@apache.org", false, "foo@apache.org", null, "foo@apache.org", false);
+        constructorTest("\"foo\"@apache.org", false, "\"foo\"@apache.org", null, "<\"foo\"@apache.org>", false);
+        constructorTest("foo@[apache].org", false, "foo@[apache].org", null, "<foo@[apache].org>", false);
+        constructorTest("foo@[apache].[org]", false, "foo@[apache].[org]", null, "<foo@[apache].[org]>", false);
+        constructorTest("foo.bar@apache.org", false, "foo.bar@apache.org", null, "foo.bar@apache.org", false);
+        constructorTest("(Foo Bar) <foo.bar@apache.org>", false, "foo.bar@apache.org", null, "foo.bar@apache.org", false);
+        constructorTest("(Foo) (Bar) <foo.bar@apache.org>", false, "foo.bar@apache.org", null, "foo.bar@apache.org", false);
+        constructorTest("\"Foo\" Bar <foo.bar@apache.org>", false, "foo.bar@apache.org", "\"Foo\" Bar", "\"\\\"Foo\\\" Bar\" <foo.bar@apache.org>", false);
+        constructorTest("(Foo Bar) foo.bar@apache.org", false, "foo.bar@apache.org", "Foo Bar", "Foo Bar <foo.bar@apache.org>", false);
+        constructorTest("apache.org", false, "apache.org", null, "apache.org", false);
+    }
+
+    public void testDefaultConstructor() throws Exception {
+        constructorDefaultTest("<@apache.org,@apache.net:foo@apache.org>", "@apache.org,@apache.net:foo@apache.org", null, "<@apache.org,@apache.net:foo@apache.org>", false);
+        constructorDefaultTest("<@apache.org:foo@apache.org>", "@apache.org:foo@apache.org", null, "<@apache.org:foo@apache.org>", false);
+        constructorDefaultTest("Foo Bar:;", "Foo Bar:;", null, "Foo Bar:;", true);
+        constructorDefaultTest("\"\\\"Foo Bar\" <foo.bar@apache.org>", "foo.bar@apache.org", "\"Foo Bar", "\"\\\"Foo Bar\" <foo.bar@apache.org>", false);
+        constructorDefaultTest("\"Foo Bar\" <foo.bar@apache.org>", "foo.bar@apache.org", "Foo Bar",  "Foo Bar <foo.bar@apache.org>", false);
+        constructorDefaultTest("(Foo) (Bar) foo.bar@apache.org", "foo.bar@apache.org", "Foo", "Foo <foo.bar@apache.org>", false);
+        constructorDefaultTest("<foo@apache.org>", "foo@apache.org", null, "foo@apache.org", false);
+        constructorDefaultTest("Foo Bar <foo.bar@apache.org>", "foo.bar@apache.org", "Foo Bar", "Foo Bar <foo.bar@apache.org>", false);
+        constructorDefaultTest("foo", "foo", null, "foo", false);
+        constructorDefaultTest("\"foo\"", "\"foo\"", null, "<\"foo\">", false);
+        constructorDefaultTest("foo@apache.org", "foo@apache.org", null, "foo@apache.org", false);
+        constructorDefaultTest("\"foo\"@apache.org", "\"foo\"@apache.org", null, "<\"foo\"@apache.org>", false);
+        constructorDefaultTest("foo@[apache].org", "foo@[apache].org", null, "<foo@[apache].org>", false);
+        constructorDefaultTest("foo@[apache].[org]", "foo@[apache].[org]", null, "<foo@[apache].[org]>", false);
+        constructorDefaultTest("foo.bar@apache.org", "foo.bar@apache.org", null, "foo.bar@apache.org", false);
+        constructorDefaultTest("(Foo Bar) <foo.bar@apache.org>", "foo.bar@apache.org", null, "foo.bar@apache.org", false);
+        constructorDefaultTest("(Foo) (Bar) <foo.bar@apache.org>", "foo.bar@apache.org", null, "foo.bar@apache.org", false);
+        constructorDefaultTest("\"Foo\" Bar <foo.bar@apache.org>", "foo.bar@apache.org", "\"Foo\" Bar", "\"\\\"Foo\\\" Bar\" <foo.bar@apache.org>", false);
+        constructorDefaultTest("(Foo Bar) foo.bar@apache.org", "foo.bar@apache.org", "Foo Bar", "Foo Bar <foo.bar@apache.org>", false);
+        constructorDefaultTest("apache.org", "apache.org", null, "apache.org", false);
+    }
+
+    public void testStrictConstructor() throws Exception {
+        constructorTest("<@apache.org,@apache.net:foo@apache.org>", true, "@apache.org,@apache.net:foo@apache.org", null, "<@apache.org,@apache.net:foo@apache.org>", false);
+        constructorTest("<@apache.org:foo@apache.org>", true, "@apache.org:foo@apache.org", null, "<@apache.org:foo@apache.org>", false);
+        constructorTest("Foo Bar:;", true, "Foo Bar:;", null, "Foo Bar:;", true);
+        constructorTest("\"\\\"Foo Bar\" <foo.bar@apache.org>", true, "foo.bar@apache.org", "\"Foo Bar", "\"\\\"Foo Bar\" <foo.bar@apache.org>", false);
+        constructorTest("\"Foo Bar\" <foo.bar@apache.org>", true, "foo.bar@apache.org", "Foo Bar",  "Foo Bar <foo.bar@apache.org>", false);
+        constructorTest("(Foo) (Bar) foo.bar@apache.org", true, "foo.bar@apache.org", "Foo", "Foo <foo.bar@apache.org>", false);
+        constructorTest("<foo@apache.org>", true, "foo@apache.org", null, "foo@apache.org", false);
+        constructorTest("Foo Bar <foo.bar@apache.org>", true, "foo.bar@apache.org", "Foo Bar", "Foo Bar <foo.bar@apache.org>", false);
+        constructorTest("foo", true, "foo", null, "foo", false);
+        constructorTest("\"foo\"", true, "\"foo\"", null, "<\"foo\">", false);
+        constructorTest("foo@apache.org", true, "foo@apache.org", null, "foo@apache.org", false);
+        constructorTest("\"foo\"@apache.org", true, "\"foo\"@apache.org", null, "<\"foo\"@apache.org>", false);
+        constructorTest("foo@[apache].org", true, "foo@[apache].org", null, "<foo@[apache].org>", false);
+        constructorTest("foo@[apache].[org]", true, "foo@[apache].[org]", null, "<foo@[apache].[org]>", false);
+        constructorTest("foo.bar@apache.org", true, "foo.bar@apache.org", null, "foo.bar@apache.org", false);
+        constructorTest("(Foo Bar) <foo.bar@apache.org>", true, "foo.bar@apache.org", null, "foo.bar@apache.org", false);
+        constructorTest("(Foo) (Bar) <foo.bar@apache.org>", true, "foo.bar@apache.org", null, "foo.bar@apache.org", false);
+        constructorTest("\"Foo\" Bar <foo.bar@apache.org>", true, "foo.bar@apache.org", "\"Foo\" Bar", "\"\\\"Foo\\\" Bar\" <foo.bar@apache.org>", false);
+        constructorTest("(Foo Bar) foo.bar@apache.org", true, "foo.bar@apache.org", "Foo Bar", "Foo Bar <foo.bar@apache.org>", false);
+        constructorTest("apache.org", true, "apache.org", null, "apache.org", false);
+    }
+
+    public void testParseHeaderList() throws Exception {
+
+        InternetAddress[] addresses = InternetAddress.parseHeader("foo@apache.org,bar@apache.org", true);
+        assertTrue("Expecting 2 addresses", addresses.length == 2);
+        validateAddress(addresses[0], "foo@apache.org", null, "foo@apache.org", false);
+        validateAddress(addresses[1], "bar@apache.org", null, "bar@apache.org", false);
+
+        addresses = InternetAddress.parseHeader("Foo <foo@apache.org>,,Bar <bar@apache.org>", true);
+        assertTrue("Expecting 2 addresses", addresses.length == 2);
+        validateAddress(addresses[0], "foo@apache.org", "Foo", "Foo <foo@apache.org>", false);
+        validateAddress(addresses[1], "bar@apache.org", "Bar", "Bar <bar@apache.org>", false);
+
+        addresses = InternetAddress.parseHeader("foo@apache.org, bar@apache.org", true);
+        assertTrue("Expecting 2 addresses", addresses.length == 2);
+        validateAddress(addresses[0], "foo@apache.org", null, "foo@apache.org", false);
+        validateAddress(addresses[1], "bar@apache.org", null, "bar@apache.org", false);
+
+        addresses = InternetAddress.parseHeader("Foo <foo@apache.org>, Bar <bar@apache.org>", true);
+        assertTrue("Expecting 2 addresses", addresses.length == 2);
+        validateAddress(addresses[0], "foo@apache.org", "Foo", "Foo <foo@apache.org>", false);
+        validateAddress(addresses[1], "bar@apache.org", "Bar", "Bar <bar@apache.org>", false);
+
+
+        addresses = InternetAddress.parseHeader("Foo <foo@apache.org>,(yada),Bar <bar@apache.org>", true);
+        assertTrue("Expecting 2 addresses", addresses.length == 2);
+        validateAddress(addresses[0], "foo@apache.org", "Foo", "Foo <foo@apache.org>", false);
+        validateAddress(addresses[1], "bar@apache.org", "Bar", "Bar <bar@apache.org>", false);
+    }
+
+    public void testParseHeaderErrors() throws Exception {
+        parseHeaderErrorTest("foo@apache.org bar@apache.org", true);
+        parseHeaderErrorTest("Foo foo@apache.org", true);
+        parseHeaderErrorTest("Foo foo@apache.org", true);
+        parseHeaderErrorTest("Foo <foo@apache.org", true);
+        parseHeaderErrorTest("[foo]@apache.org", true);
+        parseHeaderErrorTest("@apache.org", true);
+        parseHeaderErrorTest("foo@[apache.org", true);
+    }
+
+    public void testValidateErrors() throws Exception {
+        validateErrorTest("foo@apache.org bar@apache.org");
+        validateErrorTest("Foo foo@apache.org");
+        validateErrorTest("Foo foo@apache.org");
+        validateErrorTest("Foo <foo@apache.org");
+        validateErrorTest("[foo]@apache.org");
+        validateErrorTest("@apache.org");
+        validateErrorTest("foo@[apache.org");
+    }
+
+    public void testGroup() throws Exception {
+        parseHeaderTest("Foo:foo@apache.org;", true, "Foo:foo@apache.org;", null, "Foo:foo@apache.org;", true);
+        parseHeaderTest("Foo:foo@apache.org,bar@apache.org;", true, "Foo:foo@apache.org,bar@apache.org;", null, "Foo:foo@apache.org,bar@apache.org;", true);
+        parseHeaderTest("Foo Bar:<foo@apache.org>,bar@apache.org;", true, "Foo Bar:<foo@apache.org>,bar@apache.org;", null, "Foo Bar:<foo@apache.org>,bar@apache.org;", true);
+        parseHeaderTest("Foo Bar:Foo <foo@apache.org>,bar@apache.org;", true, "Foo Bar:Foo<foo@apache.org>,bar@apache.org;", null, "Foo Bar:Foo<foo@apache.org>,bar@apache.org;", true);
+        parseHeaderTest("Foo:<foo@apache.org>,,bar@apache.org;", true, "Foo:<foo@apache.org>,,bar@apache.org;", null, "Foo:<foo@apache.org>,,bar@apache.org;", true);
+        parseHeaderTest("Foo:foo,bar;", true, "Foo:foo,bar;", null, "Foo:foo,bar;", true);
+        parseHeaderTest("Foo:;", true, "Foo:;", null, "Foo:;", true);
+        parseHeaderTest("\"Foo\":foo@apache.org;", true, "\"Foo\":foo@apache.org;", null, "\"Foo\":foo@apache.org;", true);
+
+        parseHeaderErrorTest("Foo:foo@apache.org,bar@apache.org", true);
+        parseHeaderErrorTest("Foo:foo@apache.org,Bar:bar@apache.org;;", true);
+        parseHeaderErrorTest(":foo@apache.org;", true);
+        parseHeaderErrorTest("Foo Bar:<foo@apache.org,bar@apache.org;", true);
+    }
+
+    public void testGetGroup() throws Exception {
+        InternetAddress[] addresses = getGroup("Foo:foo@apache.org;", true);
+        assertTrue("Expecting 1 address", addresses.length == 1);
+        validateAddress(addresses[0], "foo@apache.org", null, "foo@apache.org", false);
+
+        addresses = getGroup("Foo:foo@apache.org,bar@apache.org;", true);
+        assertTrue("Expecting 2 addresses", addresses.length == 2);
+        validateAddress(addresses[0], "foo@apache.org", null, "foo@apache.org", false);
+        validateAddress(addresses[1], "bar@apache.org", null, "bar@apache.org", false);
+
+        addresses = getGroup("Foo:<foo@apache.org>,bar@apache.org;", true);
+        assertTrue("Expecting 2 addresses", addresses.length == 2);
+        validateAddress(addresses[0], "foo@apache.org", null, "foo@apache.org", false);
+        validateAddress(addresses[1], "bar@apache.org", null, "bar@apache.org", false);
+
+        addresses = getGroup("Foo:<foo@apache.org>,,bar@apache.org;", true);
+        assertTrue("Expecting 2 addresses", addresses.length == 2);
+        validateAddress(addresses[0], "foo@apache.org", null, "foo@apache.org", false);
+        validateAddress(addresses[1], "bar@apache.org", null, "bar@apache.org", false);
+
+        addresses = getGroup("Foo:Foo <foo@apache.org>,bar@apache.org;", true);
+        assertTrue("Expecting 2 addresses", addresses.length == 2);
+        validateAddress(addresses[0], "foo@apache.org", "Foo", "Foo <foo@apache.org>", false);
+        validateAddress(addresses[1], "bar@apache.org", null, "bar@apache.org", false);
+
+        addresses = getGroup("Foo:Foo <@apache.org:foo@apache.org>,bar@apache.org;", true);
+        assertTrue("Expecting 2 addresses", addresses.length == 2);
+        validateAddress(addresses[0], "@apache.org:foo@apache.org", "Foo", "Foo <@apache.org:foo@apache.org>", false);
+        validateAddress(addresses[1], "bar@apache.org", null, "bar@apache.org", false);
+
+
+        addresses = getGroup("Foo:;", true);
+        assertTrue("Expecting 0 addresses", addresses.length == 0);
+
+        addresses = getGroup("Foo:foo@apache.org;", false);
+        assertTrue("Expecting 1 address", addresses.length == 1);
+        validateAddress(addresses[0], "foo@apache.org", null, "foo@apache.org", false);
+
+        addresses = getGroup("Foo:foo@apache.org,bar@apache.org;", false);
+        assertTrue("Expecting 2 addresses", addresses.length == 2);
+        validateAddress(addresses[0], "foo@apache.org", null, "foo@apache.org", false);
+        validateAddress(addresses[1], "bar@apache.org", null, "bar@apache.org", false);
+
+        addresses = getGroup("Foo:<foo@apache.org>,bar@apache.org;", false);
+        assertTrue("Expecting 2 addresses", addresses.length == 2);
+        validateAddress(addresses[0], "foo@apache.org", null, "foo@apache.org", false);
+        validateAddress(addresses[1], "bar@apache.org", null, "bar@apache.org", false);
+
+        addresses = getGroup("Foo:<foo@apache.org>,,bar@apache.org;", false);
+        assertTrue("Expecting 2 addresses", addresses.length == 2);
+        validateAddress(addresses[0], "foo@apache.org", null, "foo@apache.org", false);
+        validateAddress(addresses[1], "bar@apache.org", null, "bar@apache.org", false);
+
+        addresses = getGroup("Foo:Foo <foo@apache.org>,bar@apache.org;", false);
+        assertTrue("Expecting 2 addresses", addresses.length == 2);
+        validateAddress(addresses[0], "foo@apache.org", "Foo", "Foo <foo@apache.org>", false);
+        validateAddress(addresses[1], "bar@apache.org", null, "bar@apache.org", false);
+
+        addresses = getGroup("Foo:Foo <@apache.org:foo@apache.org>,bar@apache.org;", false);
+        assertTrue("Expecting 2 addresses", addresses.length == 2);
+        validateAddress(addresses[0], "@apache.org:foo@apache.org", "Foo", "Foo <@apache.org:foo@apache.org>", false);
+        validateAddress(addresses[1], "bar@apache.org", null, "bar@apache.org", false);
+
+
+        addresses = getGroup("Foo:;", false);
+        assertTrue("Expecting 0 addresses", addresses.length == 0);
+    }
+
+
+    public void testLocalAddress() throws Exception {
+        System.getProperties().remove("user.name");
+
+        assertNull(InternetAddress.getLocalAddress(null));
+        System.setProperty("user.name", "dev");
+
+        InternetAddress localHost = null;
+        String user = null;
+        String host = null;
+        try {
+            user = System.getProperty("user.name");
+            host = InetAddress.getLocalHost().getHostName();
+
+            localHost = new InternetAddress(user + "@" + host);
+        } catch (final AddressException e) {
+            // ignore
+        } catch (final UnknownHostException e) {
+            // ignore
+        } catch (final SecurityException e) {
+            // ignore
+        }
+
+        assertEquals(InternetAddress.getLocalAddress(null), localHost);
+
+        final Properties props = new Properties();
+        Session session = Session.getInstance(props, null);
+
+        assertEquals(InternetAddress.getLocalAddress(session), localHost);
+
+        props.put("mail.host", "apache.org");
+        session = Session.getInstance(props, null);
+
+        assertEquals(InternetAddress.getLocalAddress(session), new InternetAddress(user + "@apache.org"));
+
+        props.put("mail.user", "user");
+        props.remove("mail.host");
+
+        session = Session.getInstance(props, null);
+        assertEquals(InternetAddress.getLocalAddress(session), new InternetAddress("user@" + host));
+
+        props.put("mail.host", "apache.org");
+        session = Session.getInstance(props, null);
+
+        assertEquals(InternetAddress.getLocalAddress(session), new InternetAddress("user@apache.org"));
+
+        props.put("mail.from", "tester@incubator.apache.org");
+        session = Session.getInstance(props, null);
+
+        assertEquals(InternetAddress.getLocalAddress(session), new InternetAddress("tester@incubator.apache.org"));
+    }
+
+    private InternetAddress[] getGroup(final String address, final boolean strict) throws AddressException
+    {
+        final InternetAddress group = new InternetAddress(address);
+        return group.getGroup(strict);
+    }
+
+
+    @Override
+    protected void setUp() throws Exception {
+        address = new InternetAddress();
+    }
+
+    private void parseHeaderTest(final String address, final boolean strict, final String resultAddr, final String personal, final String toString, final boolean group) throws Exception
+    {
+        final InternetAddress[] addresses = InternetAddress.parseHeader(address, strict);
+        assertTrue(addresses.length == 1);
+        validateAddress(addresses[0], resultAddr, personal, toString, group);
+    }
+
+    private void parseHeaderErrorTest(final String address, final boolean strict) throws Exception
+    {
+        try {
+            InternetAddress.parseHeader(address, strict);
+            fail("Expected AddressException");
+        } catch (final AddressException e) {
+        }
+    }
+
+    private void constructorTest(final String address, final boolean strict, final String resultAddr, final String personal, final String toString, final boolean group) throws Exception
+    {
+        validateAddress(new InternetAddress(address, strict), resultAddr, personal, toString, group);
+    }
+
+    private void constructorDefaultTest(final String address, final String resultAddr, final String personal, final String toString, final boolean group) throws Exception
+    {
+        validateAddress(new InternetAddress(address), resultAddr, personal, toString, group);
+    }
+
+    private void constructorErrorTest(final String address, final boolean strict) throws Exception
+    {
+        try {
+            final InternetAddress foo = new InternetAddress(address, strict);
+            fail("Expected AddressException");
+        } catch (final AddressException e) {
+        }
+    }
+
+    private void parseTest(final String address, final boolean strict, final String resultAddr, final String personal, final String toString, final boolean group) throws Exception
+    {
+        final InternetAddress[] addresses = InternetAddress.parse(address, strict);
+        assertTrue(addresses.length == 1);
+        validateAddress(addresses[0], resultAddr, personal, toString, group);
+    }
+
+    private void parseErrorTest(final String address, final boolean strict) throws Exception
+    {
+        try {
+            InternetAddress.parse(address, strict);
+            fail("Expected AddressException");
+        } catch (final AddressException e) {
+        }
+    }
+
+    private void parseDefaultTest(final String address, final String resultAddr, final String personal, final String toString, final boolean group) throws Exception
+    {
+        final InternetAddress[] addresses = InternetAddress.parse(address);
+        assertTrue(addresses.length == 1);
+        validateAddress(addresses[0], resultAddr, personal, toString, group);
+    }
+
+    private void parseDefaultErrorTest(final String address) throws Exception
+    {
+        try {
+            InternetAddress.parse(address);
+            fail("Expected AddressException");
+        } catch (final AddressException e) {
+        }
+    }
+
+    private void validateTest(final String address) throws Exception {
+        final InternetAddress test = new InternetAddress();
+        test.setAddress(address);
+        test.validate();
+    }
+
+    private void validateErrorTest(final String address) throws Exception {
+        final InternetAddress test = new InternetAddress();
+        test.setAddress(address);
+        try {
+            test.validate();
+            fail("Expected AddressException");
+        } catch (final AddressException e) {
+        }
+    }
+
+
+    private void validateAddress(final InternetAddress a, final String address, final String personal, final String toString, final boolean group)
+    {
+        assertEquals("Invalid address:", a.getAddress(), address);
+        if (personal == null) {
+            assertNull("Personal must be null", a.getPersonal());
+        }
+        else {
+            assertEquals("Invalid Personal:", a.getPersonal(), personal);
+        }
+        assertEquals("Invalid string value:", a.toString(), toString);
+        assertTrue("Incorrect group value:", group == a.isGroup());
+    }
+}

Added: geronimo/specs/trunk/geronimo-javamail_1.5_spec/src/test/java/javax/mail/internet/InternetHeadersTest.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-javamail_1.5_spec/src/test/java/javax/mail/internet/InternetHeadersTest.java?rev=1620683&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-javamail_1.5_spec/src/test/java/javax/mail/internet/InternetHeadersTest.java (added)
+++ geronimo/specs/trunk/geronimo-javamail_1.5_spec/src/test/java/javax/mail/internet/InternetHeadersTest.java Tue Aug 26 18:17:06 2014
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package javax.mail.internet;
+
+import java.io.ByteArrayInputStream;
+
+import javax.mail.MessagingException;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class InternetHeadersTest extends TestCase {
+    private InternetHeaders headers;
+
+    public void testLoadSingleHeader() throws MessagingException {
+        final String stream = "content-type: text/plain\r\n\r\n";
+        headers.load(new ByteArrayInputStream(stream.getBytes()));
+        final String[] header = headers.getHeader("content-type");
+        assertNotNull(header);
+        assertEquals("text/plain", header[0]);
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        headers = new InternetHeaders();
+    }
+}

Added: geronimo/specs/trunk/geronimo-javamail_1.5_spec/src/test/java/javax/mail/internet/MailDateFormatTest.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-javamail_1.5_spec/src/test/java/javax/mail/internet/MailDateFormatTest.java?rev=1620683&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-javamail_1.5_spec/src/test/java/javax/mail/internet/MailDateFormatTest.java (added)
+++ geronimo/specs/trunk/geronimo-javamail_1.5_spec/src/test/java/javax/mail/internet/MailDateFormatTest.java Tue Aug 26 18:17:06 2014
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package javax.mail.internet;
+
+import java.text.ParseException;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Locale;
+import java.util.SimpleTimeZone;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class MailDateFormatTest extends TestCase {
+    public void testMailDateFormat() throws ParseException {
+        final MailDateFormat mdf = new MailDateFormat();
+        Date date = mdf.parse("Wed, 27 Aug 2003 13:43:38 +0100 (BST)");
+        // don't we just love the Date class?
+        Calendar cal = Calendar.getInstance(new SimpleTimeZone(+1 * 60 * 60 * 1000, "BST"), Locale.getDefault());
+        cal.setTime(date);
+        assertEquals(2003, cal.get(Calendar.YEAR));
+        assertEquals(Calendar.AUGUST, cal.get(Calendar.MONTH));
+        assertEquals(27, cal.get(Calendar.DAY_OF_MONTH));
+        assertEquals(Calendar.WEDNESDAY, cal.get(Calendar.DAY_OF_WEEK));
+        assertEquals(13, cal.get(Calendar.HOUR_OF_DAY));
+        assertEquals(43, cal.get(Calendar.MINUTE));
+        assertEquals(38, cal.get(Calendar.SECOND));
+        
+        date = mdf.parse("Wed, 27-Aug-2003 13:43:38 +0100");
+        // don't we just love the Date class?
+        cal = Calendar.getInstance(new SimpleTimeZone(+1 * 60 * 60 * 1000, "BST"), Locale.getDefault());
+        cal.setTime(date);
+        assertEquals(2003, cal.get(Calendar.YEAR));
+        assertEquals(Calendar.AUGUST, cal.get(Calendar.MONTH));
+        assertEquals(27, cal.get(Calendar.DAY_OF_MONTH));
+        assertEquals(Calendar.WEDNESDAY, cal.get(Calendar.DAY_OF_WEEK));
+        assertEquals(13, cal.get(Calendar.HOUR_OF_DAY));
+        assertEquals(43, cal.get(Calendar.MINUTE));
+        assertEquals(38, cal.get(Calendar.SECOND));
+        
+        date = mdf.parse("27-Aug-2003 13:43:38 EST");
+        // don't we just love the Date class?
+        cal = Calendar.getInstance(new SimpleTimeZone(-5 * 60 * 60 * 1000, "EST"), Locale.getDefault());
+        cal.setTime(date);
+        assertEquals(2003, cal.get(Calendar.YEAR));
+        assertEquals(Calendar.AUGUST, cal.get(Calendar.MONTH));
+        assertEquals(27, cal.get(Calendar.DAY_OF_MONTH));
+        assertEquals(Calendar.WEDNESDAY, cal.get(Calendar.DAY_OF_WEEK));
+        assertEquals(13, cal.get(Calendar.HOUR_OF_DAY));
+        assertEquals(43, cal.get(Calendar.MINUTE));
+        assertEquals(38, cal.get(Calendar.SECOND));
+        
+        date = mdf.parse("27 Aug 2003 13:43 EST");
+        // don't we just love the Date class?
+        cal = Calendar.getInstance(new SimpleTimeZone(-5 * 60 * 60 * 1000, "EST"), Locale.getDefault());
+        cal.setTime(date);
+        assertEquals(2003, cal.get(Calendar.YEAR));
+        assertEquals(Calendar.AUGUST, cal.get(Calendar.MONTH));
+        assertEquals(27, cal.get(Calendar.DAY_OF_MONTH));
+        assertEquals(Calendar.WEDNESDAY, cal.get(Calendar.DAY_OF_WEEK));
+        assertEquals(13, cal.get(Calendar.HOUR_OF_DAY));
+        assertEquals(43, cal.get(Calendar.MINUTE));
+        assertEquals(00, cal.get(Calendar.SECOND));
+        
+        date = mdf.parse("27 Aug 03 13:43 EST");
+        // don't we just love the Date class?
+        cal = Calendar.getInstance(new SimpleTimeZone(-5 * 60 * 60 * 1000, "EST"), Locale.getDefault());
+        cal.setTime(date);
+        assertEquals(2003, cal.get(Calendar.YEAR));
+        assertEquals(Calendar.AUGUST, cal.get(Calendar.MONTH));
+        assertEquals(27, cal.get(Calendar.DAY_OF_MONTH));
+        assertEquals(Calendar.WEDNESDAY, cal.get(Calendar.DAY_OF_WEEK));
+        assertEquals(13, cal.get(Calendar.HOUR_OF_DAY));
+        assertEquals(43, cal.get(Calendar.MINUTE));
+        assertEquals(00, cal.get(Calendar.SECOND));
+    }
+}

Added: geronimo/specs/trunk/geronimo-javamail_1.5_spec/src/test/java/javax/mail/internet/MimeBodyPartTest.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-javamail_1.5_spec/src/test/java/javax/mail/internet/MimeBodyPartTest.java?rev=1620683&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-javamail_1.5_spec/src/test/java/javax/mail/internet/MimeBodyPartTest.java (added)
+++ geronimo/specs/trunk/geronimo-javamail_1.5_spec/src/test/java/javax/mail/internet/MimeBodyPartTest.java Tue Aug 26 18:17:06 2014
@@ -0,0 +1,261 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package javax.mail.internet;
+
+import junit.framework.TestCase;
+
+import javax.activation.DataHandler;
+import javax.mail.EncodingAware;
+import javax.mail.MessagingException;
+import javax.mail.Part;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class MimeBodyPartTest extends TestCase {
+
+    File basedir = new File(System.getProperty("basedir", "."));
+    File testInput = new File(basedir, "src/test/resources/test.dat");
+
+    public void testGetSize() throws MessagingException {
+        MimeBodyPart part = new MimeBodyPart();
+        assertEquals(part.getSize(), -1);
+
+        part = new MimeBodyPart(new InternetHeaders(), new byte[] {'a', 'b', 'c'});
+        assertEquals(part.getSize(), 3);
+    }
+
+    public void testGetLineCount() throws MessagingException {
+        MimeBodyPart part = new MimeBodyPart();
+        assertEquals(part.getLineCount(), -1);
+
+        part = new MimeBodyPart(new InternetHeaders(), new byte[] {'a', 'b', 'c'});
+        assertEquals(part.getLineCount(), -1);
+    }
+
+
+    public void testGetContentType() throws MessagingException {
+        MimeBodyPart part = new MimeBodyPart();
+        assertEquals(part.getContentType(), "text/plain");
+
+        part.setHeader("Content-Type", "text/xml");
+        assertEquals(part.getContentType(), "text/xml");
+
+        part = new MimeBodyPart();
+        part.setText("abc");
+        assertEquals(part.getContentType(), "text/plain");
+    }
+
+
+    public void testIsMimeType() throws MessagingException {
+        final MimeBodyPart part = new MimeBodyPart();
+        assertTrue(part.isMimeType("text/plain"));
+        assertTrue(part.isMimeType("text/*"));
+
+        part.setHeader("Content-Type", "text/xml");
+        assertTrue(part.isMimeType("text/xml"));
+        assertTrue(part.isMimeType("text/*"));
+    }
+
+
+    public void testGetDisposition() throws MessagingException {
+        final MimeBodyPart part = new MimeBodyPart();
+        assertNull(part.getDisposition());
+
+        part.setDisposition("inline");
+        assertEquals(part.getDisposition(), "inline");
+    }
+    
+    public void testJavaMail15AttachmentDisposition() throws MessagingException, IOException {
+        final MimeBodyPart part = new MimeBodyPart();
+        assertNull(part.getDisposition());
+        final File testInput = new File(basedir, "src/test/resources/test.dat");
+        part.attachFile(testInput);
+        assertEquals(Part.ATTACHMENT, part.getDisposition());
+    }
+    
+    public void testJavaMail15EncodingAware() throws MessagingException, IOException {
+    	final File testInput = new File(basedir, "src/test/resources/test.dat");
+    	final MimeBodyPart part = new MimeBodyPart();
+        part.attachFile(testInput, "application/octet-stream", "7bit"); // depending on the OS encoding can change
+        part.updateHeaders();
+        assertTrue(part.getDataHandler().getContentType().equals("application/octet-stream"));
+        assertEquals("7bit", part.getEncoding());
+        
+        final MimeBodyPart part2 = new MimeBodyPart();
+        part2.attachFile(testInput,"application/pdf","base64");
+        part2.updateHeaders();
+        assertTrue(part2.getDataHandler().getContentType().equals("application/pdf"));
+        assertEquals("base64", part2.getEncoding());
+    }
+
+
+    public void testSetDescription() throws MessagingException, UnsupportedEncodingException {
+        final MimeBodyPart part = new MimeBodyPart();
+
+        final String simpleSubject = "Yada, yada";
+
+        final String complexSubject = "Yada, yada\u0081";
+
+        final String mungedSubject = "Yada, yada\u003F";
+
+        part.setDescription(simpleSubject);
+        assertEquals(part.getDescription(), simpleSubject);
+
+        part.setDescription(complexSubject, "UTF-8");
+        assertEquals(part.getDescription(), complexSubject);
+        assertEquals(part.getHeader("Content-Description", null), MimeUtility.encodeText(complexSubject, "UTF-8", null));
+
+        part.setDescription(null);
+        assertNull(part.getDescription());
+    }
+
+    public void testSetFileName() throws Exception {
+        final MimeBodyPart part = new MimeBodyPart();
+        part.setFileName("test.dat");
+
+        assertEquals("test.dat", part.getFileName());
+
+        final ContentDisposition disp = new ContentDisposition(part.getHeader("Content-Disposition", null));
+        assertEquals("test.dat", disp.getParameter("filename"));
+
+        final ContentType type = new ContentType(part.getHeader("Content-Type", null));
+        assertEquals("test.dat", type.getParameter("name"));
+
+        final MimeBodyPart part2 = new MimeBodyPart();
+
+        part2.setHeader("Content-Type", type.toString());
+
+        assertEquals("test.dat", part2.getFileName());
+        part2.setHeader("Content-Type", null);
+        part2.setHeader("Content-Disposition", disp.toString());
+        assertEquals("test.dat", part2.getFileName());
+    }
+
+
+    public void testAttachments() throws Exception {
+        MimeBodyPart part = new MimeBodyPart();
+
+        final byte[] testData = getFileData(testInput);
+
+        part.attachFile(testInput);
+        assertEquals(part.getFileName(), testInput.getName());
+
+        part.updateHeaders();
+
+        File temp1 = File.createTempFile("MIME", ".dat");
+        temp1.deleteOnExit();
+
+        part.saveFile(temp1);
+
+        byte[] tempData = getFileData(temp1);
+
+        compareFileData(testData, tempData);
+
+
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+        part.writeTo(out);
+
+        ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
+
+        MimeBodyPart part2 = new MimeBodyPart(in);
+
+        temp1 = File.createTempFile("MIME", ".dat");
+        temp1.deleteOnExit();
+
+        part2.saveFile(temp1);
+
+        tempData = getFileData(temp1);
+
+        compareFileData(testData, tempData);
+
+
+        part = new MimeBodyPart();
+
+        part.attachFile(testInput.getPath());
+        assertEquals(part.getFileName(), testInput.getName());
+
+        part.updateHeaders();
+
+        temp1 = File.createTempFile("MIME", ".dat");
+        temp1.deleteOnExit();
+
+        part.saveFile(temp1.getPath());
+
+        tempData = getFileData(temp1);
+
+        compareFileData(testData, tempData);
+
+        out = new ByteArrayOutputStream();
+        part.writeTo(out);
+
+        in = new ByteArrayInputStream(out.toByteArray());
+
+        part2 = new MimeBodyPart(in);
+
+        temp1 = File.createTempFile("MIME", ".dat");
+        temp1.deleteOnExit();
+
+        part2.saveFile(temp1.getPath());
+
+        tempData = getFileData(temp1);
+
+        compareFileData(testData, tempData);
+    }
+
+    private byte[] getFileData(final File source) throws Exception {
+        final FileInputStream testIn = new FileInputStream(source);
+
+        final byte[] testData = new byte[(int)source.length()];
+
+        testIn.read(testData);
+        testIn.close();
+        return testData;
+    }
+
+    private void compareFileData(final byte[] file1, final byte [] file2) {
+        assertEquals(file1.length, file2.length);
+        for (int i = 0; i < file1.length; i++) {
+            assertEquals(file1[i], file2[i]);
+        }
+    }
+
+
+
+    class TestMimeBodyPart extends MimeBodyPart {
+        public TestMimeBodyPart() {
+            super();
+        }
+
+
+        @Override
+        public void updateHeaders() throws MessagingException {
+            super.updateHeaders();
+        }
+    }
+}
+



Mime
View raw message