commits@javamail.java.net

[javamail~mercurial:443] Skip bogus space inserted by Yahoo IMAP server when reading emails contai

From: <shannon_at_kenai.com>
Date: Thu, 3 May 2012 07:50:11 +0000

Project: javamail
Repository: mercurial
Revision: 443
Author: shannon
Date: 2012-05-03 00:29:10 UTC
Link:

Log Message:
------------
Update version to 1.4.6-SNAPSHOT.
Update copyright date.
Update to latest version of osgiversion-maven-plugin, to remove
dependency on maven.galssfish.org.
Ensure that socket is closed when connecting to server with no supported
authentication mechanisms. Bug 4906
Update to build with Maven 3 - have to specify all versions explicitly.
STARTTLS when already using SSL may cause connection to fail - Kenai bug 5086
Skip bogus space inserted by Yahoo IMAP server when reading emails containing
"undisclosed recipients" - Kenai bug 5090


Revisions:
----------
437
438
439
440
441
442
443


Modified Paths:
---------------
client/pom.xml
demo/pom.xml
dsn/pom.xml
imap/pom.xml
javadoc/pom.xml
logging/pom.xml
mail/pom.xml
mailapi/pom.xml
mailapijar/pom.xml
mbox/dist/pom.xml
mbox/native/pom.xml
mbox/pom.xml
oldmail/pom.xml
outlook/pom.xml
parent-distrib/pom.xml
pom.xml
pop3/pom.xml
servlet/pom.xml
smtp/pom.xml
taglib/pom.xml
webapp/pom.xml
doc/release/COPYRIGHT.txt
doc/release/CHANGES.txt
mail/src/main/java/com/sun/mail/imap/IMAPStore.java
mail/src/test/java/com/sun/mail/imap/IMAPHandler.java
mail/src/main/java/com/sun/mail/iap/Protocol.java
mail/src/main/java/com/sun/mail/pop3/Protocol.java
mail/src/main/java/com/sun/mail/smtp/SMTPTransport.java
mail/src/main/java/com/sun/mail/imap/protocol/ENVELOPE.java
mail/src/main/java/com/sun/mail/imap/protocol/IMAPResponse.java


Added Paths:
------------
mail/src/test/java/com/sun/mail/imap/IMAPLoginFailureTest.java
mail/src/test/java/com/sun/mail/test/SavedSocketFactory.java
mail/src/test/java/com/sun/mail/imap/protocol/EnvelopeTest.java


Diffs:
------
diff -r 42b6d8c53009 -r 6ddc2bc65ab8 client/pom.xml
--- a/client/pom.xml Fri Mar 23 14:31:07 2012 -0700
+++ b/client/pom.xml Mon Mar 26 15:52:31 2012 -0700
@@ -48,7 +48,7 @@
     <parent>
         <groupId>com.sun.mail</groupId>
         <artifactId>all</artifactId>
- <version>1.4.5</version>
+ <version>1.4.6-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
     <groupId>com.sun.mail</groupId>

diff -r 42b6d8c53009 -r 6ddc2bc65ab8 demo/pom.xml
--- a/demo/pom.xml Fri Mar 23 14:31:07 2012 -0700
+++ b/demo/pom.xml Mon Mar 26 15:52:31 2012 -0700
@@ -48,7 +48,7 @@
     <parent>
         <groupId>com.sun.mail</groupId>
         <artifactId>all</artifactId>
- <version>1.4.5</version>
+ <version>1.4.6-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
     <groupId>com.sun.mail</groupId>

diff -r 42b6d8c53009 -r 6ddc2bc65ab8 dsn/pom.xml
--- a/dsn/pom.xml Fri Mar 23 14:31:07 2012 -0700
+++ b/dsn/pom.xml Mon Mar 26 15:52:31 2012 -0700
@@ -48,7 +48,7 @@
     <parent>
         <groupId>com.sun.mail</groupId>
         <artifactId>all</artifactId>
- <version>1.4.5</version>
+ <version>1.4.6-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
     <groupId>com.sun.mail</groupId>

