geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickmcgu...@apache.org
Subject svn commit: r421852 [14/15] - in /geronimo/specs/trunk: ./ geronimo-spec-j2ee/ geronimo-spec-javamail-1.3.1/ geronimo-spec-javamail-1.3.1/src/ geronimo-spec-javamail-1.4/ geronimo-spec-javamail-1.4/src/ geronimo-spec-javamail-1.4/src/main/ geronimo-spe...
Date Fri, 14 Jul 2006 10:02:29 GMT
Added: geronimo/specs/trunk/geronimo-spec-javamail-1.4/src/test/java/javax/mail/internet/InternetAddressTest.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-spec-javamail-1.4/src/test/java/javax/mail/internet/InternetAddressTest.java?rev=421852&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-spec-javamail-1.4/src/test/java/javax/mail/internet/InternetAddressTest.java (added)
+++ geronimo/specs/trunk/geronimo-spec-javamail-1.4/src/test/java/javax/mail/internet/InternetAddressTest.java Fri Jul 14 03:02:19 2006
@@ -0,0 +1,549 @@
+/**
+ *
+ * Copyright 2003-2006 The Apache Software Foundation
+ *
+ *  Licensed 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 java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.Properties;
+
+import javax.mail.Session;
+/**
+ * @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 (AddressException e) {
+            // ignore
+        } catch (UnknownHostException e) {
+            // ignore
+        } catch (SecurityException e) {
+            // ignore
+        }
+
+        assertEquals(InternetAddress.getLocalAddress(null), localHost);
+
+        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(String address, boolean strict) throws AddressException
+    {
+        InternetAddress group = new InternetAddress(address);
+        return group.getGroup(strict);
+    }
+
+
+    protected void setUp() throws Exception {
+        address = new InternetAddress();
+    }
+
+    private void parseHeaderTest(String address, boolean strict, String resultAddr, String personal, String toString, boolean group) throws Exception
+    {
+        InternetAddress[] addresses = InternetAddress.parseHeader(address, strict);
+        assertTrue(addresses.length == 1);
+        validateAddress(addresses[0], resultAddr, personal, toString, group);
+    }
+
+    private void parseHeaderErrorTest(String address, boolean strict) throws Exception
+    {
+        try {
+            InternetAddress.parseHeader(address, strict);
+            fail("Expected AddressException");
+        } catch (AddressException e) {
+        }
+    }
+
+    private void constructorTest(String address, boolean strict, String resultAddr, String personal, String toString, boolean group) throws Exception
+    {
+        validateAddress(new InternetAddress(address, strict), resultAddr, personal, toString, group);
+    }
+
+    private void constructorDefaultTest(String address, String resultAddr, String personal, String toString, boolean group) throws Exception
+    {
+        validateAddress(new InternetAddress(address), resultAddr, personal, toString, group);
+    }
+
+    private void constructorErrorTest(String address, boolean strict) throws Exception
+    {
+        try {
+            InternetAddress foo = new InternetAddress(address, strict);
+            fail("Expected AddressException");
+        } catch (AddressException e) {
+        }
+    }
+
+    private void parseTest(String address, boolean strict, String resultAddr, String personal, String toString, boolean group) throws Exception
+    {
+        InternetAddress[] addresses = InternetAddress.parse(address, strict);
+        assertTrue(addresses.length == 1);
+        validateAddress(addresses[0], resultAddr, personal, toString, group);
+    }
+
+    private void parseErrorTest(String address, boolean strict) throws Exception
+    {
+        try {
+            InternetAddress.parse(address, strict);
+            fail("Expected AddressException");
+        } catch (AddressException e) {
+        }
+    }
+
+    private void parseDefaultTest(String address, String resultAddr, String personal, String toString, boolean group) throws Exception
+    {
+        InternetAddress[] addresses = InternetAddress.parse(address);
+        assertTrue(addresses.length == 1);
+        validateAddress(addresses[0], resultAddr, personal, toString, group);
+    }
+
+    private void parseDefaultErrorTest(String address) throws Exception
+    {
+        try {
+            InternetAddress.parse(address);
+            fail("Expected AddressException");
+        } catch (AddressException e) {
+        }
+    }
+
+    private void validateTest(String address) throws Exception {
+        InternetAddress test = new InternetAddress();
+        test.setAddress(address);
+        test.validate();
+    }
+
+    private void validateErrorTest(String address) throws Exception {
+        InternetAddress test = new InternetAddress();
+        test.setAddress(address);
+        try {
+            test.validate();
+            fail("Expected AddressException");
+        } catch (AddressException e) {
+        }
+    }
+
+
+    private void validateAddress(InternetAddress a, String address, String personal, String toString, boolean group)
+    {
+//      System.out.println("Testing address \"" + a + "\" against \"" + toString + "\"");
+        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());
+    }
+}

Propchange: geronimo/specs/trunk/geronimo-spec-javamail-1.4/src/test/java/javax/mail/internet/InternetAddressTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/specs/trunk/geronimo-spec-javamail-1.4/src/test/java/javax/mail/internet/InternetAddressTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/specs/trunk/geronimo-spec-javamail-1.4/src/test/java/javax/mail/internet/InternetAddressTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/specs/trunk/geronimo-spec-javamail-1.4/src/test/java/javax/mail/internet/InternetHeadersTest.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-spec-javamail-1.4/src/test/java/javax/mail/internet/InternetHeadersTest.java?rev=421852&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-spec-javamail-1.4/src/test/java/javax/mail/internet/InternetHeadersTest.java (added)
+++ geronimo/specs/trunk/geronimo-spec-javamail-1.4/src/test/java/javax/mail/internet/InternetHeadersTest.java Fri Jul 14 03:02:19 2006
@@ -0,0 +1,48 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation
+ *
+ *  Licensed 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.
+ */
+
+//
+// This source code implements specifications defined by the Java
+// Community Process. In order to remain compliant with the specification
+// DO NOT add / change / or delete method signatures!
+//
+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 {
+        String stream = "content-type: text/plain\r\n\r\n";
+        headers.load(new ByteArrayInputStream(stream.getBytes()));
+        String[] header = headers.getHeader("content-type");
+        assertNotNull(header);
+        assertEquals("text/plain", header[0]);
+    }
+
+    protected void setUp() throws Exception {
+        headers = new InternetHeaders();
+    }
+}

