commits@javamail.java.net

[javamail~mercurial:316] Fix handling of old MacOS line terminators - Kenai issue #3539.

From: <shannon_at_kenai.com>
Date: Sat, 13 Nov 2010 01:48:41 +0000

Project: javamail
Repository: mercurial
Revision: 316
Author: shannon
Date: 2010-11-12 18:32:28 UTC
Link:

Log Message:
------------
Require specific non-SNAPSHOT versions of maven-bundle-plugin and
maven-enforcer-plugin.
Work around bug in Exchange 2010 that returns unquoted string for encoding
Fix handling of old MacOS line terminators - Kenai issue #3539.


Revisions:
----------
314
315
316


Modified Paths:
---------------
pom.xml
mail/src/main/java/com/sun/mail/imap/protocol/BODYSTRUCTURE.java
doc/release/CHANGES.txt
mail/src/main/java/com/sun/mail/util/LineInputStream.java


Added Paths:
------------
mail/src/test/java/com/sun/mail/util/LineInputStreamTest.java


Diffs:
------
diff -r 12192f2eee28 -r a4599ee4a431 pom.xml
--- a/pom.xml Fri Nov 05 14:18:29 2010 -0700
+++ b/pom.xml Thu Nov 11 15:29:49 2010 -0800
@@ -448,6 +448,16 @@
                         <skip>true</skip>
                     </configuration>
                 </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-enforcer-plugin</artifactId>
+ <version>1.0</version>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>2.1.0</version>
+ </plugin>
             </plugins>
         </pluginManagement>
 


diff -r a4599ee4a431 -r ead1229c0567 mail/src/main/java/com/sun/mail/imap/protocol/BODYSTRUCTURE.java
--- a/mail/src/main/java/com/sun/mail/imap/protocol/BODYSTRUCTURE.java Thu Nov 11 15:29:49 2010 -0800
+++ b/mail/src/main/java/com/sun/mail/imap/protocol/BODYSTRUCTURE.java Thu Nov 11 15:33:15 2010 -0800
@@ -230,7 +230,13 @@
             description = r.readString();
             if (parseDebug)
                 System.out.println("DEBUG IMAP: description " + description);
- encoding = r.readString();
+ /*
+ * XXX - Work around bug in Exchange 2010 that
+ * returns unquoted string.
+ */
+ encoding = r.readAtomString();
+ if (encoding != null && encoding.equalsIgnoreCase("NIL"))
+ encoding = null;
             if (parseDebug)
                 System.out.println("DEBUG IMAP: encoding " + encoding);
             size = r.readNumber();


diff -r ead1229c0567 -r db47b48038d5 doc/release/CHANGES.txt
--- a/doc/release/CHANGES.txt Thu Nov 11 15:33:15 2010 -0800
+++ b/doc/release/CHANGES.txt Fri Nov 12 10:32:28 2010 -0800
@@ -23,9 +23,10 @@
 6905730 MimeMessage.parse() is very slow on malformed message content
 6910675 IMAP provider can lose track of message sequence numbers
 6928566 Header violates RFC 2822 for multiple calls of addRecipient(s)
-6995537 Work around this JDK bug that causes iso-2022-jp decoding problems
+6995537 work around this JDK bug that causes iso-2022-jp decoding problems
 G 11069 update the mail.jar manifest to include DynamicImport-Package
 K 3442 make sure socket is closed if SMTP connect fails
+K 3539 Multiparts do not parse correctly in presence of legacy Mac line endings
 <no id> add mail.mime.windowsfilenames System property to handle IE6 breakage
 <no id> properly disable TOP if POP3 CAPA response doesn't include it
 <no id> add mail.pop3.disablecapa property to disable use of the CAPA command