diff -r 42b6d8c53009 -r 6ddc2bc65ab8 imap/pom.xml
--- a/imap/pom.xml Fri Mar 23 14:31:07 2012 -0700
+++ b/imap/pom.xml Mon Mar 26 15:52:31 2012 -0700
@@ -48,7 +48,7 @@
     <parent>
         <groupId>com.sun.mail</groupId>
         <artifactId>parent-distrib</artifactId>
- <version>1.4.5</version>
+ <version>1.4.6-SNAPSHOT</version>
         <relativePath>../parent-distrib/pom.xml</relativePath>
     </parent>
     <modelVersion>4.0.0</modelVersion>

diff -r 42b6d8c53009 -r 6ddc2bc65ab8 javadoc/pom.xml
--- a/javadoc/pom.xml Fri Mar 23 14:31:07 2012 -0700
+++ b/javadoc/pom.xml Mon Mar 26 15:52:31 2012 -0700
@@ -48,13 +48,13 @@
     <parent>
         <groupId>com.sun.mail</groupId>
         <artifactId>all</artifactId>
- <version>1.4.5</version>
+ <version>1.4.6-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
     <groupId>com.sun.mail</groupId>
     <artifactId>javadoc</artifactId>
     <packaging>pom</packaging>
- <version>1.4.5</version>
+ <version>1.4.6-SNAPSHOT</version>
     <name>JavaMail API javadocs</name>
     <description>${project.name}</description>
 

diff -r 42b6d8c53009 -r 6ddc2bc65ab8 logging/pom.xml
--- a/logging/pom.xml Fri Mar 23 14:31:07 2012 -0700
+++ b/logging/pom.xml Mon Mar 26 15:52:31 2012 -0700
@@ -48,7 +48,7 @@
     <parent>
         <groupId>com.sun.mail</groupId>
         <artifactId>all</artifactId>
- <version>1.4.5</version>
+ <version>1.4.6-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
     <groupId>com.sun.mail</groupId>

diff -r 42b6d8c53009 -r 6ddc2bc65ab8 mail/pom.xml
--- a/mail/pom.xml Fri Mar 23 14:31:07 2012 -0700
+++ b/mail/pom.xml Mon Mar 26 15:52:31 2012 -0700
@@ -48,7 +48,7 @@
     <parent>
         <groupId>com.sun.mail</groupId>
         <artifactId>all</artifactId>
- <version>1.4.5</version>
+ <version>1.4.6-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
     <groupId>com.sun.mail</groupId>

diff -r 42b6d8c53009 -r 6ddc2bc65ab8 mailapi/pom.xml
--- a/mailapi/pom.xml Fri Mar 23 14:31:07 2012 -0700
+++ b/mailapi/pom.xml Mon Mar 26 15:52:31 2012 -0700
@@ -56,7 +56,7 @@
     <parent>
         <groupId>com.sun.mail</groupId>
         <artifactId>all</artifactId>
- <version>1.4.5</version>
+ <version>1.4.6-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
     <groupId>com.sun.mail</groupId>

diff -r 42b6d8c53009 -r 6ddc2bc65ab8 mailapijar/pom.xml
--- a/mailapijar/pom.xml Fri Mar 23 14:31:07 2012 -0700
+++ b/mailapijar/pom.xml Mon Mar 26 15:52:31 2012 -0700
@@ -55,7 +55,7 @@
     <parent>
         <groupId>com.sun.mail</groupId>
         <artifactId>all</artifactId>
- <version>1.4.5</version>
+ <version>1.4.6-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
     <groupId>javax.mail</groupId>

diff -r 42b6d8c53009 -r 6ddc2bc65ab8 mbox/dist/pom.xml
--- a/mbox/dist/pom.xml Fri Mar 23 14:31:07 2012 -0700
+++ b/mbox/dist/pom.xml Mon Mar 26 15:52:31 2012 -0700
@@ -48,7 +48,7 @@
     <parent>
         <groupId>com.sun.mail</groupId>
         <artifactId>all</artifactId>
- <version>1.4.5</version>
+ <version>1.4.6-SNAPSHOT</version>
         <relativePath>../../pom.xml</relativePath>
     </parent>
     <modelVersion>4.0.0</modelVersion>

