commits@javamail.java.net

[javamail~mercurial:408] Fixed bug 3815 - ArrayIndexOutOfBoundsException for some IMAP protocol er

From: <shannon_at_kenai.com>
Date: Tue, 17 Jan 2012 23:51:52 +0000

Project: javamail
Repository: mercurial
Revision: 408
Author: shannon
Date: 2012-01-17 23:46:32 UTC
Link:

Log Message:
------------
No longer need an optional import for jcifs since it's not used at all.
Updates from Jason:

FileErrorManager raw emails are ASCII.
MailHandler use handler encoding for fallback stacktrace.
MailHandlerDemo use Arrays.asList to comply with JDK 1.4
MailHandlerTest declare encoding and decoding of bytes.
Fix copyright year.
Fix license - should be BSD.
Removed unneeded (and wrong) <taglib> element.
Add mail.mbox.homerelative property (default false) to control whether
folder names are relative to the user's home directory or the current
directory. This provides more compatibility with mailx.
Support multiple lock types, controlled by mail.mbox.locktype system property.
Possible values are "native" (default), "java", and "none".
Avoid ArrayIndexOutOfBoundsException if a terminating quote is missing.
Fixed bug 3815 - ArrayIndexOutOfBoundsException for some IMAP protocol errors
(forgot to add entry)


Revisions:
----------
401
402
403
404
405
406
407
408


Modified Paths:
---------------
pom.xml
logging/src/main/java/FileErrorManager.java
logging/src/main/java/MailHandlerDemo.java
mail/src/main/java/com/sun/mail/util/logging/MailHandler.java
mail/src/test/java/com/sun/mail/util/logging/MailHandlerTest.java
mail/src/main/java/javax/mail/internet/InternetAddress.java
webapp/src/main/webapp/WEB-INF/web.xml
mbox/src/main/java/com/sun/mail/mbox/DefaultMailbox.java
mbox/src/main/java/com/sun/mail/mbox/MboxFolder.java
mbox/src/main/java/com/sun/mail/mbox/SolarisMailbox.java
mbox/src/main/java/com/sun/mail/mbox/UNIXFile.java
mbox/src/main/java/com/sun/mail/mbox/UNIXFolder.java
mbox/src/main/java/com/sun/mail/mbox/UNIXInbox.java
mail/src/main/java/com/sun/mail/iap/Response.java
doc/release/CHANGES.txt


Diffs:
------
diff -r 3fe01175a4f2 -r bac560ae4374 pom.xml
--- a/pom.xml Mon Dec 05 21:10:14 2011 -0800
+++ b/pom.xml Mon Dec 19 16:10:32 2011 -0800
@@ -115,7 +115,6 @@
         <mail.packages.import>
             javax.security.sasl;resolution:=optional,
             sun.security.util;resolution:=optional,
- jcifs.ntlmssp;resolution:=optional,
             *
         </mail.packages.import>
         <mail.packages.private>


