commits@javamail.java.net

[javamail~mercurial:248] Fix use of deprecated getBytes method.

From: <shannon_at_kenai.com>
Date: Tue, 19 Jan 2010 18:22:55 +0000

Project: javamail
Repository: mercurial
Revision: 248
Author: shannon
Date: 2010-01-16 01:36:36 UTC
Link:

Log Message:
------------
Make blockSize static to eliminate FindBugs complaint.
Convert parameterized tests to JUnit 4.
Convert MimeMultipart parsing test to JUnit.
Convert MimeUtility fold/unfold test to JUnit.
Convert SearchTerm serialization test to JUnit.
Convert BASE64 test to JUnit.
Commit removes of old tests (forgotten from previous commits).
Convert HeaderTokenizer test to JUnit; update corresponding test cases.
Convert more ParameterList tests to JUnit.
Add file cache support to POP3 provider.
Add mail.mime.ignorewhitespacelines System property.
MailHandler updates from Jason:

MailHandler missing throws ISE for setPushFilter doc.
MailHandler typo in setAuthenticator doc.
MailHandler error manager example didn't work with empty string.
MailHandler split up init method into smaller methods.
MailHandler split push method so email send happens outside of lock.
MailHandler improve capacity management of the internal buffer.
MailHandler check class type with expected type when creating new objects.
MailHandler fixed null attachment name.

MailHandlerTest fixed null pointer in isLoggableTest.
MailHandlerTest added test for bad config file.
MailHandlerTest swapped the expected and result params.
MailHandlerTest more testing of raw emails.

SummaryNameFormatter ext from handler fixes.
Convert to new sigtest tool, still Sun-internal only.
Make TempFile private to the con.sun.mail.pop3 package.
Once again, suppress noise from MailHandlerTest.
Handle CAPA command in POP3StoreTest.
Add support for IMAP UNSELECT command.
Fix use of deprecated getBytes method.


Revisions:
----------
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248


Modified Paths:
---------------
mail/src/main/java/com/sun/mail/auth/MD4.java
mail/src/test/java/com/sun/mail/util/UUDecoderStreamTest.java
mail/src/test/java/javax/mail/internet/InternetAddressTest.java
mail/src/test/java/javax/mail/internet/ParameterListTestSuite.java
doc/release/CHANGES.txt
mail/src/main/java/com/sun/mail/pop3/POP3Folder.java
mail/src/main/java/com/sun/mail/pop3/POP3Message.java
mail/src/main/java/com/sun/mail/pop3/POP3Store.java
mail/src/main/java/com/sun/mail/pop3/Protocol.java
mail/src/main/java/com/sun/mail/pop3/package.html
mail/src/main/java/javax/mail/internet/InternetHeaders.java
mail/src/main/java/javax/mail/internet/package.html
logging/src/main/java/MailHandlerDemo.java
logging/src/main/java/SummaryNameFormatter.java
mail/src/main/java/com/sun/mail/util/logging/MailHandler.java
mail/src/test/java/com/sun/mail/util/logging/MailHandlerTest.java
mail.sig
siggen
sigtest
mail/src/main/java/com/sun/mail/pop3/TempFile.java
mail/src/test/java/com/sun/mail/pop3/POP3Handler.java
mail/src/main/java/com/sun/mail/imap/IMAPFolder.java
mail/src/main/java/com/sun/mail/imap/protocol/IMAPProtocol.java
demo/src/main/java/NewlineOutputStream.java


Added Paths:
------------
mail/src/test/java/javax/mail/internet/MimeMultipartParseTest.java
mail/src/test/java/javax/mail/internet/FoldTest.java
mail/src/test/resources/javax/mail/internet/folddata
mail/src/test/java/javax/mail/search/SearchTermSerializationTest.java
mail/src/test/java/com/sun/mail/util/BASE64Test.java
mail/src/test/java/javax/mail/internet/HeaderTokenizerTest.java
mail/src/test/resources/javax/mail/internet/tokenlist
mail/src/test/java/javax/mail/internet/DecodeParameters.java
mail/src/test/java/javax/mail/internet/ParameterListDecode.java
mail/src/test/java/javax/mail/internet/ParametersNoStrict.java
mail/src/test/resources/javax/mail/internet/paramdata
mail/src/test/resources/javax/mail/internet/paramdatanostrict
mail/src/main/java/com/sun/mail/pop3/TempFile.java


Diffs:
------
diff -r 849bafcc24ed -r 923ae963eebe mail/src/main/java/com/sun/mail/auth/MD4.java
--- a/mail/src/main/java/com/sun/mail/auth/MD4.java Fri Jan 08 12:31:55 2010 -0800
+++ b/mail/src/main/java/com/sun/mail/auth/MD4.java Fri Jan 08 13:35:09 2010 -0800
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright 2005-2009 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2005-2010 Sun Microsystems, Inc. All rights reserved.
  *
  * The contents of this file are subject to the terms of either the GNU
  * General Public License Version 2 only ("GPL") or the Common Development
@@ -60,7 +60,7 @@
     private final int[] x;
 
     // size of the input to the compression function in bytes
- private final int blockSize = 64;
+ private static final int blockSize = 64;
 
     // buffer to store partial blocks, blockSize bytes large
     private final byte[] buffer = new byte[blockSize];


diff -r 923ae963eebe -r 39360f6e3f5a mail/src/test/java/com/sun/mail/util/UUDecoderStreamTest.java
--- a/mail/src/test/java/com/sun/mail/util/UUDecoderStreamTest.java Fri Jan 08 13:35:09 2010 -0800
+++ b/mail/src/test/java/com/sun/mail/util/UUDecoderStreamTest.java Fri Jan 08 14:46:03 2010 -0800
@@ -37,13 +37,14 @@
 package com.sun.mail.util;
 
 import java.io.*;
-import java.util.StringTokenizer;
+import java.util.*;
 import com.sun.mail.util.UUDecoderStream;
 
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-import junit.framework.Test;
-import junit.framework.Assert;
+import org.junit.Test;
+import org.junit.Assert;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
 
 /**
  * Test uudecoder.
@@ -51,14 +52,14 @@
  * @author Bill Shannon
  */
 