diff -r ead1229c0567 -r db47b48038d5 mail/src/main/java/com/sun/mail/util/LineInputStream.java
--- a/mail/src/main/java/com/sun/mail/util/LineInputStream.java Thu Nov 11 15:33:15 2010 -0800
+++ b/mail/src/main/java/com/sun/mail/util/LineInputStream.java Fri Nov 12 10:32:28 2010 -0800
@@ -91,14 +91,20 @@
                 break;
             else if (c1 == '\r') {
                 // Got CR, is the next char NL ?
+ boolean twoCRs = false;
                 int c2 = in.read();
- if (c2 == '\r') // discard extraneous CR
+ if (c2 == '\r') { // discard extraneous CR
+ twoCRs = true;
                     c2 = in.read();
+ }
                 if (c2 != '\n') {
                     // If not NL, push it back
                     if (!(in instanceof PushbackInputStream))
- in = this.in = new PushbackInputStream(in);
- ((PushbackInputStream)in).unread(c2);
+ in = this.in = new PushbackInputStream(in, 2);
+ if (c2 != -1)
+ ((PushbackInputStream)in).unread(c2);
+ if (twoCRs)
+ ((PushbackInputStream)in).unread('\r');
                 }
                 break; // outa here.
             }

diff -r ead1229c0567 -r db47b48038d5 mail/src/test/java/com/sun/mail/util/LineInputStreamTest.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mail/src/test/java/com/sun/mail/util/LineInputStreamTest.java Fri Nov 12 10:32:28 2010 -0800
@@ -0,0 +1,123 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright (c) 1997-2010 Oracle and/or its affiliates. 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_1_1.html
+ * or packager/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 packager/legal/LICENSE.txt.
+ *
+ * GPL Classpath Exception:
+ * Oracle designates this particular file as subject to the "Classpath"
+ * exception as provided by Oracle in the GPL Version 2 section of the License
+ * file that accompanied this code.
+ *
+ * Modifications:
+ * If applicable, add the following below the License Header, with the fields
+ * enclosed by brackets [] replaced by your own identifying information:
+ * "Portions Copyright [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 com.sun.mail.util;
+
+import java.io.*;
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Test handling of line terminators.
+ * LineInputStream handles these different line terminators:
+ *
+ * NL - Unix
+ * CR LF - Windows, MIME
+ * CR - old MacOS
+ * CR CR LF - broken internet servers
+ *
+ * @author Bill Shannon
+ */
+
+public class LineInputStreamTest {
+ private static final String[] lines = {
+ "line1\nline2\nline3\n",
+ "line1\r\nline2\r\nline3\r\n",
+ "line1\rline2\rline3\r",
+ "line1\r\r\nline2\r\r\nline3\r\r\n"
+ };
+
+ private static final String[] empty = {
+ "\n\n\n",
+ "\r\n\r\n\r\n",
+ "\r\r\r",
+ "\r\r\n\r\r\n\r\r\n"
+ };
+
+ private static final String[] mixed = {
+ "line1\n\nline3\n",
+ "line1\r\n\r\nline3\r\n",
+ "line1\r\rline3\r",
+ "line1\r\r\n\r\r\nline3\r\r\n"
+ };
+
+ @Test
+ public void testLines() throws IOException {
+ for (String s : lines) {
+ LineInputStream is = createStream(s);
+ assertEquals("line1", is.readLine());
+ assertEquals("line2", is.readLine());
+ assertEquals("line3", is.readLine());
+ assertEquals(null, is.readLine());
+ }
+ }
+
+ @Test
+ public void testEmpty() throws IOException {
+ for (String s : empty) {
+ LineInputStream is = createStream(s);
+ assertEquals("", is.readLine());
+ assertEquals("", is.readLine());
+ assertEquals("", is.readLine());
+ assertEquals(null, is.readLine());
+ }
+ }
+
+ @Test
+ public void testMixed() throws IOException {
+ for (String s : mixed) {
+ LineInputStream is = createStream(s);
+ assertEquals("line1", is.readLine());
+ assertEquals("", is.readLine());
+ assertEquals("line3", is.readLine());
+ assertEquals(null, is.readLine());
+ }
+ }
+
+ private LineInputStream createStream(String s) {
+ try {
+ return new LineInputStream(
+ new ByteArrayInputStream(s.getBytes("us-ascii")));
+ } catch (UnsupportedEncodingException ex) {
+ return null; // should never happen
+ }
+ }
+}