diff -r 42b6d8c53009 -r 6ddc2bc65ab8 mbox/native/pom.xml
--- a/mbox/native/pom.xml Fri Mar 23 14:31:07 2012 -0700
+++ b/mbox/native/pom.xml Mon Mar 26 15:52:31 2012 -0700
@@ -48,7 +48,7 @@
     <parent>
         <groupId>com.sun.mail</groupId>
         <artifactId>all</artifactId>
- <version>1.4.5</version>
+ <version>1.4.6-SNAPSHOT</version>
         <relativePath>../../pom.xml</relativePath>
     </parent>
     <modelVersion>4.0.0</modelVersion>

diff -r 42b6d8c53009 -r 6ddc2bc65ab8 mbox/pom.xml
--- a/mbox/pom.xml Fri Mar 23 14:31:07 2012 -0700
+++ b/mbox/pom.xml Mon Mar 26 15:52:31 2012 -0700
@@ -48,7 +48,7 @@
     <parent>
         <groupId>com.sun.mail</groupId>
         <artifactId>all</artifactId>
- <version>1.4.5</version>
+ <version>1.4.6-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
     <groupId>com.sun.mail</groupId>

diff -r 42b6d8c53009 -r 6ddc2bc65ab8 oldmail/pom.xml
--- a/oldmail/pom.xml Fri Mar 23 14:31:07 2012 -0700
+++ b/oldmail/pom.xml Mon Mar 26 15:52:31 2012 -0700
@@ -53,7 +53,7 @@
     <parent>
         <groupId>com.sun.mail</groupId>
         <artifactId>all</artifactId>
- <version>1.4.5</version>
+ <version>1.4.6-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
     <groupId>javax.mail</groupId>

diff -r 42b6d8c53009 -r 6ddc2bc65ab8 outlook/pom.xml
--- a/outlook/pom.xml Fri Mar 23 14:31:07 2012 -0700
+++ b/outlook/pom.xml Mon Mar 26 15:52:31 2012 -0700
@@ -48,7 +48,7 @@
     <parent>
         <groupId>com.sun.mail</groupId>
         <artifactId>all</artifactId>
- <version>1.4.5</version>
+ <version>1.4.6-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
     <groupId>com.sun.mail</groupId>

diff -r 42b6d8c53009 -r 6ddc2bc65ab8 parent-distrib/pom.xml
--- a/parent-distrib/pom.xml Fri Mar 23 14:31:07 2012 -0700
+++ b/parent-distrib/pom.xml Mon Mar 26 15:52:31 2012 -0700
@@ -48,7 +48,7 @@
     <parent>
         <groupId>com.sun.mail</groupId>
         <artifactId>all</artifactId>
- <version>1.4.5</version>
+ <version>1.4.6-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
     <groupId>com.sun.mail</groupId>

diff -r 42b6d8c53009 -r 6ddc2bc65ab8 pom.xml
--- a/pom.xml Fri Mar 23 14:31:07 2012 -0700
+++ b/pom.xml Mon Mar 26 15:52:31 2012 -0700
@@ -54,7 +54,7 @@
     <groupId>com.sun.mail</groupId>
     <artifactId>all</artifactId>
     <packaging>pom</packaging>
- <version>1.4.5</version>
+ <version>1.4.6-SNAPSHOT</version>
     <name>JavaMail API distribution</name>
     <description>${project.name}</description>
     <url>http://kenai.com/projects/javamail</url>
@@ -91,9 +91,9 @@
     </organization>
 
     <properties>
- <mail.version>1.4.5</mail.version>
+ <mail.version>1.4.6-SNAPSHOT</mail.version>
         <!-- like mail.version, but with underscores instead of dots -->
- <mail.zipversion>1_4_5</mail.zipversion>
+ <mail.zipversion>1_4_6-SNAPSHOT</mail.zipversion>
         <mail.spec.version>1.4</mail.spec.version>
         <activation-api.version>1.1</activation-api.version>
         <!-- defaults that are overridden in mail module -->