-public class UUDecoderStreamTest extends TestCase {
+_at_RunWith(Parameterized.class)
+public class UUDecoderStreamTest {
     private TestData data;
 
     private static boolean gen_test_input = false; // output good
     private static int errors = 0; // number of errors detected
 
     private static boolean junit;
- private static TestSuite suite;
 
     static class TestData {
         public String name;
@@ -70,23 +71,25 @@
     }
 
     public UUDecoderStreamTest(TestData t) {
- super("testData");
         data = t;
     }
 
- public void testData() throws Exception {
+ @Test
+ public void testData() {
         test(data);
     }
 
- public static Test suite() throws Exception {
- suite = new TestSuite();
+ @Parameters
+ public static Collection data() throws Exception {
         junit = true;
+ // XXX - gratuitous array requirement
+ List<TestData[]> testData = new ArrayList<TestData[]>();
         BufferedReader in = new BufferedReader(new InputStreamReader(
             UUDecoderStreamTest.class.getResourceAsStream("uudata")));
         TestData t;
         while ((t = parse(in)) != null)
- suite.addTest(new UUDecoderStreamTest(t));
- return suite;
+ testData.add(new TestData[] { t });
+ return testData;
     }
 
     public static void main(String argv[]) throws Exception {
@@ -190,7 +193,7 @@
     /**
      * Test the data in the test case.
      */
- public static void test(TestData t) throws Exception {
+ public static void test(TestData t) {
         InputStream in =
             new UUDecoderStream(new ByteArrayInputStream(t.input),
                                 t.ignoreErrors, t.ignoreMissingBeginEnd);

diff -r 923ae963eebe -r 39360f6e3f5a mail/src/test/java/javax/mail/internet/InternetAddressTest.java
--- a/mail/src/test/java/javax/mail/internet/InternetAddressTest.java Fri Jan 08 13:35:09 2010 -0800
+++ b/mail/src/test/java/javax/mail/internet/InternetAddressTest.java Fri Jan 08 14:46:03 2010 -0800
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
  *
  * The contents of this file are subject to the terms of either the GNU
  * General Public License Version 2 only ("GPL") or the Common Development
@@ -37,14 +37,16 @@
 package javax.mail.internet;
 
 import java.io.*;
+import java.util.*;
 import javax.mail.*;
 import javax.mail.internet.InternetAddress;
 import javax.mail.internet.AddressException;
 
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-import junit.framework.Test;
-import junit.framework.Assert;
+import org.junit.Test;
+import org.junit.Assert;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
 
 /**
  * Test Internet address parsing.
@@ -52,7 +54,8 @@
  * @author Bill Shannon
  */
 
-public class InternetAddressTest extends TestCase {
+_at_RunWith(Parameterized.class)
+public class InternetAddressTest {
     private String headerName;
     private String headerValue;
     private String[] expected;
@@ -67,11 +70,10 @@
     static int errors = 0; // number of errors detected
 
     static boolean junit;
- static TestSuite suite;
+ static List testData;
 
     public InternetAddressTest(String headerName, String headerValue,
             String[] expected, boolean doStrict, boolean doParseHeader) {
- super("testAddress");
         this.headerName = headerName;
         this.headerValue = headerValue;
         this.expected = expected;
@@ -79,12 +81,13 @@
         this.doParseHeader = doParseHeader;
     }
 
- public static Test suite() throws Exception {
+ @Parameters
+ public static Collection data() throws IOException {
         junit = true;
- suite = new TestSuite();
+ testData = new ArrayList();
         parse(new BufferedReader(new InputStreamReader(
             InternetAddressTest.class.getResourceAsStream("addrlist"))));
- return suite;
+ return testData;
     }
 
     public static void main(String argv[]) throws Exception {
@@ -148,7 +151,7 @@
      * headers and testing them. The parse is rather crude, but sufficient
      * to test against most existing UNIX mailboxes.
      */
- public static void parse(BufferedReader in) throws Exception {
+ public static void parse(BufferedReader in) throws IOException {
         String header = "";
         boolean doStrict = strict;
         boolean doParseHeader = parse_header;
@@ -193,9 +196,9 @@
                 i = header.indexOf(':');
                 try {
                     if (junit)
- suite.addTest(new InternetAddressTest(
+ testData.add(new Object[] {
                             header.substring(0, i), header.substring(i + 2),
- expect, doStrict, doParseHeader));
+ expect, doStrict, doParseHeader });
                     else
                         test(header.substring(0, i), header.substring(i + 2),
                             expect, doStrict, doParseHeader);
@@ -221,7 +224,8 @@
         return header.substring(header.indexOf(':') + 1).trim();
     }
 
- public void testAddress() throws Exception {
+ @Test
+ public void testAddress() {
         test(headerName, headerValue, expected, doStrict, doParseHeader);
     }
 
@@ -229,7 +233,7 @@
      * Test the header's value to see if we can parse it as expected.
      */
     public static void test(String header, String value, String expect[],
- boolean doStrict, boolean doParseHeader) throws Exception {
+ boolean doStrict, boolean doParseHeader) {
         PrintStream out = System.out;
         if (gen_test_input)
             pr(header + ": " + value);


diff -r 39360f6e3f5a -r 826f7c513f64 mail/src/test/java/javax/mail/internet/MimeMultipartParseTest.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mail/src/test/java/javax/mail/internet/MimeMultipartParseTest.java Fri Jan 08 16:34:58 2010 -0800
@@ -0,0 +1,163 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common Development
+ * and Distribution License("CDDL") (collectively, the "License"). You
+ * may not use this file except in compliance with the License. You can obtain
+ * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
+ * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
+ * language governing permissions and limitations under the License.
+ *
+ * When distributing the software, include this License Header Notice in each
+ * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
+ * Sun designates this particular file as subject to the "Classpath" exception
+ * as provided by Sun in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the License
+ * Header, with the fields enclosed by brackets [] replaced by your own
+ * identifying information: "Portions Copyrighted [year]
+ * [name of copyright owner]"
+ *
+ * Contributor(s):
+ *
+ * If you wish your version of this file to be governed by only the CDDL or
+ * only the GPL Version 2, indicate your decision by adding "[Contributor]
+ * elects to include this software in this distribution under the [CDDL or GPL
+ * Version 2] license." If you don't indicate a single choice of license, a
+ * recipient has the option to distribute your version of this file under
+ * either the CDDL, the GPL Version 2 or to extend the choice of license to
+ * its licensees as provided above. However, if you add GPL Version 2 code
+ * and therefore, elected the GPL Version 2 license, then the option applies
+ * only if the new code is made subject to such option by the copyright
+ * holder.
+ */
+
+import java.util.*;
+import java.io.*;
+import javax.mail.*;
+import javax.mail.event.*;
+import javax.mail.internet.*;
+import javax.mail.util.*;
+import javax.activation.*;
+
+import org.junit.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/*
+ * Test multipart parsing.
+ *
+ * @author Bill Shannon
+ */
+
+public class MimeMultipartParseTest {
+ private static Session session =
+ Session.getInstance(new Properties(), null);
+
+ private static final int maxsize = 10000;
+ private static final String data =
+ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
+
+ @Test
+ public void testParse() throws Exception {
+ test(false);
+ }
+
+ @Test
+ public void testParseShared() throws Exception {
+ test(true);
+ }
+
+ /*
+ * Test a few potential boundary cases, then test a range.
+ * This is a compromise to make the run time of this test reasonable,
+ * although it still takes about 30 seconds, which is on the long side
+ * for a unit test.
+ */
+ public void test(boolean shared) throws Exception {
+ testMessage(1, shared);
+ testMessage(2, shared);
+ testMessage(62, shared);
+ testMessage(63, shared);
+ testMessage(64, shared);
+ testMessage(65, shared);
+ testMessage(1023, shared);
+ testMessage(1024, shared);
+ testMessage(1025, shared);
+ for (int size = 8100; size <= maxsize; size++)
+ testMessage(size, shared);
+ }
+
+ public void testMessage(int size, boolean shared) throws Exception {
+ //System.out.println("SIZE: " + size);
+ /*
+ * Construct a multipart message with a part of the
+ * given size.
+ */
+ MimeMessage msg = new MimeMessage(session);
+ msg.setFrom(new InternetAddress("me_at_example.com"));
+ msg.setSubject("test multipart parsing");
+ msg.setSentDate(new Date(0));
+ MimeBodyPart mbp1 = new MimeBodyPart();
+ mbp1.setText("main text\n");
+ MimeBodyPart mbp3 = new MimeBodyPart();
+ mbp3.setText("end text\n");
+ MimeBodyPart mbp2 = new MimeBodyPart();
+ byte[] part = new byte[size];
+ for (int i = 0; i < size; i++) {
+ int j = i % 64;
+ if (j == 62)
+ part[i] = (byte)'\r';
+ else if (j == 63)
+ part[i] = (byte)'\n';
+ else
+ part[i] = (byte)data.charAt((j + i / 64) % 62);
+ }
+ mbp2.setDataHandler(new DataHandler(
+ new ByteArrayDataSource(part, "text/plain")));
+
+ MimeMultipart mp = new MimeMultipart();
+ mp.addBodyPart(mbp1);
+ mp.addBodyPart(mbp2);
+ mp.addBodyPart(mbp3);
+ msg.setContent(mp);
+ msg.saveChanges();
+
+ /*
+ * Write the message out to a byte array.
+ */
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ msg.writeTo(bos);
+ bos.close();
+ byte[] buf = bos.toByteArray();
+
+ /*
+ * Construct a new message to parse the bytes.
+ */
+ msg = new MimeMessage(session, shared ?
+ new SharedByteArrayInputStream(buf) :
+ new ByteArrayInputStream(buf));
+
+ // verify that the part content is correct
+ mp = (MimeMultipart)msg.getContent();
+ mbp2 = (MimeBodyPart)mp.getBodyPart(1);
+ InputStream is = mbp2.getInputStream();
+ int k = 0;
+ int c;
+ while ((c = is.read()) >= 0) {
+ int j = k % 64;
+ byte e;
+ if (j == 62)
+ e = (byte)'\r';
+ else if (j == 63)
+ e = (byte)'\n';
+ else
+ e = (byte)data.charAt((j + k / 64) % 62);
+ Assert.assertEquals("Size " + size + " at byte " + k, e, c);
+ k++;
+ }
+ Assert.assertEquals("Expected size", size, k);
+ }
+}


diff -r 826f7c513f64 -r 604fe1cd5ebd mail/src/test/java/javax/mail/internet/FoldTest.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mail/src/test/java/javax/mail/internet/FoldTest.java Fri Jan 08 17:07:43 2010 -0800
@@ -0,0 +1,130 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common Development
+ * and Distribution License("CDDL") (collectively, the "License"). You
+ * may not use this file except in compliance with the License. You can obtain
+ * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
+ * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
+ * language governing permissions and limitations under the License.
+ *
+ * When distributing the software, include this License Header Notice in each
+ * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
+ * Sun designates this particular file as subject to the "Classpath" exception
+ * as provided by Sun in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the License
+ * Header, with the fields enclosed by brackets [] replaced by your own
+ * identifying information: "Portions Copyrighted [year]
+ * [name of copyright owner]"
+ *
+ * Contributor(s):
+ *
+ * If you wish your version of this file to be governed by only the CDDL or
+ * only the GPL Version 2, indicate your decision by adding "[Contributor]
+ * elects to include this software in this distribution under the [CDDL or GPL
+ * Version 2] license." If you don't indicate a single choice of license, a
+ * recipient has the option to distribute your version of this file under
+ * either the CDDL, the GPL Version 2 or to extend the choice of license to
+ * its licensees as provided above. However, if you add GPL Version 2 code
+ * and therefore, elected the GPL Version 2 license, then the option applies
+ * only if the new code is made subject to such option by the copyright
+ * holder.
+ */
+
+package javax.mail.internet;
+
+import java.io.*;
+import java.util.*;
+import javax.mail.internet.MimeUtility;
+
+import org.junit.Test;
+import org.junit.Assert;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+/**
+ * Test header folding.
+ *
+ * @author Bill Shannon
+ */
+
+_at_RunWith(Parameterized.class)
+public class FoldTest {
+ private String direction;
+ private String orig;
+ private String expect;
+
+ private static List testData;
+
+ public FoldTest(String direction, String orig, String expect) {
+ this.direction = direction;
+ this.orig = orig;
+ this.expect = expect;
+ }
+
+ @Parameters
+ public static Collection data() throws IOException {
+ testData = new ArrayList();
+ parse(new BufferedReader(new InputStreamReader(
+ FoldTest.class.getResourceAsStream("folddata"))));
+ return testData;
+ }
+
+ /**
+ * Read the data from the test file. Format is multiple of any of
+ * the following:
+ *
+ * FOLD\nString$\nEXPECT\nString$\n
+ * UNFOLD\nString$\nEXPECT\nString$\n
+ * BOTH\nString$\n
+ */
+ private static void parse(BufferedReader in) throws IOException {
+ String line;
+ while ((line = in.readLine()) != null) {
+ if (line.startsWith("#"))
+ continue;
+ String orig = readString(in);
+ if (line.equals("BOTH")) {
+ testData.add(new Object[] { line, orig, null });
+ } else {
+ String e = in.readLine();
+ if (!e.equals("EXPECT"))
+ throw new IOException("TEST DATA FORMAT ERROR");
+ String expect = readString(in);
+ testData.add(new Object[] { line, orig, expect });
+ }
+ }
+ }
+
+ /**
+ * Read a string that ends with '$', preserving all characters,
+ * especially including CR and LF.
+ */
+ private static String readString(BufferedReader in) throws IOException {
+ StringBuffer sb = new StringBuffer();
+ int c;
+ while ((c = in.read()) != '$')
+ sb.append((char)c);
+ in.readLine(); // throw away rest of line
+ return sb.toString();
+ }
+
+ @Test
+ public void testFold() {
+ if (direction.equals("BOTH")) {
+ String fs = MimeUtility.fold(0, orig);
+ String us = MimeUtility.unfold(fs);
+ Assert.assertEquals(orig, us);
+ } else if (direction.equals("FOLD")) {
+ Assert.assertEquals("Fold", expect, MimeUtility.fold(0, orig));
+ } else if (direction.equals("UNFOLD")) {
+ Assert.assertEquals("Unfold", expect, MimeUtility.unfold(orig));
+ } else {
+ Assert.fail("Unknown direction: " + direction);
+ }
+ }
+}

diff -r 826f7c513f64 -r 604fe1cd5ebd mail/src/test/resources/javax/mail/internet/folddata
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mail/src/test/resources/javax/mail/internet/folddata Fri Jan 08 17:07:43 2010 -0800
@@ -0,0 +1,228 @@
+#
+#
+# Test data used by foldtest.java to test the MimeUtility.fold
+# and MimeUtility.unfold methods.
+#
+# First, tests that ensure simple strings aren't changed.
+#
+FOLD
+a b c$
+EXPECT
+a b c$
+UNFOLD
+a b c$
+EXPECT
+a b c$
+BOTH
+a b c$
+#
+# Test that long strings with no whitespace aren't changed.
+#
+FOLD
+aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa$
+EXPECT
+aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa$
+UNFOLD
+aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa$
+EXPECT
+aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa$
+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
+ b$
+EXPECT
+a
+ b$
+UNFOLD
+a\
+ b$
+EXPECT
+a
+ b$
+#
+# Test with leading and trailing newlines
+# XXX - Should trailing whitespace always be removed,
+# especially when it's the result of unfolding?
+#
+UNFOLD
+
+ a$
+EXPECT
+a$
+UNFOLD
+
+a$
+EXPECT
+
+a$
+UNFOLD
+
+ a$
+EXPECT
+a$
+UNFOLD
+
+a$
+EXPECT
+
+a$
+UNFOLD
+a
+$
+EXPECT
+a
+$
+UNFOLD
+a
+ $
+EXPECT
+a $
+#
+# Test some boundary conditions for folding.
+#
+FOLD
+aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa xxx$
+EXPECT
+aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+ xxx$
+FOLD
+xxx aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa xxx$
+EXPECT
+xxx
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+ xxx$
+FOLD
+aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa xxx$
+EXPECT
+aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa xxx$
+FOLD
+aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa xxx$
+EXPECT
+aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa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b c$
+UNFOLD
+a\
+ b\
+ c$
+EXPECT
+a
+ b
+ c$
+#
+# Unfold with multiple leading whitespace characters
+#
+UNFOLD
+a
+ b$
+EXPECT
+a b$
+UNFOLD
+a
+ b$
+EXPECT
+a b$


diff -r 604fe1cd5ebd -r 1dd4a095701c mail/src/test/java/javax/mail/search/SearchTermSerializationTest.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mail/src/test/java/javax/mail/search/SearchTermSerializationTest.java Fri Jan 08 17:16:25 2010 -0800
@@ -0,0 +1,94 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common Development
+ * and Distribution License("CDDL") (collectively, the "License"). You
+ * may not use this file except in compliance with the License. You can obtain
+ * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
+ * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
+ * language governing permissions and limitations under the License.
+ *
+ * When distributing the software, include this License Header Notice in each
+ * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
+ * Sun designates this particular file as subject to the "Classpath" exception
+ * as provided by Sun in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the License
+ * Header, with the fields enclosed by brackets [] replaced by your own
+ * identifying information: "Portions Copyrighted [year]
+ * [name of copyright owner]"
+ *
+ * Contributor(s):
+ *
+ * If you wish your version of this file to be governed by only the CDDL or
+ * only the GPL Version 2, indicate your decision by adding "[Contributor]
+ * elects to include this software in this distribution under the [CDDL or GPL
+ * Version 2] license." If you don't indicate a single choice of license, a
+ * recipient has the option to distribute your version of this file under
+ * either the CDDL, the GPL Version 2 or to extend the choice of license to
+ * its licensees as provided above. However, if you add GPL Version 2 code
+ * and therefore, elected the GPL Version 2 license, then the option applies
+ * only if the new code is made subject to such option by the copyright
+ * holder.
+ */
+
+package javax.mail.internet.search;
+
+import java.io.*;
+import java.util.Date;
+
+import javax.mail.*;
+import javax.mail.search.*;
+import javax.mail.internet.*;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * SearchTerm serialization test.
+ *
+ * @author Bill Shannon
+ */
+
+public class SearchTermSerializationTest {
+
+ @Test
+ public void testSerialization() throws IOException, ClassNotFoundException {
+ // construct a SearchTerm using all SearchTerm types
+ SearchTerm term = new AndTerm(new SearchTerm[] {
+ new BodyTerm("text"),
+ new FlagTerm(new Flags(Flags.Flag.RECENT), true),
+ new FromStringTerm("foo_at_bar"),
+ new HeaderTerm("X-Mailer", "dtmail"),
+ new MessageIDTerm("12345_at_sun.com"),
+ new MessageNumberTerm(42),
+ new NotTerm(
+ new OrTerm(
+ new ReceivedDateTerm(ReceivedDateTerm.LT, new Date()),
+ new RecipientStringTerm(Message.RecipientType.CC, "foo")
+ )
+ ),
+ new RecipientTerm(MimeMessage.RecipientType.NEWSGROUPS,
+ new NewsAddress("comp.lang.java", "newshost")),
+ new SentDateTerm(SentDateTerm.NE, new Date()),
+ new SizeTerm(SizeTerm.LT, 1000),
+ new SubjectTerm("test")
+ });
+
+ // serialize it to a byte array
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(bos);
+ oos.writeObject(term);
+ bos.close();
+
+ // read it back in
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+ ObjectInputStream ois = new ObjectInputStream(bis);
+ SearchTerm term2 = (SearchTerm)ois.readObject();
+
+ // compare it with the original
+ assertEquals(term, term2);
+ }
+}


diff -r 1dd4a095701c -r 862ee3227691 mail/src/oldtest/java/javax/mail/internet/b64test.java
--- a/mail/src/oldtest/java/javax/mail/internet/b64test.java Fri Jan 08 17:16:25 2010 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,260 +0,0 @@
-/*
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
- *
- * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
- *
- * The contents of this file are subject to the terms of either the GNU
- * General Public License Version 2 only ("GPL") or the Common Development
- * and Distribution License("CDDL") (collectively, the "License"). You
- * may not use this file except in compliance with the License. You can obtain
- * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
- * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
- * language governing permissions and limitations under the License.
- *
- * When distributing the software, include this License Header Notice in each
- * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
- * Sun designates this particular file as subject to the "Classpath" exception
- * as provided by Sun in the GPL Version 2 section of the License file that
- * accompanied this code. If applicable, add the following below the License
- * Header, with the fields enclosed by brackets [] replaced by your own
- * identifying information: "Portions Copyrighted [year]
- * [name of copyright owner]"
- *
- * Contributor(s):
- *
- * If you wish your version of this file to be governed by only the CDDL or
- * only the GPL Version 2, indicate your decision by adding "[Contributor]
- * elects to include this software in this distribution under the [CDDL or GPL
- * Version 2] license." If you don't indicate a single choice of license, a
- * recipient has the option to distribute your version of this file under
- * either the CDDL, the GPL Version 2 or to extend the choice of license to
- * its licensees as provided above. However, if you add GPL Version 2 code
- * and therefore, elected the GPL Version 2 license, then the option applies
- * only if the new code is made subject to such option by the copyright
- * holder.
- */
-
-//package javax.mail.internet.tests;
-
-import java.io.*;
-import java.util.*;
-import javax.mail.*;
-import com.sun.mail.util.*;
-
-/**
- * Test base64 encoding/decoding.
- *
- * @author Bill Shannon
- */
-
-public class b64test {
- static int errors;
-
- public static void main(String argv[]) throws Exception {
- // test a range of buffer sizes
- for (int bufsize = 1; bufsize < 100; bufsize++) {
- System.out.println("Buffer size: " + bufsize);
- byte[] buf = new byte[bufsize];
-
- // test a set of patterns
-
- // first, all zeroes
- Arrays.fill(buf, (byte)0);
- test("Zeroes", buf);
-
- // now, all ones
- Arrays.fill(buf, (byte)0xff);
- test("Ones", buf);
-
- // now, small integers
- for (int i = 0; i < bufsize; i++)
- buf[i] = (byte)i;
- test("Ints", buf);
-
- // finally, random numbers
- Random rnd = new Random();
- rnd.nextBytes(buf);
- test("Random", buf);
- }
-
- System.exit(errors);
-
- }
-
- /**
- * Encode and decode the buffer and check that we get back the
- * same data. Encoding is done both with the static encode
- * method and using the encoding stream. Likewise, decoding
- * is done both with the static decode method and using the
- * decoding stream. Check all combinations.
- */
- private static void test(String name, byte[] buf) {
- try {
- // first encode and decode with method
- byte[] encoded = BASE64EncoderStream.encode(buf);
- byte[] nbuf = BASE64DecoderStream.decode(encoded);
- compare(name, "method", buf, nbuf);
-
- // encode with stream, compare with method encoded version
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- BASE64EncoderStream os =
- new BASE64EncoderStream(bos, Integer.MAX_VALUE);
- os.write(buf);
- os.flush();
- os.close();
- byte[] sbuf = bos.toByteArray();
- compare(name, "encoded", encoded, sbuf);
-
- // encode with stream, decode with method
- nbuf = BASE64DecoderStream.decode(sbuf);
- compare(name, "stream->method", buf, nbuf);
-
- // encode with stream, decode with stream
- ByteArrayInputStream bin = new ByteArrayInputStream(sbuf);
- BASE64DecoderStream in = new BASE64DecoderStream(bin);
- readAll(in, nbuf, nbuf.length);
- compare(name, "stream", buf, nbuf);
-
- // encode with method, decode with stream
- for (int i = 1; i <= nbuf.length; i++) {
- bin = new ByteArrayInputStream(encoded);
- in = new BASE64DecoderStream(bin);
- readAll(in, nbuf, i);
- compare(name, "method->stream " + i, buf, nbuf);
- }
-
- // encode with stream, decode with stream, many buffers
-
- // first, fill the output with multiple buffers, up to the limit
- int limit = 10000; // more than 8K
- bos = new ByteArrayOutputStream();
- os = new BASE64EncoderStream(bos);
- for (int size = 0, blen = buf.length; size < limit; size += blen) {
- if (size + blen > limit) {
- blen = limit - size;
- // write out partial buffer, starting at non-zero offset
- os.write(buf, buf.length - blen, blen);
- } else
- os.write(buf);
- }
- os.flush();
- os.close();
-
- // read the encoded output and check the line length
- String type = "big stream"; // for error messages below
- sbuf = bos.toByteArray();
- bin = new ByteArrayInputStream(sbuf);
- byte[] inbuf = new byte[78];
- for (int size = 0, blen = 76; size < limit; size += blen) {
- if (size + blen > limit) {
- blen = limit - size;
- int n = bin.read(inbuf, 0, blen);
- if (n != blen) {
- System.out.println(name + ": " + type +
- " read wrong size: " +
- "got " + n + ", expected " + blen +
- ", at offset " + (size + blen));
- errors++;
- }
- } else {
- int n = bin.read(inbuf, 0, blen + 2);
- if (n != blen + 2) {
- System.out.println(name + ": " + type +
- " read wrong size: " +
- "got " + n + ", expected " + (blen + 2) +
- ", at offset " + (size + blen));
- errors++;
- }
- if (inbuf[blen] != (byte)'\r' ||
- inbuf[blen+1] != (byte)'\n') {
- System.out.println(name + ": " + type +
- " no CRLF: at offset " + (size + blen));
- errors++;
- }
- }
- }
-
- // decode the output and check the data
- bin = new ByteArrayInputStream(sbuf);
- in = new BASE64DecoderStream(bin);
- inbuf = new byte[buf.length];
- for (int size = 0, blen = buf.length; size < limit; size += blen) {
- if (size + blen > limit)
- blen = limit - size;
- int n = in.read(nbuf, 0, blen);
- if (n != blen) {
- System.out.println(name + ": " + type +
- " read decoded wrong size: " +
- "got " + n + ", expected " + blen +
- ", at offset " + (size + blen));
- errors++;
- }
- if (blen != buf.length) {
- // have to compare with end of original buffer
- byte[] cbuf = new byte[blen];
- System.arraycopy(buf, buf.length - blen, cbuf, 0, blen);
- // need a version of the read buffer that's the right size
- byte[] cnbuf = new byte[blen];
- System.arraycopy(nbuf, 0, cnbuf, 0, blen);
- compare(name, type, cbuf, cnbuf);
- } else {
- compare(name, type, buf, nbuf);
- }
- }
- } catch (Exception ex) {
- System.out.println(name + ": Exception: " + ex);
- errors++;
- }
- }
-
- /**
- * Fill the buffer from the stream.
- */
- private static void readAll(InputStream in, byte[] buf, int readsize)
- throws IOException {
- int need = buf.length;
- int off = 0;
- int got;
- while (need > 0) {
- got = in.read(buf, off, need > readsize ? readsize : need);
- if (got <= 0)
- break;
- off += got;
- need -= got;
- }
- if (need != 0)
- System.out.println("couldn't read all bytes");
- }
-
- /**
- * Compare the two buffers.
- */
- private static void compare(String name, String type,
- byte[] buf, byte[] nbuf) {
- if (nbuf.length != buf.length) {
- System.out.println(name + ": " + type +
- " decoded array size wrong: " +
- "got " + nbuf.length + ", expected " + buf.length);
- dump(name + " buf", buf);
- dump(name + " nbuf", nbuf);
- errors++;
- }
- for (int i = 0; i < buf.length; i++) {
- if (nbuf[i] != buf[i]) {
- System.out.println(name + ": " + type + " data wrong: " +
- "index " + i + ", " +
- "got " + (nbuf[i]&0xff) + ", expected " + (buf[i]&0xff));
- errors++;
- }
- }
- }
-
- /**
- * Dump the contents of the buffer.
- */
- private static void dump(String name, byte[] buf) {
- System.out.println(name);
- for (int i = 0; i < buf.length; i++)
- System.out.println(buf[i]);
- }
-}

diff -r 1dd4a095701c -r 862ee3227691 mail/src/oldtest/java/javax/mail/internet/folddata
--- a/mail/src/oldtest/java/javax/mail/internet/folddata Fri Jan 08 17:16:25 2010 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,228 +0,0 @@
-#
-#
-# Test data used by foldtest.java to test the MimeUtility.fold
-# and MimeUtility.unfold methods.
-#
-# First, tests that ensure simple strings aren't changed.
-#
-FOLD
-a b c$
-EXPECT
-a b c$
-UNFOLD
-a b c$
-EXPECT
-a b c$
-BOTH
-a b c$
-#
-# Test that long strings with no whitespace aren't changed.
-#
-FOLD
-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa$
-EXPECT
-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa$
-UNFOLD
-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa$
-EXPECT
-aaaaaaaaaaaaaaaaaaaaaaaa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$
-EXPECT
-a b$
-UNFOLD
-a
- b$
-EXPECT
-a b$
-#
-UNFOLD
-a \
- b$
-EXPECT
-a
- b$
-UNFOLD
-a\
- b$
-EXPECT
-a
- b$
-#
-# Test with leading and trailing newlines
-# XXX - Should trailing whitespace always be removed,
-# especially when it's the result of unfolding?
-#
-UNFOLD
-
- a$
-EXPECT
-a$
-UNFOLD
-
-a$
-EXPECT
-
-a$
-UNFOLD
-
- a$
-EXPECT
-a$
-UNFOLD
-
-a$
-EXPECT
-
-a$
-UNFOLD
-a
-$
-EXPECT
-a
-$
-UNFOLD
-a
- $
-EXPECT
-a $
-#
-# Test some boundary conditions for folding.
-#
-FOLD
-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa xxx$
-EXPECT
-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
- xxx$
-FOLD
-xxx aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa xxx$
-EXPECT
-xxx
- aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
- xxx$
-FOLD
-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa xxx$
-EXPECT
-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa xxx$
-FOLD
-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa xxx$
-EXPECT
-aaaaaaaaaaaaaaa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
- c$
-UNFOLD
-a
- b
- c$
-EXPECT
-a b c$
-UNFOLD
-a\
- b\
- c$
-EXPECT
-a
- b
- c$
-#
-# Unfold with multiple leading whitespace characters
-#
-UNFOLD
-a
- b$
-EXPECT
-a b$
-UNFOLD
-a
- b$
-EXPECT
-a b$

diff -r 1dd4a095701c -r 862ee3227691 mail/src/oldtest/java/javax/mail/internet/foldtest.java
--- a/mail/src/oldtest/java/javax/mail/internet/foldtest.java Fri Jan 08 17:16:25 2010 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,183 +0,0 @@
-/*
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
- *
- * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
- *
- * The contents of this file are subject to the terms of either the GNU
- * General Public License Version 2 only ("GPL") or the Common Development
- * and Distribution License("CDDL") (collectively, the "License"). You
- * may not use this file except in compliance with the License. You can obtain
- * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
- * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
- * language governing permissions and limitations under the License.
- *
- * When distributing the software, include this License Header Notice in each
- * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
- * Sun designates this particular file as subject to the "Classpath" exception
- * as provided by Sun in the GPL Version 2 section of the License file that
- * accompanied this code. If applicable, add the following below the License
- * Header, with the fields enclosed by brackets [] replaced by your own
- * identifying information: "Portions Copyrighted [year]
- * [name of copyright owner]"
- *
- * Contributor(s):
- *
- * If you wish your version of this file to be governed by only the CDDL or
- * only the GPL Version 2, indicate your decision by adding "[Contributor]
- * elects to include this software in this distribution under the [CDDL or GPL
- * Version 2] license." If you don't indicate a single choice of license, a
- * recipient has the option to distribute your version of this file under
- * either the CDDL, the GPL Version 2 or to extend the choice of license to
- * its licensees as provided above. However, if you add GPL Version 2 code
- * and therefore, elected the GPL Version 2 license, then the option applies
- * only if the new code is made subject to such option by the copyright
- * holder.
- */
-
-//package javax.mail.internet.tests;
-
-import java.io.*;
-import javax.mail.internet.MimeUtility;
-
-/**
- * Test header folding.
- *
- * NOTE: Requires hacked version of MimeUtility to make
- * fold and unfold methods public.
- *
- * @author Bill Shannon
- */
-
-public class foldtest {
- private static boolean verbose;
- private static int errors;
-
- public static void main(String argv[]) throws Exception {
- int optind;
- for (optind = 0; optind < argv.length; optind++) {
- if (argv[optind].equals("-")) {
- // ignore
- } else if (argv[optind].equals("-v")) {
- verbose = true;
- /*
- } else if (argv[optind].equals("-p")) {
- parse_mail = true;
- } else if (argv[optind].equals("-s")) {
- strict = true;
- */
- } else if (argv[optind].equals("--")) {
- optind++;
- break;
- } else if (argv[optind].startsWith("-")) {
- System.out.println(
- "Usage: foldtest [-v] [-] [address ...]");
- System.exit(1);
- } else {
- break;
- }
- }
-
- /*
- * If there's any args left on the command line,
- * test each of them.
- */
- if (optind < argv.length) {
- for (int i = optind; i < argv.length; i++) {
- test(argv[i]);
- }
- } else {
- // read from stdin
- BufferedReader in =
- new BufferedReader(new InputStreamReader(System.in));
- test(in);
- }
- System.exit(errors);
-
- }
-
- /**
- * Read the data from the test file. Format is multiple of any of
- * the following:
- *
- * FOLD\nString$\nEXPECT\nString$\n
- * UNFOLD\nString$\nEXPECT\nString$\n
- * BOTH\nString$\n
- */
- private static void test(BufferedReader in) throws Exception {
- String line;
- while ((line = in.readLine()) != null) {
- if (line.startsWith("#"))
- continue;
- String orig = readString(in);
- if (line.equals("BOTH")) {
- test(orig);
- } else {
- String e = in.readLine();
- if (!e.equals("EXPECT"))
- System.out.println("TEST DATA FORMAT ERROR");
- String expect = readString(in);
- if (line.equals("FOLD")) {
- String t = MimeUtility.fold(0, orig);
- if (!t.equals(expect) || verbose) {
- if (!t.equals(expect)) {
- System.out.println("ERROR:");
- errors++;
- }
- System.out.println("Orig: " + orig);
- System.out.println("Folded: " + t);
- System.out.println("Expected: " + expect);
- //diff(t, expect);
- }
- } else {
- String t = MimeUtility.unfold(orig);
- if (!t.equals(expect) || verbose) {
- if (!t.equals(expect)) {
- System.out.println("ERROR:");
- errors++;
- }
- System.out.println("Orig: " + orig);
- System.out.println("Unfolded: " + t);
- System.out.println("Expected: " + expect);
- //diff(t, expect);
- }
- }
- }
- }
- }
-
- /**
- * Read a string that ends with '$', preserving all characters,
- * especially including CR and LF.
- */
- private static String readString(BufferedReader in) throws Exception {
- StringBuffer sb = new StringBuffer();
- int c;
- while ((c = in.read()) != '$')
- sb.append((char)c);
- in.readLine(); // throw away rest of line
- return sb.toString();
- }
-
- private static void test(String s) throws Exception {
- String fs = MimeUtility.fold(0, s);
- String us = MimeUtility.unfold(fs);
- if (!s.equals(us) || verbose) {
- if (!s.equals(us)) {
- System.out.println("ERROR:");
- errors++;
- }
- System.out.println("Orig: " + s);
- System.out.println("Folded: " + fs);
- System.out.println("Unfolded: " + us);
- }
- }
-
- private static void diff(String s, String t) {
- int len = Math.max(s.length(), t.length());
- for (int i = 0; i < len; i++) {
- System.out.println(i + " " +
- (i < s.length() ? (s.charAt(i)&0xff) : -1) + " " +
- (i < t.length() ? (t.charAt(i)&0xff) : -1));
- }
- }
-}

diff -r 1dd4a095701c -r 862ee3227691 mail/src/oldtest/java/javax/mail/internet/multiparttest.java
--- a/mail/src/oldtest/java/javax/mail/internet/multiparttest.java Fri Jan 08 17:16:25 2010 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,380 +0,0 @@
-/*
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
- *
- * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
- *
- * The contents of this file are subject to the terms of either the GNU
- * General Public License Version 2 only ("GPL") or the Common Development
- * and Distribution License("CDDL") (collectively, the "License"). You
- * may not use this file except in compliance with the License. You can obtain
- * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
- * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
- * language governing permissions and limitations under the License.
- *
- * When distributing the software, include this License Header Notice in each
- * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
- * Sun designates this particular file as subject to the "Classpath" exception
- * as provided by Sun in the GPL Version 2 section of the License file that
- * accompanied this code. If applicable, add the following below the License
- * Header, with the fields enclosed by brackets [] replaced by your own
- * identifying information: "Portions Copyrighted [year]
- * [name of copyright owner]"
- *
- * Contributor(s):
- *
- * If you wish your version of this file to be governed by only the CDDL or
- * only the GPL Version 2, indicate your decision by adding "[Contributor]
- * elects to include this software in this distribution under the [CDDL or GPL
- * Version 2] license." If you don't indicate a single choice of license, a
- * recipient has the option to distribute your version of this file under
- * either the CDDL, the GPL Version 2 or to extend the choice of license to
- * its licensees as provided above. However, if you add GPL Version 2 code
- * and therefore, elected the GPL Version 2 license, then the option applies
- * only if the new code is made subject to such option by the copyright
- * holder.
- */
-
-import java.util.*;
-import java.io.*;
-import javax.mail.*;
-import javax.mail.event.*;
-import javax.mail.internet.*;
-import javax.mail.util.*;
-import javax.activation.*;
-
-/*
- * Test multipart parsing.
- *
- * @author Bill Shannon
- */
-
-public class multiparttest {
-
- static boolean verbose = false;
- static boolean debug = false;
- static boolean showStructure = false;
- static boolean saveAttachments = false;
- static boolean shared = false;
- static int attnum = 1;
-
- static final String data =
- "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
-
- public static void main(String argv[]) {
- int maxsize = 10000;
- int optind;
-
- for (optind = 0; optind < argv.length; optind++) {
- if (argv[optind].equals("-v")) {
- verbose = true;
- } else if (argv[optind].equals("-D")) {
- debug = true;
- } else if (argv[optind].equals("-s")) {
- showStructure = true;
- } else if (argv[optind].equals("-S")) {
- saveAttachments = true;
- } else if (argv[optind].equals("-F")) {
- shared = true;
- } else if (argv[optind].equals("--")) {
- optind++;
- break;
- } else if (argv[optind].startsWith("-")) {
- System.out.println(
-"Usage: multiparttest [-v] [-D] [-s] [-S] [mazsize]");
- System.exit(1);
- } else {
- break;
- }
- }
-
- if (optind < argv.length)
- maxsize = Integer.parseInt(argv[optind]);
-
- try {
- // Get a Properties object
- Properties props = System.getProperties();
-
- // Get a Session object
- Session session = Session.getInstance(props, null);
- session.setDebug(debug);
-
- long t0 = System.currentTimeMillis();
- for (int size = 1; size <= maxsize; size++) {
- System.out.println("SIZE: " + size);
- /*
- * Construct a multipart message with a part of the
- * given size.
- */
- MimeMessage msg = new MimeMessage(session);
- msg.setFrom(new InternetAddress("me_at_example.com"));
- msg.setSubject("test multipart parsing");
- msg.setSentDate(new Date(0));
- MimeBodyPart mbp1 = new MimeBodyPart();
- mbp1.setText("main text\n");
- MimeBodyPart mbp3 = new MimeBodyPart();
- mbp3.setText("end text\n");
- MimeBodyPart mbp2 = new MimeBodyPart();
- byte[] part = new byte[size];
- for (int i = 0; i < size; i++) {
- int j = i % 64;
- if (j == 62)
- part[i] = (byte)'\r';
- else if (j == 63)
- part[i] = (byte)'\n';
- else
- part[i] = (byte)data.charAt((j + i / 64) % 62);
- }
- mbp2.setDataHandler(new DataHandler(
- new ByteArrayDataSource(part, "text/plain")));
-
- MimeMultipart mp = new MimeMultipart();
- mp.addBodyPart(mbp1);
- mp.addBodyPart(mbp2);
- mp.addBodyPart(mbp3);
- msg.setContent(mp);
- msg.saveChanges();
-
- /*
- * Write the message out to a byte array.
- */
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- msg.writeTo(bos);
- bos.close();
- byte[] buf = bos.toByteArray();
-
- /*
- // to verify that the message is being constructed properly
- FileOutputStream fos = new FileOutputStream("msg.txt");
- fos.write(buf);
- fos.close();
- */
-
- /*
- * Construct a new message to parse the bytes.
- */
- msg = new MimeMessage(session, shared ?
- new SharedByteArrayInputStream(buf) :
- new ByteArrayInputStream(buf));
-
- // verify that the part content is correct
- mp = (MimeMultipart)msg.getContent();
[truncated due to length]