Propchange: geronimo/specs/trunk/geronimo-spec-javamail-1.4/src/test/java/javax/mail/internet/InternetHeadersTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/specs/trunk/geronimo-spec-javamail-1.4/src/test/java/javax/mail/internet/InternetHeadersTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/specs/trunk/geronimo-spec-javamail-1.4/src/test/java/javax/mail/internet/InternetHeadersTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/specs/trunk/geronimo-spec-javamail-1.4/src/test/java/javax/mail/internet/MailDateFormatTest.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-spec-javamail-1.4/src/test/java/javax/mail/internet/MailDateFormatTest.java?rev=421852&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-spec-javamail-1.4/src/test/java/javax/mail/internet/MailDateFormatTest.java (added)
+++ geronimo/specs/trunk/geronimo-spec-javamail-1.4/src/test/java/javax/mail/internet/MailDateFormatTest.java Fri Jul 14 03:02:19 2006
@@ -0,0 +1,46 @@
+/**
+ *
+ * Copyright 2003-2006 The Apache Software Foundation
+ *
+ *  Licensed 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 {
+        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));
+    }
+}

Propchange: geronimo/specs/trunk/geronimo-spec-javamail-1.4/src/test/java/javax/mail/internet/MailDateFormatTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/specs/trunk/geronimo-spec-javamail-1.4/src/test/java/javax/mail/internet/MailDateFormatTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/specs/trunk/geronimo-spec-javamail-1.4/src/test/java/javax/mail/internet/MailDateFormatTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/specs/trunk/geronimo-spec-javamail-1.4/src/test/java/javax/mail/internet/MimeBodyPartTest.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-spec-javamail-1.4/src/test/java/javax/mail/internet/MimeBodyPartTest.java?rev=421852&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-spec-javamail-1.4/src/test/java/javax/mail/internet/MimeBodyPartTest.java (added)
+++ geronimo/specs/trunk/geronimo-spec-javamail-1.4/src/test/java/javax/mail/internet/MimeBodyPartTest.java Fri Jul 14 03:02:19 2006
@@ -0,0 +1,232 @@
+/**
+ *
+ * Copyright 2006 The Apache Software Foundation
+ *
+ *  Licensed 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 java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.UnsupportedEncodingException;
+
+import javax.mail.MessagingException;
+
+import junit.framework.TestCase;
+
+/**
+ * @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 {
+        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 {
+        MimeBodyPart part = new MimeBodyPart();
+        assertNull(part.getDisposition());
+
+        part.setDisposition("inline");
+        assertEquals(part.getDisposition(), "inline");
+    }
+
+
+    public void testSetDescription() throws MessagingException, UnsupportedEncodingException {
+        MimeBodyPart part = new MimeBodyPart();
+
+        String simpleSubject = "Yada, yada";
+
+        String complexSubject = "Yada, yada\u0081";
+
+        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 {
+        MimeBodyPart part = new MimeBodyPart();
+        part.setFileName("test.dat");
+
+        assertEquals("test.dat", part.getFileName());
+
+        ContentDisposition disp = new ContentDisposition(part.getHeader("Content-Disposition", null));
+        assertEquals("test.dat", disp.getParameter("filename"));
+
+        ContentType type = new ContentType(part.getHeader("Content-Type", null));
+        assertEquals("test.dat", type.getParameter("name"));
+
+        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();
+
+        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(File source) throws Exception {
+        FileInputStream testIn = new FileInputStream(source);
+
+        byte[] testData = new byte[(int)source.length()];
+
+        testIn.read(testData);
+        testIn.close();
+        return testData;
+    }
+
+    private void compareFileData(byte[] file1, 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();
+        }
+
+
+        public void updateHeaders() throws MessagingException {
+            super.updateHeaders();
+        }
+    }
+}
+

Propchange: geronimo/specs/trunk/geronimo-spec-javamail-1.4/src/test/java/javax/mail/internet/MimeBodyPartTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/specs/trunk/geronimo-spec-javamail-1.4/src/test/java/javax/mail/internet/MimeBodyPartTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/specs/trunk/geronimo-spec-javamail-1.4/src/test/java/javax/mail/internet/MimeBodyPartTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/specs/trunk/geronimo-spec-javamail-1.4/src/test/java/javax/mail/internet/MimeMessageTest.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-spec-javamail-1.4/src/test/java/javax/mail/internet/MimeMessageTest.java?rev=421852&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-spec-javamail-1.4/src/test/java/javax/mail/internet/MimeMessageTest.java (added)
+++ geronimo/specs/trunk/geronimo-spec-javamail-1.4/src/test/java/javax/mail/internet/MimeMessageTest.java Fri Jul 14 03:02:19 2006
@@ -0,0 +1,419 @@
+/**
+ *
+ * Copyright 2003-2006 The Apache Software Foundation
+ *
+ *  Licensed 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 java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Properties;
+
+import javax.activation.CommandMap;
+import javax.activation.MailcapCommandMap;
+import javax.mail.Address;
+import javax.mail.Message;
+import javax.mail.MessagingException;
+import javax.mail.Session;
+import javax.swing.text.AbstractDocument.Content;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class MimeMessageTest extends TestCase {
+    private CommandMap defaultMap;
+    private Session session;
+
+    public void testWriteTo() throws MessagingException, IOException {
+        MimeMessage msg = new MimeMessage(session);
+        msg.setSender(new InternetAddress("foo"));
+        msg.setHeader("foo", "bar");
+        MimeMultipart mp = new MimeMultipart();
+        MimeBodyPart part1 = new MimeBodyPart();
+        part1.setHeader("foo", "bar");
+        part1.setContent("Hello World", "text/plain");
+        mp.addBodyPart(part1);
+        MimeBodyPart part2 = new MimeBodyPart();
+        part2.setContent("Hello Again", "text/plain");
+        mp.addBodyPart(part2);
+        msg.setContent(mp);
+
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        msg.writeTo(out);
+
+        InputStream in = new ByteArrayInputStream(out.toByteArray());
+
+        MimeMessage newMessage = new MimeMessage(session, in);
+
+        assertEquals(((InternetAddress)newMessage.getSender()).getAddress(), "foo");
+
+        String[] headers = newMessage.getHeader("foo");
+        System.out.println("Get header returned " + headers);
+        assertTrue(headers.length == 1);
+        assertEquals(headers[0], "bar");
+
+
+        newMessage = new MimeMessage(msg);
+
+        assertEquals(((InternetAddress)newMessage.getSender()).getAddress(), "foo");
+        assertEquals(newMessage.getHeader("foo")[0], "bar");
+    }
+
+
+    public void testFrom() throws MessagingException {
+        MimeMessage msg = new MimeMessage(session);
+
+        InternetAddress dev = new InternetAddress("geronimo-dev@apache.org");
+        InternetAddress user = new InternetAddress("geronimo-user@apache.org");
+
+        msg.setSender(dev);
+
+        Address[] from = msg.getFrom();
+        assertTrue(from.length == 1);
+        assertEquals(from[0], dev);
+
+        msg.setFrom(user);
+        from = msg.getFrom();
+        assertTrue(from.length == 1);
+        assertEquals(from[0], user);
+
+        msg.addFrom(new Address[] { dev });
+        from = msg.getFrom();
+        assertTrue(from.length == 2);
+        assertEquals(from[0], user);
+        assertEquals(from[1], dev);
+
+        msg.setFrom();
+        InternetAddress local = InternetAddress.getLocalAddress(session);
+        from = msg.getFrom();
+
+        assertTrue(from.length == 1);
+        assertEquals(local, from[0]);
+
+        msg.setFrom(null);
+        from = msg.getFrom();
+
+        assertTrue(from.length == 1);
+        assertEquals(dev, from[0]);
+
+        msg.setSender(null);
+        from = msg.getFrom();
+        assertNull(from);
+    }
+
+
+    public void testSender() throws MessagingException {
+        MimeMessage msg = new MimeMessage(session);
+
+        InternetAddress dev = new InternetAddress("geronimo-dev@apache.org");
+        InternetAddress user = new InternetAddress("geronimo-user@apache.org");
+
+        msg.setSender(dev);
+
+        Address[] from = msg.getFrom();
+        assertTrue(from.length == 1);
+        assertEquals(from[0], dev);
+
+        assertEquals(msg.getSender(), dev);
+
+        msg.setSender(null);
+        assertNull(msg.getSender());
+    }
+
+    public void testGetAllRecipients() throws MessagingException {
+        MimeMessage msg = new MimeMessage(session);
+
+        InternetAddress dev = new InternetAddress("geronimo-dev@apache.org");
+        InternetAddress user = new InternetAddress("geronimo-user@apache.org");
+        InternetAddress user1 = new InternetAddress("geronimo-user1@apache.org");
+        InternetAddress user2 = new InternetAddress("geronimo-user2@apache.org");
+        NewsAddress group = new NewsAddress("comp.lang.rexx");
+
+        Address[] recipients = msg.getAllRecipients();
+        assertNull(recipients);
+
+        msg.setRecipients(Message.RecipientType.TO, new Address[] { dev });
+
+        recipients = msg.getAllRecipients();
+        assertTrue(recipients.length == 1);
+        assertEquals(recipients[0], dev);
+
+        msg.addRecipients(Message.RecipientType.BCC, new Address[] { user });
+
+        recipients = msg.getAllRecipients();
+        assertTrue(recipients.length == 2);
+        assertEquals(recipients[0], dev);
+        assertEquals(recipients[1], user);
+
+        msg.addRecipients(Message.RecipientType.CC, new Address[] { user1, user2} );
+
+        recipients = msg.getAllRecipients();
+        assertTrue(recipients.length == 4);
+        assertEquals(recipients[0], dev);
+        assertEquals(recipients[1], user1);
+        assertEquals(recipients[2], user2);
+        assertEquals(recipients[3], user);
+
+
+        msg.addRecipients(MimeMessage.RecipientType.NEWSGROUPS, new Address[] { group } );
+
+        recipients = msg.getAllRecipients();
+        assertTrue(recipients.length == 5);
+        assertEquals(recipients[0], dev);
+        assertEquals(recipients[1], user1);
+        assertEquals(recipients[2], user2);
+        assertEquals(recipients[3], user);
+        assertEquals(recipients[4], group);
+
+        msg.setRecipients(Message.RecipientType.CC, (String)null);
+
+        recipients = msg.getAllRecipients();
+
+        System.out.println("Get all recipients returns " + recipients.length);
+        assertTrue(recipients.length == 3);
+        assertEquals(recipients[0], dev);
+        assertEquals(recipients[1], user);
+        assertEquals(recipients[2], group);
+    }
+
+    public void testGetRecipients() throws MessagingException {
+        doRecipientTest(Message.RecipientType.TO);
+        doRecipientTest(Message.RecipientType.CC);
+        doRecipientTest(Message.RecipientType.BCC);
+        doNewsgroupRecipientTest(MimeMessage.RecipientType.NEWSGROUPS);
+    }
+
+    private void doRecipientTest(Message.RecipientType type) throws MessagingException {
+        MimeMessage msg = new MimeMessage(session);
+
+        InternetAddress dev = new InternetAddress("geronimo-dev@apache.org");
+        InternetAddress user = new InternetAddress("geronimo-user@apache.org");
+
+        Address[] recipients = msg.getRecipients(type);
+        assertNull(recipients);
+
+        msg.setRecipients(type, "geronimo-dev@apache.org");
+        recipients = msg.getRecipients(type);
+        assertTrue(recipients.length == 1);
+        assertEquals(recipients[0], dev);
+
+        msg.addRecipients(type, "geronimo-user@apache.org");
+
+        recipients = msg.getRecipients(type);
+        assertTrue(recipients.length == 2);
+        assertEquals(recipients[0], dev);
+        assertEquals(recipients[1], user);
+
+        msg.setRecipients(type, (String)null);
+
+        recipients = msg.getRecipients(type);
+        assertNull(recipients);
+
+        msg.setRecipients(type, new Address[] { dev });
+        recipients = msg.getRecipients(type);
+        assertTrue(recipients.length == 1);
+        assertEquals(recipients[0], dev);
+
+        msg.addRecipients(type, new Address[] { user });
+
+        recipients = msg.getRecipients(type);
+        assertTrue(recipients.length == 2);
+        assertEquals(recipients[0], dev);
+        assertEquals(recipients[1], user);
+
+        msg.setRecipients(type, (Address[])null);
+
+        recipients = msg.getRecipients(type);
+        assertNull(recipients);
+
+        msg.setRecipients(type, new Address[] { dev, user });
+
+        recipients = msg.getRecipients(type);
+        assertTrue(recipients.length == 2);
+        assertEquals(recipients[0], dev);
+        assertEquals(recipients[1], user);
+    }
+
+
+    private void doNewsgroupRecipientTest(Message.RecipientType type) throws MessagingException {
+        MimeMessage msg = new MimeMessage(session);
+
+        Address dev = new NewsAddress("geronimo-dev");
+        Address user = new NewsAddress("geronimo-user");
+
+        Address[] recipients = msg.getRecipients(type);
+        assertNull(recipients);
+
+        msg.setRecipients(type, "geronimo-dev");
+        recipients = msg.getRecipients(type);
+        assertTrue(recipients.length == 1);
+        System.out.println("Received address " + recipients[0] + " of type " + recipients[0].getType());
+        assertEquals(recipients[0], dev);
+
+        msg.addRecipients(type, "geronimo-user");
+
+        recipients = msg.getRecipients(type);
+        assertTrue(recipients.length == 2);
+        assertEquals(recipients[0], dev);
+        assertEquals(recipients[1], user);
+
+        msg.setRecipients(type, (String)null);
+
+        recipients = msg.getRecipients(type);
+        assertNull(recipients);
+
+        msg.setRecipients(type, new Address[] { dev });
+        recipients = msg.getRecipients(type);
+        assertTrue(recipients.length == 1);
+        assertEquals(recipients[0], dev);
+
+        msg.addRecipients(type, new Address[] { user });
+
+        recipients = msg.getRecipients(type);
+        assertTrue(recipients.length == 2);
+        assertEquals(recipients[0], dev);
+        assertEquals(recipients[1], user);
+
+        msg.setRecipients(type, (Address[])null);
+
+        recipients = msg.getRecipients(type);
+        assertNull(recipients);
+
+        msg.setRecipients(type, new Address[] { dev, user });
+
+        recipients = msg.getRecipients(type);
+        assertTrue(recipients.length == 2);
+        assertEquals(recipients[0], dev);
+        assertEquals(recipients[1], user);
+    }
+
+    public void testReplyTo() throws MessagingException {
+        MimeMessage msg = new MimeMessage(session);
+
+        InternetAddress dev = new InternetAddress("geronimo-dev@apache.org");
+        InternetAddress user = new InternetAddress("geronimo-user@apache.org");
+
+        msg.setReplyTo(new Address[] { dev });
+
+        Address[] recipients = msg.getReplyTo();
+        assertTrue(recipients.length == 1);
+        assertEquals(recipients[0], dev);
+
+        msg.setReplyTo(new Address[] { dev, user });
+
+        recipients = msg.getReplyTo();
+        assertTrue(recipients.length == 2);
+        assertEquals(recipients[0], dev);
+        assertEquals(recipients[1], user);
+
+        msg.setReplyTo(null);
+
+        recipients = msg.getReplyTo();
+        assertNull(recipients);
+    }
+
+
+    public void testSetSubject() throws MessagingException {
+        MimeMessage msg = new MimeMessage(session);
+
+        String simpleSubject = "Yada, yada";
+
+        String complexSubject = "Yada, yada\u0081";
+
+        String mungedSubject = "Yada, yada\u003F";
+
+        msg.setSubject(simpleSubject);
+        assertEquals(msg.getSubject(), simpleSubject);
+
+        msg.setSubject(complexSubject, "UTF-8");
+        assertEquals(msg.getSubject(), complexSubject);
+
+        msg.setSubject(null);
+        assertNull(msg.getSubject());
+    }
+
+
+    public void testSetDescription() throws MessagingException {
+        MimeMessage msg = new MimeMessage(session);
+
+        String simpleSubject = "Yada, yada";
+
+        String complexSubject = "Yada, yada\u0081";
+
+        String mungedSubject = "Yada, yada\u003F";
+
+        msg.setDescription(simpleSubject);
+        assertEquals(msg.getDescription(), simpleSubject);
+
+        msg.setDescription(complexSubject, "UTF-8");
+        assertEquals(msg.getDescription(), complexSubject);
+
+        msg.setDescription(null);
+        assertNull(msg.getDescription());
+    }
+
+
+    public void testGetContentType() throws MessagingException {
+        MimeMessage msg = new MimeMessage(session);
+        assertEquals(msg.getContentType(), "text/plain");
+
+        msg.setHeader("Content-Type", "text/xml");
+        assertEquals(msg.getContentType(), "text/xml");
+    }
+
+
+    public void testSetText() throws MessagingException {
+        MimeMessage msg = new MimeMessage(session);
+
+        msg.setText("Yada, yada");
+        msg.saveChanges();
+        ContentType type = new ContentType(msg.getContentType());
+        assertTrue(type.match("text/plain"));
+
+        msg = new MimeMessage(session);
+        msg.setText("Yada, yada", "UTF-8");
+        msg.saveChanges();
+        type = new ContentType(msg.getContentType());
+        assertTrue(type.match("text/plain"));
+        assertEquals(type.getParameter("charset"), "UTF-8");
+
+        msg = new MimeMessage(session);
+        msg.setText("Yada, yada", "UTF-8", "xml");
+        msg.saveChanges();
+        type = new ContentType(msg.getContentType());
+        assertTrue(type.match("text/xml"));
+        assertEquals(type.getParameter("charset"), "UTF-8");
+    }
+
+
+
+    protected void setUp() throws Exception {
+        defaultMap = CommandMap.getDefaultCommandMap();
+        MailcapCommandMap myMap = new MailcapCommandMap();
+        myMap.addMailcap("text/plain;;    x-java-content-handler=" + MimeMultipartTest.DummyTextHandler.class.getName());
+        myMap.addMailcap("multipart/*;;    x-java-content-handler=" + MimeMultipartTest.DummyMultipartHandler.class.getName());
+        CommandMap.setDefaultCommandMap(myMap);
+        session = Session.getDefaultInstance(new Properties());
+    }
+
+    protected void tearDown() throws Exception {
+        CommandMap.setDefaultCommandMap(defaultMap);
+    }
+}

Propchange: geronimo/specs/trunk/geronimo-spec-javamail-1.4/src/test/java/javax/mail/internet/MimeMessageTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/specs/trunk/geronimo-spec-javamail-1.4/src/test/java/javax/mail/internet/MimeMessageTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/specs/trunk/geronimo-spec-javamail-1.4/src/test/java/javax/mail/internet/MimeMessageTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/specs/trunk/geronimo-spec-javamail-1.4/src/test/java/javax/mail/internet/MimeMultipartTest.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-spec-javamail-1.4/src/test/java/javax/mail/internet/MimeMultipartTest.java?rev=421852&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-spec-javamail-1.4/src/test/java/javax/mail/internet/MimeMultipartTest.java (added)
+++ geronimo/specs/trunk/geronimo-spec-javamail-1.4/src/test/java/javax/mail/internet/MimeMultipartTest.java Fri Jul 14 03:02:19 2006
@@ -0,0 +1,153 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation
+ *
+ *  Licensed 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.
+ */
+
+//
+// This source code implements specifications defined by the Java
+// Community Process. In order to remain compliant with the specification
+// DO NOT add / change / or delete method signatures!
+//
+package javax.mail.internet;
+
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.UnsupportedFlavorException;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.util.Properties;
+import javax.mail.BodyPart;
+import javax.mail.MessagingException;
+import javax.mail.Session;
+import javax.mail.Message;
+import javax.activation.CommandMap;
+import javax.activation.MailcapCommandMap;
+import javax.activation.DataContentHandler;
+import javax.activation.DataSource;
+import javax.activation.DataHandler;
+import javax.activation.FileDataSource;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class MimeMultipartTest extends TestCase {
+    private CommandMap defaultMap;
+
+    public void testWriteTo() throws MessagingException, IOException, Exception {
+        writeToSetUp();
+
+        MimeMultipart mp = new MimeMultipart();
+        MimeBodyPart part1 = new MimeBodyPart();
+        part1.setHeader("foo", "bar");
+        part1.setContent("Hello World", "text/plain");
+        mp.addBodyPart(part1);
+        MimeBodyPart part2 = new MimeBodyPart();
+        part2.setContent("Hello Again", "text/plain");
+        mp.addBodyPart(part2);
+        mp.writeTo(System.out);
+
+        writeToTearDown();
+    }
+
+    public void testPreamble() throws MessagingException, IOException {
+        Properties props = new Properties();
+        Session session = Session.getDefaultInstance(props);
+        session.setDebug(true);
+        MimeMessage message = new MimeMessage(session);
+        message.setFrom(new InternetAddress("rickmcg@gmail.com"));
+        message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("rick@us.ibm.com"));
+        message.setSubject("test subject");
+
+        BodyPart messageBodyPart1 = new MimeBodyPart();
+        messageBodyPart1.setHeader("Content-Type", "text/xml");
+        messageBodyPart1.setHeader("Content-Transfer-Encoding", "binary");
+        messageBodyPart1.setText("This is a test");
+
+        MimeMultipart multipart = new MimeMultipart();
+        multipart.addBodyPart(messageBodyPart1);
+        multipart.setPreamble("This is a preamble");
+
+        assertEquals("This is a preamble", multipart.getPreamble());
+
+        message.setContent(multipart);
+
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+        message.writeTo(out);
+        out.writeTo(System.out);
+
+        ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
+
+        MimeMessage newMessage = new MimeMessage(session, in);
+        assertEquals("This is a preamble\r\n", ((MimeMultipart)newMessage.getContent()).getPreamble());
+    }
+
+    protected void writeToSetUp() throws Exception {
+        defaultMap = CommandMap.getDefaultCommandMap();
+        MailcapCommandMap myMap = new MailcapCommandMap();
+        myMap.addMailcap("text/plain;;    x-java-content-handler=" + DummyTextHandler.class.getName());
+        myMap.addMailcap("multipart/*;;    x-java-content-handler=" + DummyMultipartHandler.class.getName());
+        CommandMap.setDefaultCommandMap(myMap);
+    }
+
+    protected void writeToTearDown() throws Exception {
+        CommandMap.setDefaultCommandMap(defaultMap);
+    }
+
+    public static class DummyTextHandler implements DataContentHandler {
+        public DataFlavor[] getTransferDataFlavors() {
+            return new DataFlavor[0];  //To change body of implemented methods use File | Settings | File Templates.
+        }
+
+        public Object getTransferData(DataFlavor df, DataSource ds) throws UnsupportedFlavorException, IOException {
+            return null;  //To change body of implemented methods use File | Settings | File Templates.
+        }
+
+        public Object getContent(DataSource ds) throws IOException {
+            return null;  //To change body of implemented methods use File | Settings | File Templates.
+        }
+
+        public void writeTo(Object obj, String mimeType, OutputStream os) throws IOException {
+            os.write(((String)obj).getBytes());
+        }
+    }
+
+    public static class DummyMultipartHandler implements DataContentHandler {
+        public DataFlavor[] getTransferDataFlavors() {
+            throw new UnsupportedOperationException();
+        }
+
+        public Object getTransferData(DataFlavor df, DataSource ds) throws UnsupportedFlavorException, IOException {
+            throw new UnsupportedOperationException();
+        }
+
+        public Object getContent(DataSource ds) throws IOException {
+            throw new UnsupportedOperationException();
+        }
+
+        public void writeTo(Object obj, String mimeType, OutputStream os) throws IOException {
+            MimeMultipart mp = (MimeMultipart) obj;
+            try {
+                mp.writeTo(os);
+            } catch (MessagingException e) {
+                throw (IOException) new IOException(e.getMessage()).initCause(e);
+            }
+        }
+    }
+}