diff -r bac560ae4374 -r 43f9e9fcaa8a logging/src/main/java/FileErrorManager.java
--- a/logging/src/main/java/FileErrorManager.java Mon Dec 19 16:10:32 2011 -0800
+++ b/logging/src/main/java/FileErrorManager.java Fri Jan 13 15:51:52 2012 -0800
@@ -1,6 +1,6 @@
 /*
- * Copyright (c) 2009-2011 Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2009-2011 Jason Mehrens. All Rights Reserved.
+ * Copyright (c) 2009-2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009-2012 Jason Mehrens. All Rights Reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -191,8 +191,9 @@
             }
         }
 
- try {
- PrintStream ps = new PrintStream(new NewlineOutputStream(out));
+ try { //Raw email is ASCII.
+ PrintStream ps = new PrintStream(
+ new NewlineOutputStream(out), false, "US-ASCII");
             ps.print(email);
             ps.flush();
             tmp = null; //Don't delete 'tmp' if all bytes were written.

diff -r bac560ae4374 -r 43f9e9fcaa8a logging/src/main/java/MailHandlerDemo.java
--- a/logging/src/main/java/MailHandlerDemo.java Mon Dec 19 16:10:32 2011 -0800
+++ b/logging/src/main/java/MailHandlerDemo.java Fri Jan 13 15:51:52 2012 -0800
@@ -1,6 +1,6 @@
 /*
- * Copyright (c) 2009-2010 Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2009-2010 Jason Mehrens. All Rights Reserved.
+ * Copyright (c) 2009-2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009-2012 Jason Mehrens. All Rights Reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -126,9 +126,9 @@
             String to = manager.getProperty(key);
             err.println(prefix + ": TO=" + to);
             err.println(prefix + ": TO="
- + Arrays.toString(InternetAddress.parse(to, false)));
+ + Arrays.asList(InternetAddress.parse(to, false)));
             err.println(prefix + ": TO="
- + Arrays.toString(InternetAddress.parse(to, true)));
+ + Arrays.asList(InternetAddress.parse(to, true)));
 
             key = p.concat(".mail.from");
             String from = manager.getProperty(key);
@@ -138,9 +138,9 @@
                 err.println(prefix + ": FROM=" + local);
             } else {
                 err.println(prefix + ": FROM="
- + Arrays.toString(InternetAddress.parse(from, false)));
+ + Arrays.asList(InternetAddress.parse(from, false)));
                 err.println(prefix + ": FROM="
- + Arrays.toString(InternetAddress.parse(from, true)));
+ + Arrays.asList(InternetAddress.parse(from, true)));
             }
         } catch (Throwable error) {
             err.print(prefix + ": ");

diff -r bac560ae4374 -r 43f9e9fcaa8a mail/src/main/java/com/sun/mail/util/logging/MailHandler.java
--- a/mail/src/main/java/com/sun/mail/util/logging/MailHandler.java Mon Dec 19 16:10:32 2011 -0800
+++ b/mail/src/main/java/com/sun/mail/util/logging/MailHandler.java Fri Jan 13 15:51:52 2012 -0800
@@ -1,8 +1,8 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright (c) 2009-2011 Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2009-2011 Jason Mehrens. All rights reserved.
+ * Copyright (c) 2009-2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009-2012 Jason Mehrens. 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
@@ -2789,8 +2789,7 @@
     }
 
     /**
- * Converts a throwable to a message string. This method is called when
- * Message.writeTo throws an exception.
+ * Converts a throwable to a message string.
      * @param t any throwable or null.
      * @return the throwable with a stack trace or the literal null.
      */
@@ -2798,15 +2797,27 @@
         if (t == null) {
            return "null";
         }