diff -r 42b6d8c53009 -r 6ddc2bc65ab8 pop3/pom.xml
--- a/pop3/pom.xml Fri Mar 23 14:31:07 2012 -0700
+++ b/pop3/pom.xml Mon Mar 26 15:52:31 2012 -0700
@@ -48,7 +48,7 @@
     <parent>
         <groupId>com.sun.mail</groupId>
         <artifactId>parent-distrib</artifactId>
- <version>1.4.5</version>
+ <version>1.4.6-SNAPSHOT</version>
         <relativePath>../parent-distrib/pom.xml</relativePath>
     </parent>
     <modelVersion>4.0.0</modelVersion>

diff -r 42b6d8c53009 -r 6ddc2bc65ab8 servlet/pom.xml
--- a/servlet/pom.xml Fri Mar 23 14:31:07 2012 -0700
+++ b/servlet/pom.xml Mon Mar 26 15:52:31 2012 -0700
@@ -48,7 +48,7 @@
     <parent>
         <groupId>com.sun.mail</groupId>
         <artifactId>all</artifactId>
- <version>1.4.5</version>
+ <version>1.4.6-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
     <groupId>com.sun.mail</groupId>

diff -r 42b6d8c53009 -r 6ddc2bc65ab8 smtp/pom.xml
--- a/smtp/pom.xml Fri Mar 23 14:31:07 2012 -0700
+++ b/smtp/pom.xml Mon Mar 26 15:52:31 2012 -0700
@@ -48,7 +48,7 @@
     <parent>
         <groupId>com.sun.mail</groupId>
         <artifactId>parent-distrib</artifactId>
- <version>1.4.5</version>
+ <version>1.4.6-SNAPSHOT</version>
         <relativePath>../parent-distrib/pom.xml</relativePath>
     </parent>
     <modelVersion>4.0.0</modelVersion>

diff -r 42b6d8c53009 -r 6ddc2bc65ab8 taglib/pom.xml
--- a/taglib/pom.xml Fri Mar 23 14:31:07 2012 -0700
+++ b/taglib/pom.xml Mon Mar 26 15:52:31 2012 -0700
@@ -48,7 +48,7 @@
     <parent>
         <groupId>com.sun.mail</groupId>
         <artifactId>all</artifactId>
- <version>1.4.5</version>
+ <version>1.4.6-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
     <groupId>com.sun.mail</groupId>

diff -r 42b6d8c53009 -r 6ddc2bc65ab8 webapp/pom.xml
--- a/webapp/pom.xml Fri Mar 23 14:31:07 2012 -0700
+++ b/webapp/pom.xml Mon Mar 26 15:52:31 2012 -0700
@@ -48,7 +48,7 @@
     <parent>
         <groupId>com.sun.mail</groupId>
         <artifactId>all</artifactId>
- <version>1.4.5</version>
+ <version>1.4.6-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
     <groupId>com.sun.mail</groupId>


diff -r 6ddc2bc65ab8 -r 640252cf66f6 doc/release/COPYRIGHT.txt
--- a/doc/release/COPYRIGHT.txt Mon Mar 26 15:52:31 2012 -0700
+++ b/doc/release/COPYRIGHT.txt Tue Mar 27 12:12:40 2012 -0700
@@ -1,4 +1,4 @@
-Copyright © 1997-2011, Oracle and/or its affiliates. All rights reserved.
+Copyright © 1997-2012, Oracle and/or its affiliates. All rights reserved.
 
 This software and related documentation are provided under a license
 agreement containing restrictions on use and disclosure and are


diff -r 640252cf66f6 -r 2fbc97fa8d12 pom.xml
--- a/pom.xml Tue Mar 27 12:12:40 2012 -0700
+++ b/pom.xml Wed Apr 11 15:01:28 2012 -0700
@@ -122,7 +122,7 @@
         </mail.packages.private>
         <mail.probeFile/>
         <!-- for the osgiversion-maven-plugin -->
- <hk2.plugin.version>0.4.11</hk2.plugin.version>
+ <hk2.plugin.version>2.0.0</hk2.plugin.version>
         <javac.path>/opt/jdk1.4/bin/javac</javac.path>
         <project.build.sourceEncoding>iso-8859-1</project.build.sourceEncoding>
         <findbugs.threshold>