Propchange: geronimo/specs/trunk/geronimo-spec-javamail-1.4/src/test/java/javax/mail/internet/MimeMultipartTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/specs/trunk/geronimo-spec-javamail-1.4/src/test/java/javax/mail/internet/MimeMultipartTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/specs/trunk/geronimo-spec-javamail-1.4/src/test/java/javax/mail/internet/MimeMultipartTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/specs/trunk/geronimo-spec-javamail-1.4/src/test/java/javax/mail/internet/MimeTest.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-spec-javamail-1.4/src/test/java/javax/mail/internet/MimeTest.java?rev=421852&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-spec-javamail-1.4/src/test/java/javax/mail/internet/MimeTest.java (added)
+++ geronimo/specs/trunk/geronimo-spec-javamail-1.4/src/test/java/javax/mail/internet/MimeTest.java Fri Jul 14 03:02:19 2006
@@ -0,0 +1,121 @@
+/**
+ *
+ * Copyright 2003-2006 The Apache Software Foundation
+ *
+ *  Licensed 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 java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Properties;
+
+import javax.activation.DataHandler;
+import javax.activation.DataSource;
+import javax.mail.Session;
+
+import junit.framework.TestCase;
+
+public class MimeTest extends TestCase {
+
+    public void testWriteRead() throws Exception {
+        Session session = Session.getDefaultInstance(new Properties(), null);
+        MimeMessage mime = new MimeMessage(session);
+        MimeMultipart parts = new MimeMultipart("related; type=\"text/xml\"; start=\"<xml>\"");
+        MimeBodyPart xmlPart = new MimeBodyPart();
+        xmlPart.setContentID("<xml>");
+        xmlPart.setDataHandler(new DataHandler(new ByteArrayDataSource("<hello/>".getBytes(), "text/xml")));
+        parts.addBodyPart(xmlPart);
+        MimeBodyPart jpegPart = new MimeBodyPart();
+        jpegPart.setContentID("<jpeg>");
+        jpegPart.setDataHandler(new DataHandler(new ByteArrayDataSource(new byte[] { 0, 1, 2, 3, 4, 5 }, "image/jpeg")));
+        parts.addBodyPart(jpegPart);
+        mime.setContent(parts);
+        mime.setHeader("Content-Type", parts.getContentType());
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        mime.writeTo(baos);
+
+        System.out.println(baos);
+
+        MimeMessage mime2 = new MimeMessage(session, new ByteArrayInputStream(baos.toByteArray()));
+        assertTrue(mime2.getContent() instanceof MimeMultipart);
+        MimeMultipart parts2 = (MimeMultipart) mime2.getContent();
+        assertEquals(mime.getContentType(), mime2.getContentType());
+        assertEquals(parts.getCount(), parts2.getCount());
+        assertTrue(parts2.getBodyPart(0) instanceof MimeBodyPart);
+        assertTrue(parts2.getBodyPart(1) instanceof MimeBodyPart);
+
+        MimeBodyPart xmlPart2 = (MimeBodyPart) parts2.getBodyPart(0);
+        assertEquals(xmlPart.getContentID(), xmlPart2.getContentID());
+        ByteArrayOutputStream xmlBaos = new ByteArrayOutputStream();
+        copyInputStream(xmlPart.getDataHandler().getInputStream(), xmlBaos);
+        ByteArrayOutputStream xmlBaos2 = new ByteArrayOutputStream();
+        copyInputStream(xmlPart2.getDataHandler().getInputStream(), xmlBaos2);
+        assertEquals(xmlBaos.toString(), xmlBaos2.toString());
+
+        MimeBodyPart jpegPart2 = (MimeBodyPart) parts2.getBodyPart(1);
+        assertEquals(jpegPart.getContentID(), jpegPart2.getContentID());
+        ByteArrayOutputStream jpegBaos = new ByteArrayOutputStream();
+        copyInputStream(jpegPart.getDataHandler().getInputStream(), jpegBaos);
+        ByteArrayOutputStream jpegBaos2 = new ByteArrayOutputStream();
+        copyInputStream(jpegPart2.getDataHandler().getInputStream(), jpegBaos2);
+        assertEquals(jpegBaos.toString(), jpegBaos2.toString());
+    }
+
+    public static class ByteArrayDataSource implements DataSource {
+        private byte[] data;
+        private String type;
+        private String name = "unused";
+
+        public ByteArrayDataSource(byte[] data, String type) {
+            this.data = data;
+            this.type = type;
+        }
+
+        public InputStream getInputStream() throws IOException {
+            if (data == null) throw new IOException("no data");
+            return new ByteArrayInputStream(data);
+        }
+
+        public OutputStream getOutputStream() throws IOException {
+            throw new IOException("getOutputStream() not supported");
+        }
+
+        public String getContentType() {
+            return type;
+        }
+
+        public String getName() {
+            return name;
+        }
+
+        public void setName(String name) {
+            this.name = name;
+        }
+    }
+
+    public static void copyInputStream(InputStream in, OutputStream out) throws IOException {
+        byte[] buffer = new byte[1024];
+        int len;
+        while ((len = in.read(buffer)) >= 0) {
+            out.write(buffer, 0, len);
+        }
+        in.close();
+        out.close();
+    }
+}

Propchange: geronimo/specs/trunk/geronimo-spec-javamail-1.4/src/test/java/javax/mail/internet/MimeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/specs/trunk/geronimo-spec-javamail-1.4/src/test/java/javax/mail/internet/MimeTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/specs/trunk/geronimo-spec-javamail-1.4/src/test/java/javax/mail/internet/MimeTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/specs/trunk/geronimo-spec-javamail-1.4/src/test/java/javax/mail/internet/MimeUtilityTest.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-spec-javamail-1.4/src/test/java/javax/mail/internet/MimeUtilityTest.java?rev=421852&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-spec-javamail-1.4/src/test/java/javax/mail/internet/MimeUtilityTest.java (added)
+++ geronimo/specs/trunk/geronimo-spec-javamail-1.4/src/test/java/javax/mail/internet/MimeUtilityTest.java Fri Jul 14 03:02:19 2006
@@ -0,0 +1,174 @@
+/**
+ *
+ * Copyright 2006 The Apache Software Foundation
+ *
+ *  Licensed 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 java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Properties;
+
+import javax.activation.DataHandler;
+import javax.activation.DataSource;
+import javax.mail.Session;
+import javax.mail.util.ByteArrayDataSource;
+
+import junit.framework.TestCase;
+
+public class MimeUtilityTest extends TestCase {
+
+    public void testEncodeDecode() throws Exception {
+
+        byte [] data = new byte[256];
+        for (int i = 0; i < data.length; i++) {
+            data[i] = (byte)i;
+        }
+
+        // different lengths test boundary conditions
+        doEncodingTest(data, 256, "uuencode");
+        doEncodingTest(data, 255, "uuencode");
+        doEncodingTest(data, 254, "uuencode");
+
+        doEncodingTest(data, 256, "binary");
+        doEncodingTest(data, 256, "7bit");
+        doEncodingTest(data, 256, "8bit");
+        doEncodingTest(data, 256, "base64");
+        doEncodingTest(data, 255, "base64");
+        doEncodingTest(data, 254, "base64");
+
+        doEncodingTest(data, 256, "x-uuencode");
+        doEncodingTest(data, 256, "x-uue");
+        doEncodingTest(data, 256, "quoted-printable");
+        doEncodingTest(data, 255, "quoted-printable");
+        doEncodingTest(data, 254, "quoted-printable");
+    }
+
+
+    public void testFoldUnfold() throws Exception {
+        doFoldTest(0, "This is a short string", "This is a short string");
+        doFoldTest(0, "The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog.",
+            "The quick brown fox jumped over the lazy dog. The quick brown fox jumped\r\n over the lazy dog. The quick brown fox jumped over the lazy dog.");
+        doFoldTest(50, "The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog.",
+            "The quick brown fox jumped\r\n over the lazy dog. The quick brown fox jumped over the lazy dog. The quick\r\n brown fox jumped over the lazy dog.");
+        doFoldTest(20, "======================================================================================================================= break should be here",
+            "=======================================================================================================================\r\n break should be here");
+    }
+
+
+    public void doEncodingTest(byte[] data, int length, String encoding) throws Exception {
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        OutputStream encoder = MimeUtility.encode(out, encoding);
+
+        encoder.write(data, 0, length);
+        encoder.flush();
+
+        byte[] encodedData = out.toByteArray();
+
+        ByteArrayInputStream in = new ByteArrayInputStream(encodedData);
+
+        InputStream decoder = MimeUtility.decode(in, encoding);
+
+        byte[] decodedData = new byte[length];
+
+        int count = decoder.read(decodedData);
+
+        assertEquals(length, count);
+
+        for (int i = 0; i < length; i++) {
+            assertEquals(data[i], decodedData[i]);
+        }
+    }
+
+
+    public void doFoldTest(int used, String source, String folded) throws Exception {
+        String newFolded = MimeUtility.fold(used, source);
+        String newUnfolded = MimeUtility.unfold(newFolded);
+
+        assertEquals(folded, newFolded);
+        assertEquals(source, newUnfolded);
+    }
+
+
+    public void testEncodeWord() throws Exception {
+        assertEquals("abc", MimeUtility.encodeWord("abc"));
+        // default code page dependent, hard to directly test the encoded results
+        assertEquals(" hé! àèôu !!!", MimeUtility.decodeWord(MimeUtility.encodeWord(" hé! àèôu !!!")));
+
+        String encoded = MimeUtility.encodeWord(" hé! àèôu !!!", "UTF-8", "Q");
+        assertEquals("=?UTF-8?Q?_h=C3=A9!_=C3=A0=C3=A8=C3=B4u_!!!?=", encoded);
+        assertEquals(" hé! àèôu !!!", MimeUtility.decodeWord(encoded));
+
+        encoded = MimeUtility.encodeWord(" hé! àèôu !!!", "UTF-8", "B");
+        assertEquals("=?UTF-8?B?IGjDqSEgw6DDqMO0dSAhISE=?=", encoded);
+        assertEquals(" hé! àèôu !!!", MimeUtility.decodeWord(encoded));
+    }
+
+
+    public void testEncodeText() throws Exception {
+        assertEquals("abc", MimeUtility.encodeWord("abc"));
+        // default code page dependent, hard to directly test the encoded results
+        assertEquals(" hé! àèôu !!!", MimeUtility.decodeText(MimeUtility.encodeText(" hé! àèôu !!!")));
+
+        String encoded = MimeUtility.encodeText(" hé! àèôu !!!", "UTF-8", "Q");
+        assertEquals("=?UTF-8?Q?_h=C3=A9!_=C3=A0=C3=A8=C3=B4u_!!!?=", encoded);
+        assertEquals(" hé! àèôu !!!", MimeUtility.decodeText(encoded));
+
+        encoded = MimeUtility.encodeText(" hé! àèôu !!!", "UTF-8", "B");
+        assertEquals("=?UTF-8?B?IGjDqSEgw6DDqMO0dSAhISE=?=", encoded);
+        assertEquals(" hé! àèôu !!!", MimeUtility.decodeText(encoded));
+    }
+
+
+    public void testGetEncoding() throws Exception {
+        ByteArrayDataSource source = new ByteArrayDataSource(new byte[] { 'a', 'b', 'c'}, "text/plain");
+
+        assertEquals("7bit", MimeUtility.getEncoding(source));
+
+        source = new ByteArrayDataSource(new byte[] { 'a', 'b', (byte)0x81}, "text/plain");
+
+        assertEquals("quoted-printable", MimeUtility.getEncoding(source));
+
+        source = new ByteArrayDataSource(new byte[] { 'a', (byte)0x82, (byte)0x81}, "text/plain");
+
+        assertEquals("base64", MimeUtility.getEncoding(source));
+
+
+        source = new ByteArrayDataSource(new byte[] { 'a', 'b', 'c'}, "application/binary");
+
+        assertEquals("7bit", MimeUtility.getEncoding(source));
+
+        source = new ByteArrayDataSource(new byte[] { 'a', 'b', (byte)0x81}, "application/binary");
+
+        assertEquals("base64", MimeUtility.getEncoding(source));
+
+        source = new ByteArrayDataSource(new byte[] { 'a', (byte)0x82, (byte)0x81}, "application/binary");
+
+        assertEquals("base64", MimeUtility.getEncoding(source));
+    }
+
+
+    public void testQuote() throws Exception {
+        assertEquals("abc", MimeUtility.quote("abc", "&*%"));
+        assertEquals("\"abc&\"", MimeUtility.quote("abc&", "&*%"));
+        assertEquals("\"abc\\\"\"", MimeUtility.quote("abc\"", "&*%"));
+        assertEquals("\"abc\\\\\"", MimeUtility.quote("abc\\", "&*%"));
+        assertEquals("\"abc\\\r\"", MimeUtility.quote("abc\r", "&*%"));
+        assertEquals("\"abc\\\n\"", MimeUtility.quote("abc\n", "&*%"));
+    }
+}



Mime
View raw message