-
- final ByteArrayOutputStream out =
- new ByteArrayOutputStream(MIN_HEADER_SIZE);
- final PrintStream ps = new PrintStream(out);
- ps.println(t.getMessage());
- t.printStackTrace(ps);
- ps.flush();
- ps.close(); //BUG ID 6995537
- return out.toString();
+
+ String encoding = getEncoding();
+ if (encoding == null) {
+ encoding = MimeUtility.getDefaultJavaCharset();
+ }
+
+ try {
+ final ByteArrayOutputStream out =
+ new ByteArrayOutputStream(MIN_HEADER_SIZE);
+
+ //Create an output stream writer so streams are not double buffered.
+ final PrintWriter pw =
+ new PrintWriter(new OutputStreamWriter(out, encoding));
+ pw.println(t.getMessage());
+ t.printStackTrace(pw);
+ pw.flush();
+ pw.close(); //BUG ID 6995537
+ return out.toString(encoding);
+ } catch (IOException IOE) { //Should not happen.
+ return t.toString() + ' ' + IOE.toString();
+ }
     }
 
     private static RuntimeException attachmentMismatch(final String msg) {

diff -r bac560ae4374 -r 43f9e9fcaa8a mail/src/test/java/com/sun/mail/util/logging/MailHandlerTest.java
--- a/mail/src/test/java/com/sun/mail/util/logging/MailHandlerTest.java Mon Dec 19 16:10:32 2011 -0800
+++ b/mail/src/test/java/com/sun/mail/util/logging/MailHandlerTest.java Fri Jan 13 15:51:52 2012 -0800
@@ -1,8 +1,8 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright (c) 2009-2011 Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2009-2011 Jason Mehrens. All rights reserved.
+ * Copyright (c) 2009-2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009-2012 Jason Mehrens. 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
@@ -3999,6 +3999,7 @@
 
     @Test
     public void testInitErrorManagerException() throws Exception {
+ final String encoding = System.getProperty("file.encoding", "8859_1");
         final String p = MailHandler.class.getName();
         final Properties props = this.createInitProperties(p);
         String key;
@@ -4012,7 +4013,7 @@
             try {
                 read(manager, props);
                 ByteArrayOutputStream oldErrors = new ByteArrayOutputStream();
- PrintStream newErr = new PrintStream(oldErrors);
+ PrintStream newErr = new PrintStream(oldErrors, false, encoding);
                 final PrintStream err = System.err;
                 System.setErr(newErr);
                 try {
@@ -4032,7 +4033,7 @@
                 //java.lang.reflect.InvocationTargetException
                 // at...
                 //Caused by: java.lang.RuntimeException
- final String data = oldErrors.toString("US-ASCII");
+ final String data = oldErrors.toString(encoding);
                 assertTrue(data, data.indexOf(ErrorManager.class.getName()) > -1);
                 int ite, re;
                 ite = data.indexOf(InvocationTargetException.class.getName());
@@ -4048,6 +4049,7 @@
 
     @Test
     public void testInitErrorManagerError() throws Exception {
+ final String encoding = System.getProperty("file.encoding", "8859_1");
         final String p = MailHandler.class.getName();
         final Properties props = this.createInitProperties(p);
         String key;
@@ -4061,7 +4063,7 @@
             try {
                 read(manager, props);
                 ByteArrayOutputStream oldErrors = new ByteArrayOutputStream();
- PrintStream newErr = new PrintStream(oldErrors);
+ PrintStream newErr = new PrintStream(oldErrors, false, encoding);
                 final PrintStream err = System.err;
                 System.setErr(newErr);
                 try {
@@ -4081,7 +4083,7 @@
                 //java.lang.reflect.InvocationTargetException
                 // at...
                 //Caused by: java.lang.Error
- final String data = oldErrors.toString("US-ASCII");
+ final String data = oldErrors.toString(encoding);
                 assertTrue(data, data.indexOf(ErrorManager.class.getName()) > -1);
                 int ite, re;
                 ite = data.indexOf(InvocationTargetException.class.getName());
@@ -4256,6 +4258,7 @@
 
     @Test
     public void testStaticInitErrorManagerException() throws Exception {
+ final String encoding = System.getProperty("file.encoding", "8859_1");
         final String test = MailHandlerTest.class.getName();
         final String p = MailHandler.class.getName();
         final Properties props = this.createInitProperties(p);
@@ -4270,7 +4273,7 @@
             try {
                 read(manager, props);
                 ByteArrayOutputStream oldErrors = new ByteArrayOutputStream();
- PrintStream newErr = new PrintStream(oldErrors);
+ PrintStream newErr = new PrintStream(oldErrors, false, encoding);
                 final PrintStream err = System.err;
                 System.setErr(newErr);
                 try {
@@ -4292,7 +4295,7 @@
                 //Caused by: java.lang.ExceptionInInitializerError
                 // at...
                 //Caused by: java.lang.RuntimeException
- final String data = oldErrors.toString("US-ASCII");
+ final String data = oldErrors.toString(encoding);
                 assertTrue(data, data.indexOf(ErrorManager.class.getName()) > -1);
                 int ite, eiie, re;
                 ite = data.indexOf(InvocationTargetException.class.getName());
@@ -4694,6 +4697,7 @@
 
     private void initBadTest(File cfg, Class<? extends MailHandler> type,
             Class[] types, Object[] params) throws Exception {
+ final String encoding = System.getProperty("file.encoding", "8859_1");
         final PrintStream err = System.err;
         ByteArrayOutputStream oldErrors = new ByteArrayOutputStream();
 
@@ -4730,7 +4734,7 @@
 
         MailHandler h = null;
         oldErrors.reset();
- System.setErr(new PrintStream(oldErrors));
+ System.setErr(new PrintStream(oldErrors, false, encoding));
         try {
             /**
              * Bad level value for property: com.sun.mail.util.logging.MailHandler.level
@@ -4740,7 +4744,7 @@
             LogManager.getLogManager().readConfiguration();
             System.err.print(""); //flushBuffer.
             System.err.flush();
- String result = oldErrors.toString().trim();
+ String result = oldErrors.toString(encoding).trim();
             oldErrors.reset();
             if (result.length() > 0) {
                 final String expect = "Bad level value for property: " + p + ".level";
@@ -4757,7 +4761,7 @@
              */
             h = type.getConstructor(types).newInstance(params);
             System.err.flush();
- result = oldErrors.toString().trim();
+ result = oldErrors.toString(encoding).trim();
             int index = result.indexOf(ErrorManager.class.getName() + ": "
                     + ErrorManager.OPEN_FAILURE + ": " + Level.SEVERE.getName()
                     + ": InvalidErrorManager");
@@ -4879,8 +4883,8 @@
             if (msg != null && msg.length() > 0
                     && !msg.startsWith(Level.SEVERE.getName())) {
                 MimeMessage message = null;
- try {
- byte[] b = msg.getBytes();
+ try { //Raw message is ascii.
+ byte[] b = msg.getBytes("US-ASCII");
                     assertTrue(b.length > 0);
 
                     ByteArrayInputStream in = new ByteArrayInputStream(b);


diff -r 43f9e9fcaa8a -r 377b01e67a88 mail/src/main/java/javax/mail/internet/InternetAddress.java
--- a/mail/src/main/java/javax/mail/internet/InternetAddress.java Fri Jan 13 15:51:52 2012 -0800
+++ b/mail/src/main/java/javax/mail/internet/InternetAddress.java Tue Jan 17 14:09:55 2012 -0800
@@ -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


diff -r 377b01e67a88 -r 780bbf94a5c8 webapp/src/main/webapp/WEB-INF/web.xml
--- a/webapp/src/main/webapp/WEB-INF/web.xml Tue Jan 17 14:09:55 2012 -0800
+++ b/webapp/src/main/webapp/WEB-INF/web.xml Tue Jan 17 14:11:34 2012 -0800
@@ -1,43 +1,34 @@
 <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
 <!--
 
- DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ Copyright (c) 2010-2012 Oracle and/or its affiliates. All rights reserved.
 
- Copyright (c) 2010 Oracle and/or its affiliates. All rights reserved.
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
 
- 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.
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
 
- When distributing the software, include this License Header Notice in each
- file and include the License file at packager/legal/LICENSE.txt.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
 
- 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.
+ - Neither the name of Oracle nor the names of its
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
 
- 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.
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 -->
 
@@ -88,10 +79,6 @@
     <servlet-name>AttachmentServlet</servlet-name>
     <url-pattern>/attachment</url-pattern>
   </servlet-mapping>
- <taglib>
- <taglib-uri>http://java.sun.com/products/javamail/demo/webapp</taglib-uri>
- <taglib-location>/WEB-INF/lib/jtl.jar</taglib-location>
- </taglib>
   <resource-ref>
     <res-ref-name>MySession</res-ref-name>
     <res-type>javax.mail.Session</res-type>


diff -r 780bbf94a5c8 -r a1f4145ab2fe mbox/src/main/java/com/sun/mail/mbox/DefaultMailbox.java
--- a/mbox/src/main/java/com/sun/mail/mbox/DefaultMailbox.java Tue Jan 17 14:11:34 2012 -0800
+++ b/mbox/src/main/java/com/sun/mail/mbox/DefaultMailbox.java Tue Jan 17 14:16:31 2012 -0800
@@ -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
@@ -43,7 +43,10 @@
 import java.io.*;
 
 public class DefaultMailbox extends Mailbox {
- private String home;
+ private final String home;
+
+ private static final boolean homeRelative =
+ Boolean.getBoolean("mail.mbox.homerelative");
 
     public DefaultMailbox() {
         home = System.getProperty("user.home");
@@ -69,7 +72,10 @@
             } else {
                 if (folder.equalsIgnoreCase("INBOX"))
                     folder = "INBOX";
- return home + File.separator + folder;
+ if (homeRelative)
+ return home + File.separator + folder;
+ else
+ return folder;
             }
         } catch (StringIndexOutOfBoundsException e) {
             return folder;

diff -r 780bbf94a5c8 -r a1f4145ab2fe mbox/src/main/java/com/sun/mail/mbox/MboxFolder.java
--- a/mbox/src/main/java/com/sun/mail/mbox/MboxFolder.java Tue Jan 17 14:11:34 2012 -0800
+++ b/mbox/src/main/java/com/sun/mail/mbox/MboxFolder.java Tue Jan 17 14:16:31 2012 -0800
@@ -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
@@ -68,6 +68,9 @@
     private long saved_file_size; // size at the last open, close, or expunge
     private boolean special_imap_message;
 
+ private static final boolean homeRelative =
+ Boolean.getBoolean("mail.mbox.homerelative");
+
     /**
      * Metadata for each message, to avoid instantiating MboxMessage
      * objects for messages we're not going to look at. <p>
@@ -137,9 +140,12 @@
             refdir = refdir.substring(0, i + 1);
             realdir = mstore.mb.filename(mstore.user, refdir);
         } else if (refdir.length() == 0 || refdir.charAt(0) != '~') {
- // no separator and doesn't start with "~" => home dir
+ // no separator and doesn't start with "~" => home or cwd
             refdir = null;
- realdir = mstore.home;
+ if (homeRelative)
+ realdir = mstore.home;
+ else
+ realdir = ".";
         } else {
             realdir = mstore.mb.filename(mstore.user, refdir);
         }
@@ -223,12 +229,8 @@
                                         throws MessagingException {
         if (folder.exists() && !folder.isDirectory())
             throw new MessagingException("not a directory");
- Folder f;
- if (this.name != null)
- f = createFolder(mstore, this.name + File.separator + name);
- else
- f = createFolder(mstore, name);
- return f;
+ return createFolder(mstore,
+ (this.name == null ? "~" : this.name) + File.separator + name);
     }
 
     public synchronized boolean create(int type) throws MessagingException {

diff -r 780bbf94a5c8 -r a1f4145ab2fe mbox/src/main/java/com/sun/mail/mbox/SolarisMailbox.java
--- a/mbox/src/main/java/com/sun/mail/mbox/SolarisMailbox.java Tue Jan 17 14:11:34 2012 -0800
+++ b/mbox/src/main/java/com/sun/mail/mbox/SolarisMailbox.java Tue Jan 17 14:16:31 2012 -0800
@@ -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
@@ -43,13 +43,17 @@
 import java.io.File;
 
 public class SolarisMailbox extends Mailbox {
- private String home;
- private String user;
+ private final String home;
+ private final String user;
+
+ private static final boolean homeRelative =
+ Boolean.getBoolean("mail.mbox.homerelative");
 
     public SolarisMailbox() {
- home = System.getenv("HOME");
- if (home == null)
- home = System.getProperty("user.home");
+ String h = System.getenv("HOME");
+ if (h == null)
+ h = System.getProperty("user.home");
+ home = h;
         user = System.getProperty("user.name");
     }
 
@@ -87,8 +91,12 @@
                     if (inbox == null)
                         inbox = "/var/mail/" + user;
                     return inbox;
- } else
- return home + File.separator + folder;
+ } else {
+ if (homeRelative)
+ return home + File.separator + folder;
+ else
+ return folder;
+ }
             }
         } catch (StringIndexOutOfBoundsException e) {
             return folder;


diff -r a1f4145ab2fe -r 9e95a68b4812 mbox/src/main/java/com/sun/mail/mbox/UNIXFile.java
--- a/mbox/src/main/java/com/sun/mail/mbox/UNIXFile.java Tue Jan 17 14:16:31 2012 -0800
+++ b/mbox/src/main/java/com/sun/mail/mbox/UNIXFile.java Tue Jan 17 14:59:07 2012 -0800
@@ -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
@@ -46,6 +46,7 @@
 
 public class UNIXFile extends File {
     protected static final boolean loaded;
+ protected static final int lockType;
 
     private static final long serialVersionUID = -7972156315284146651L;
 
@@ -53,34 +54,51 @@
         super(name);
     }
 
+ // lock type enum
+ protected static final int NONE = 0;
+ protected static final int NATIVE = 1;
+ protected static final int JAVA = 2;
+
     static {
+ String lt = System.getProperty("mail.mbox.locktype", "native");
+ int type = NATIVE;
+ if (lt.equalsIgnoreCase("none"))
+ type = NONE;
+ else if (lt.equalsIgnoreCase("java"))
+ type = JAVA;
+ lockType = type;
+
         boolean lloaded = false;
- try {
- System.loadLibrary("mbox");
- lloaded = true;
- } catch (UnsatisfiedLinkError e) {
- String classpath = System.getProperty("java.class.path");
- String sep = System.getProperty("path.separator");
- String arch = System.getProperty("os.arch");
- StringTokenizer st = new StringTokenizer(classpath, sep);
- while (st.hasMoreTokens()) {
- String path = st.nextToken();
- if (path.endsWith("/classes") || path.endsWith("/mail.jar")) {
- int i = path.lastIndexOf('/');
- String libdir = path.substring(0, i + 1) + "lib/";
- String lib = libdir + arch + "/libmbox.so";
- try {
- System.load(lib);
- lloaded = true;
- break;
- } catch (UnsatisfiedLinkError e2) {
- lib = libdir + "libmbox.so";
+ if (lockType == NATIVE) {
+ try {
+ System.loadLibrary("mbox");
+ lloaded = true;
+ } catch (UnsatisfiedLinkError e) {
+ String classpath = System.getProperty("java.class.path");
+ String sep = System.getProperty("path.separator");
+ String arch = System.getProperty("os.arch");
+ StringTokenizer st = new StringTokenizer(classpath, sep);
+ while (st.hasMoreTokens()) {
+ String path = st.nextToken();
+ if (path.endsWith("/classes") ||
+ path.endsWith("/mail.jar") ||
+ path.endsWith("/javax.mail.jar")) {
+ int i = path.lastIndexOf('/');
+ String libdir = path.substring(0, i + 1) + "lib/";
+ String lib = libdir + arch + "/libmbox.so";
                         try {
                             System.load(lib);
                             lloaded = true;
                             break;
- } catch (UnsatisfiedLinkError e3) {
- continue;
+ } catch (UnsatisfiedLinkError e2) {
+ lib = libdir + "libmbox.so";
+ try {
+ System.load(lib);
+ lloaded = true;
+ break;
+ } catch (UnsatisfiedLinkError e3) {
+ continue;
+ }
                         }
                     }
                 }

diff -r a1f4145ab2fe -r 9e95a68b4812 mbox/src/main/java/com/sun/mail/mbox/UNIXFolder.java
--- a/mbox/src/main/java/com/sun/mail/mbox/UNIXFolder.java Tue Jan 17 14:16:31 2012 -0800
+++ b/mbox/src/main/java/com/sun/mail/mbox/UNIXFolder.java Tue Jan 17 14:59:07 2012 -0800
@@ -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
@@ -54,7 +54,16 @@
     public boolean lock(String mode) {
         try {
             file = new RandomAccessFile(this, mode);
- return UNIXFile.lock(file.getFD(), mode);
+ switch (lockType) {
+ case NONE:
+ return true;
+ case NATIVE:
+ default:
+ return UNIXFile.lock(file.getFD(), mode);
+ case JAVA:
+ return file.getChannel().
+ tryLock(0L, Long.MAX_VALUE, !mode.equals("rw")) != null;
+ }
         } catch (FileNotFoundException fe) {
             return false;
         } catch (IOException ie) {

diff -r a1f4145ab2fe -r 9e95a68b4812 mbox/src/main/java/com/sun/mail/mbox/UNIXInbox.java
--- a/mbox/src/main/java/com/sun/mail/mbox/UNIXInbox.java Tue Jan 17 14:16:31 2012 -0800
+++ b/mbox/src/main/java/com/sun/mail/mbox/UNIXInbox.java Tue Jan 17 14:59:07 2012 -0800
@@ -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
@@ -60,12 +60,15 @@
     }
 
     public boolean lock(String mode) {
- if (!loaded)
- return false;
- if (!maillock(user, 5))
- return false;
+ if (lockType == NATIVE) {
+ if (!loaded)
+ return false;
+ if (!maillock(user, 5))
+ return false;
+ }
         if (!super.lock(mode)) {
- mailunlock();
+ if (loaded)
+ mailunlock();
             return false;
         }
         return true;
@@ -94,7 +97,17 @@
         }
         try {
             lockfile = new RandomAccessFile(lockfileName, mode);
- boolean ret = UNIXFile.lock(lockfile.getFD(), mode);
+ boolean ret;
+ switch (lockType) {
+ case NONE:
+ ret = true;
+ case NATIVE:
+ default:
+ ret = UNIXFile.lock(lockfile.getFD(), mode);
+ case JAVA:
+ ret = lockfile.getChannel().
+ tryLock(0L, Long.MAX_VALUE, !mode.equals("rw")) != null;
+ }
             if (!ret)
                 closeLock();
             return ret;


diff -r 9e95a68b4812 -r fb20ae045352 mail/src/main/java/com/sun/mail/iap/Response.java
--- a/mail/src/main/java/com/sun/mail/iap/Response.java Tue Jan 17 14:59:07 2012 -0800
+++ b/mail/src/main/java/com/sun/mail/iap/Response.java Tue Jan 17 15:00:31 2012 -0800
@@ -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
@@ -396,7 +396,7 @@
             int start = index;
             int copyto = index;
 
- while ((b = buffer[index]) != '"') {
+ while (index < size && (b = buffer[index]) != '"') {
                 if (b == '\\') // skip escaped byte
                     index++;
                 if (index != copyto) { // only copy if we need to
@@ -407,7 +407,13 @@
                 copyto++;
                 index++;
             }
- index++; // skip past the terminating quote
+ if (index >= size) {
+ // didn't find terminating quote, something is seriously wrong
+ //throw new ArrayIndexOutOfBoundsException(
+ // "index = " + index + ", size = " + size);
+ return null;
+ } else
+ index++; // skip past the terminating quote
 
             if (returnString)
                 return ASCIIUtility.toString(buffer, start, copyto);


diff -r fb20ae045352 -r 421a1b0a6e32 doc/release/CHANGES.txt
--- a/doc/release/CHANGES.txt Tue Jan 17 15:00:31 2012 -0800
+++ b/doc/release/CHANGES.txt Tue Jan 17 15:46:32 2012 -0800
@@ -19,6 +19,7 @@
 The following bugs have been fixed in the 1.4.5 release.
 
 7021190 MimeMessage.setRecipients(type, String) does not accept null address
+K 3815 ArrayIndexOutOfBoundsException for some IMAP protocol errors
 K 4002 MultipartReport.setReport and setDeliveryStatus are broken
 K 4065 Wrong representation of CR/LF are appended to the attachment
 K 4296 SSL Re-Negotiation Problem with checkserveridentity=true