@@ -399,7 +399,7 @@
                 version without the qualifier.
             -->
             <plugin>
- <groupId>com.sun.enterprise</groupId>
+ <groupId>org.glassfish.hk2</groupId>
                 <artifactId>osgiversion-maven-plugin</artifactId>
                 <version>${hk2.plugin.version}</version>
                 <configuration>


diff -r 2fbc97fa8d12 -r 8384ffa6cb2c doc/release/CHANGES.txt
--- a/doc/release/CHANGES.txt Wed Apr 11 15:01:28 2012 -0700
+++ b/doc/release/CHANGES.txt Thu Apr 19 14:36:36 2012 -0700
@@ -14,6 +14,13 @@
         https://kenai.com/bugzilla/
 
 
+ CHANGES IN THE 1.4.6 RELEASE
+ ----------------------------
+The following bugs have been fixed in the 1.4.6 release.
+
+K 4906 IMAP Store socket leak on connect with ProtocolException
+
+
                   CHANGES IN THE 1.4.5 RELEASE
                   ----------------------------
 The following bugs have been fixed in the 1.4.5 release.

diff -r 2fbc97fa8d12 -r 8384ffa6cb2c mail/src/main/java/com/sun/mail/imap/IMAPStore.java
--- a/mail/src/main/java/com/sun/mail/imap/IMAPStore.java Wed Apr 11 15:01:28 2012 -0700
+++ b/mail/src/main/java/com/sun/mail/imap/IMAPStore.java Thu Apr 19 14:36:36 2012 -0700
@@ -665,6 +665,10 @@
             throw new AuthenticationFailedException(
                                         cex.getResponse().getRest());
         } catch (ProtocolException pex) { // any other exception
+ // failure in login command, close connection to server
+ if (protocol != null)
+ protocol.disconnect();
+ protocol = null;
             throw new MessagingException(pex.getMessage(), pex);
         } catch (IOException ioex) {
             throw new MessagingException(ioex.getMessage(), ioex);

diff -r 2fbc97fa8d12 -r 8384ffa6cb2c mail/src/test/java/com/sun/mail/imap/IMAPHandler.java
--- a/mail/src/test/java/com/sun/mail/imap/IMAPHandler.java Wed Apr 11 15:01:28 2012 -0700
+++ b/mail/src/test/java/com/sun/mail/imap/IMAPHandler.java Thu Apr 19 14:36:36 2012 -0700
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright (c) 2009-2010 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009-2012 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
@@ -210,7 +210,8 @@
         currentLine = reader.readLine();
 
         if (currentLine == null) {
- LOGGER.severe("Current line is null!");
+ // probably just EOF because the socket was closed
+ //LOGGER.severe("Current line is null!");
             exit();
             return;
         }

diff -r 2fbc97fa8d12 -r 8384ffa6cb2c mail/src/test/java/com/sun/mail/imap/IMAPLoginFailureTest.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mail/src/test/java/com/sun/mail/imap/IMAPLoginFailureTest.java Thu Apr 19 14:36:36 2012 -0700
@@ -0,0 +1,112 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright (c) 2009-2012 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.imap;
+
+import java.io.*;
+import java.util.Properties;
+
+import javax.mail.Session;
+import javax.mail.Store;
+import javax.mail.MessagingException;
+
+import com.sun.mail.test.SavedSocketFactory;
+
+import org.junit.Test;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.fail;
+
+/**
+ * Test that login failures are handled correctly.
+ */
+public final class IMAPLoginFailureTest {
+
+ /**
+ * Test that login failures when no login methods are supported
+ * cause the socket to be closed.
+ */
+ @Test
+ public void testSocketClosed() {
+ IMAPServer server = null;
+ try {
+ final IMAPHandler handler = new IMAPHandler() {
+ public void sendGreetings() throws IOException {
+ capabilities = "IMAP4REV1 LOGINDISABLED";
+ super.sendGreetings();
+ }
+ };
+ server = new IMAPServer(handler, 26422);
+ server.start();
+ Thread.sleep(1000);
+
+ SavedSocketFactory ssf = new SavedSocketFactory();
+ Properties properties = new Properties();
+ properties.setProperty("mail.imap.host", "localhost");
+ properties.setProperty("mail.imap.port", "26422");
+ properties.put("mail.imap.socketFactory", ssf);
+ final Session session = Session.getInstance(properties);
+ //session.setDebug(true);
+
+ final Store store = session.getStore("imap");
+ try {
+ store.connect("test", "test");
+ fail("login did not fail");
+ } catch (MessagingException mex) {
+ // this is what we expect, now check that the socket is closed
+ assertTrue(ssf.getSocket().isClosed());
+ } catch (Exception ex) {
+ System.out.println(ex);
+ //ex.printStackTrace();
+ fail(ex.toString());
+ } finally {
+ store.close();
+ }
+
+ } catch (final Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ } finally {
+ if (server != null) {
+ server.quit();
+ }
+ }
+ }
+}

diff -r 2fbc97fa8d12 -r 8384ffa6cb2c mail/src/test/java/com/sun/mail/test/SavedSocketFactory.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mail/src/test/java/com/sun/mail/test/SavedSocketFactory.java Thu Apr 19 14:36:36 2012 -0700
@@ -0,0 +1,99 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright (c) 2012 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.test;
+
+import java.io.IOException;
+import java.net.Socket;
+import java.net.InetAddress;
+import javax.net.SocketFactory;
+
+/**
+ * A SocketFactory that saves the Socket it creates so that it can be
+ * accessed later. Useful for checking that sockets are closed properly.
+ */
+public class SavedSocketFactory extends SocketFactory {
+ private SocketFactory factory;
+ private Socket saved;
+
+ public SavedSocketFactory() {
+ super();
+ try {
+ factory = SocketFactory.getDefault();
+ } catch(Exception ex) {
+ // ignore
+ }
+ }
+
+ public Socket createSocket() throws IOException {
+ return save(factory.createSocket());
+ }
+
+ public Socket createSocket(InetAddress host, int port)
+ throws IOException {
+ return save(factory.createSocket(host, port));
+ }
+
+ public Socket createSocket(InetAddress address, int port,
+ InetAddress localAddress, int localPort)
+ throws IOException {
+ return save(factory.createSocket(
+ address, port, localAddress, localPort));
+ }
+
+ public Socket createSocket(String host, int port) throws IOException {
+ return save(factory.createSocket(host, port));
+ }
+
+ public Socket createSocket(String host, int port,
+ InetAddress localHost, int localPort)
+ throws IOException {
+ return save(factory.createSocket(host, port, localHost, localPort));
+ }
+
+ public Socket getSocket() {
+ return saved;
+ }
+
+ private Socket save(Socket s) {
+ saved = s;
+ return saved;
+ }
+}


diff -r 8384ffa6cb2c -r 5ffd683d1b99 pom.xml
--- a/pom.xml Thu Apr 19 14:36:36 2012 -0700
+++ b/pom.xml Tue May 01 12:26:19 2012 -0700
@@ -129,7 +129,7 @@
             High
         </findbugs.threshold>
         <findbugs.version>
- RELEASE
+ 2.4.0
         </findbugs.version>
         <findbugs.skip>
             true
@@ -582,6 +582,26 @@
         <pluginManagement>
             <plugins>
                 <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.0.2</version>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>2.4.3</version>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>2.4</version>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ <version>1.7</version>
+ </plugin>
+ <plugin>
                     <!--
                         By default, disable the FindBugs plugin for all modules.
                         It's enabled in the modules where we actually want to
@@ -670,6 +690,7 @@
             <plugin>
                 <groupId>org.codehaus.mojo</groupId>
                 <artifactId>findbugs-maven-plugin</artifactId>
+ <version>${findbugs.version}</version>
                 <configuration>
                     <skip>${findbugs.skip}</skip>
                     <threshold>${findbugs.threshold}</threshold>


diff -r 5ffd683d1b99 -r 73f399b2ae4c doc/release/CHANGES.txt
--- a/doc/release/CHANGES.txt Tue May 01 12:26:19 2012 -0700
+++ b/doc/release/CHANGES.txt Tue May 01 13:02:03 2012 -0700
@@ -19,6 +19,7 @@
 The following bugs have been fixed in the 1.4.6 release.
 
 K 4906 IMAP Store socket leak on connect with ProtocolException
+K 5086 STARTTLS when already using SSL may cause connection to fail
 
 
                   CHANGES IN THE 1.4.5 RELEASE

diff -r 5ffd683d1b99 -r 73f399b2ae4c mail/src/main/java/com/sun/mail/iap/Protocol.java
--- a/mail/src/main/java/com/sun/mail/iap/Protocol.java Tue May 01 12:26:19 2012 -0700
+++ b/mail/src/main/java/com/sun/mail/iap/Protocol.java Tue May 01 13:02:03 2012 -0700
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright (c) 1997-2011 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997-2012 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
@@ -44,6 +44,7 @@
 import java.util.Properties;
 import java.io.*;
 import java.net.*;
+import javax.net.ssl.SSLSocket;
 import com.sun.mail.util.*;
 
 /**
@@ -377,9 +378,13 @@
      * Start TLS on the current connection.
      * <code>cmd</code> is the command to issue to start TLS negotiation.
      * If the command succeeds, we begin TLS negotiation.
+ * If the socket is already an SSLSocket this is a nop and the command
+ * is not issued.
      */
     public synchronized void startTLS(String cmd)
                                 throws IOException, ProtocolException {
+ if (socket instanceof SSLSocket)
+ return; // nothing to do
         simpleCommand(cmd, null);
         socket = SocketFetcher.startTLS(socket, host, props, prefix);
         initStreams(out);

diff -r 5ffd683d1b99 -r 73f399b2ae4c mail/src/main/java/com/sun/mail/pop3/Protocol.java
--- a/mail/src/main/java/com/sun/mail/pop3/Protocol.java Tue May 01 12:26:19 2012 -0700
+++ b/mail/src/main/java/com/sun/mail/pop3/Protocol.java Tue May 01 13:02:03 2012 -0700
@@ -642,8 +642,11 @@
 
     /**
      * Start TLS using STLS command specified by RFC 2595.
+ * If already using SSL, this is a nop and the STLS command is not issued.
      */
     synchronized boolean stls() throws IOException {
+ if (socket instanceof SSLSocket)
+ return true; // nothing to do
         Response r = simpleCommand("STLS");
         if (r.ok) {
             // it worked, now switch the socket into TLS mode

diff -r 5ffd683d1b99 -r 73f399b2ae4c mail/src/main/java/com/sun/mail/smtp/SMTPTransport.java
--- a/mail/src/main/java/com/sun/mail/smtp/SMTPTransport.java Tue May 01 12:26:19 2012 -0700
+++ b/mail/src/main/java/com/sun/mail/smtp/SMTPTransport.java Tue May 01 13:02:03 2012 -0700
@@ -44,6 +44,7 @@
 import java.net.*;
 import java.util.*;
 import java.lang.reflect.*;
+import javax.net.ssl.SSLSocket;
 
 import javax.mail.*;
 import javax.mail.event.*;
@@ -648,7 +649,11 @@
                 helo(getLocalHost());
 
             if (useStartTLS || requireStartTLS) {
- if (supportsExtension("STARTTLS")) {
+ if (serverSocket instanceof SSLSocket) {
+ if (debug)
+ out.println(
+ "DEBUG SMTP: STARTTLS requested but already using SSL");
+ } else if (supportsExtension("STARTTLS")) {
                     startTLS();
                     /*
                      * Have to issue another EHLO to update list of extensions


diff -r 73f399b2ae4c -r 0fb22a2395e9 doc/release/CHANGES.txt
--- a/doc/release/CHANGES.txt Tue May 01 13:02:03 2012 -0700
+++ b/doc/release/CHANGES.txt Wed May 02 17:29:10 2012 -0700
@@ -20,6 +20,7 @@
 
 K 4906 IMAP Store socket leak on connect with ProtocolException
 K 5086 STARTTLS when already using SSL may cause connection to fail
+K 5090 Yahoo: Error reading emails containing "undisclosed recipients"
 
 
                   CHANGES IN THE 1.4.5 RELEASE

diff -r 73f399b2ae4c -r 0fb22a2395e9 mail/src/main/java/com/sun/mail/imap/protocol/ENVELOPE.java
--- a/mail/src/main/java/com/sun/mail/imap/protocol/ENVELOPE.java Tue May 01 13:02:03 2012 -0700
+++ b/mail/src/main/java/com/sun/mail/imap/protocol/ENVELOPE.java Wed May 02 17:29:10 2012 -0700
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997-2012 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
@@ -158,6 +158,9 @@
         r.readString(); // throw away address_list
         String mb = r.readString();
         String host = r.readString();
+ // skip bogus spaces inserted by Yahoo IMAP server if
+ // "undisclosed-recipients" is a recipient
+ r.skipSpaces();
         if (r.readByte() != ')') // skip past terminating ')'
             throw new ParsingException("ADDRESS parse error");
 

diff -r 73f399b2ae4c -r 0fb22a2395e9 mail/src/main/java/com/sun/mail/imap/protocol/IMAPResponse.java
--- a/mail/src/main/java/com/sun/mail/imap/protocol/IMAPResponse.java Tue May 01 13:02:03 2012 -0700
+++ b/mail/src/main/java/com/sun/mail/imap/protocol/IMAPResponse.java Wed May 02 17:29:10 2012 -0700
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997-2012 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
@@ -58,7 +58,10 @@
 
     public IMAPResponse(Protocol c) throws IOException, ProtocolException {
         super(c);
+ init();
+ }
 
+ private void init() throws IOException, ProtocolException {
         // continue parsing if this is an untagged response
         if (isUnTagged() && !isOK() && !isNO() && !isBAD() && !isBYE()) {
             key = readAtom();
@@ -81,6 +84,14 @@
     }
 
     /**
+ * For testing.
+ */
+ public IMAPResponse(String r) throws IOException, ProtocolException {
+ super(r);
+ init();
+ }
+
+ /**
      * Read a list of space-separated "flag_extension" sequences and
      * return the list as a array of Strings. An empty list is returned
      * as null. This is an IMAP-ism, and perhaps this method should

diff -r 73f399b2ae4c -r 0fb22a2395e9 mail/src/test/java/com/sun/mail/imap/protocol/EnvelopeTest.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mail/src/test/java/com/sun/mail/imap/protocol/EnvelopeTest.java Wed May 02 17:29:10 2012 -0700
@@ -0,0 +1,74 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright (c) 2012 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.imap.protocol;
+
+import com.sun.mail.iap.Response;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+import org.junit.Test;
+
+/**
+ * Test the ENVELOPE class.
+ */
+public class EnvelopeTest {
+ /**
+ * Test workaround for Yahoo IMAP bug that returns a bogus space
+ * character when one of the recipients is "undisclosed-recipients".
+ */
+ @Test
+ public void testYahooUndisclosedRecipientsBug() throws Exception {
+ IMAPResponse response =
+ new IMAPResponse(
+ "* 2 FETCH (INTERNALDATE \"24-Apr-2012 20:28:58 +0000\" " +
+ "RFC822.SIZE 155937 " +
+ "ENVELOPE (\"Wed, 28 Sep 2011 11:16:17 +0100\" \"test\" " +
+ "((NIL NIL \"xxx\" \"tju.edu.cn\")) " +
+ "((NIL NIL \"xxx\" \"gmail.com\")) " +
+ "((NIL NIL \"xxx\" \"tju.edu.cn\")) " +
+ "((\"undisclosed-recipients\" NIL " +
+ "\"\\\"undisclosed-recipients\\\"\" NIL )) " +
+ // here's the space inserted by Yahoo IMAP ^
+ "NIL NIL NIL " +
+ "\"<xxx_at_mail.gmail.com>\"))");
+ FetchResponse fr = new FetchResponse(response);
+ // no exception means it worked
+ }
+}