Project: javamail
Repository: mercurial
Revision: 687
Author: shannon
Date: 2015-02-13 23:10:08 UTC
Link:
Log Message:
------------
Make it easier to test IMAP FETCH responses.
Remove unnecessary sleeps and make tests more reliable.
Add log message when a FETCH response can't be parsed.
long parameter values should be split using RFC 2231 - bug 6687
Enable most lint warnings and fix the reported warnings.
Make constructor of POP3Folder protected to allow subclassing - bug 6379
Use classloader ergonomics in the MailHandler - bug 6552
FindBugs 3.0 warning fixes.
Use JDK5 for loops in test case.
(From Jason)
Revisions:
----------
681
682
683
684
685
686
687
Modified Paths:
---------------
mail/src/test/java/com/sun/mail/imap/IMAPHandler.java
mail/src/test/java/com/sun/mail/imap/IMAPAlertTest.java
mail/src/test/java/com/sun/mail/imap/IMAPAuthDebugTest.java
mail/src/test/java/com/sun/mail/imap/IMAPCloseFailureTest.java
mail/src/test/java/com/sun/mail/imap/IMAPIdleStateTest.java
mail/src/test/java/com/sun/mail/imap/IMAPIdleUntaggedResponseTest.java
mail/src/test/java/com/sun/mail/imap/IMAPLoginFailureTest.java
mail/src/test/java/com/sun/mail/imap/IMAPSaslLoginTest.java
mail/src/main/java/com/sun/mail/iap/Protocol.java
mail/src/main/java/com/sun/mail/imap/protocol/FetchResponse.java
doc/release/CHANGES.txt
mail/src/main/java/javax/mail/internet/ParameterList.java
mail/src/test/java/javax/mail/internet/ParameterListTests.java
dsn/src/main/java/com/sun/mail/dsn/MultipartReport.java
mail/pom.xml
mail/src/main/java/com/sun/mail/handlers/text_xml.java
mail/src/main/java/com/sun/mail/imap/IMAPFolder.java
mail/src/main/java/com/sun/mail/imap/IMAPMessage.java
mail/src/main/java/com/sun/mail/imap/protocol/ENVELOPE.java
mail/src/main/java/com/sun/mail/imap/protocol/IMAPProtocol.java
mail/src/main/java/com/sun/mail/pop3/Protocol.java
mail/src/main/java/com/sun/mail/smtp/DigestMD5.java
mail/src/main/java/com/sun/mail/smtp/SMTPTransport.java
mail/src/main/java/com/sun/mail/util/MailSSLSocketFactory.java
mail/src/main/java/javax/mail/internet/InternetAddress.java
mail/src/main/java/javax/mail/search/AndTerm.java
mail/src/main/java/javax/mail/search/OrTerm.java
mail/src/main/java/com/sun/mail/pop3/POP3Folder.java
mail/src/main/java/com/sun/mail/util/logging/MailHandler.java
mail/src/test/java/com/sun/mail/util/logging/MailHandlerTest.java
Diffs:
------
diff -r 9e42fb16000d -r 883bd1885628 mail/src/test/java/com/sun/mail/imap/IMAPHandler.java
--- a/mail/src/test/java/com/sun/mail/imap/IMAPHandler.java Fri Jan 16 16:08:09 2015 -0800
+++ b/mail/src/test/java/com/sun/mail/imap/IMAPHandler.java Mon Jan 26 16:29:13 2015 -0800
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
- * Copyright (c) 2009-2014 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009-2015 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
@@ -62,6 +62,12 @@
/** IMAP capabilities supported */
protected String capabilities = "IMAP4REV1 IDLE";
+ /** Number of messages */
+ protected int numberOfMessages = 0;
+
+ /** Number of recent messages */
+ protected int numberOfRecentMessages = 0;
+
/**
* Send greetings.
*
@@ -208,7 +214,7 @@
} else if (commandName.equals("IDLE")) {
idle();
} else if (commandName.equals("FETCH")) {
- ok(); // XXX
+ fetch();
} else if (commandName.equals("CLOSE")) {
close();
} else if (commandName.equals("LOGOUT")) {
@@ -243,8 +249,8 @@
* @throws IOException unable to read/write to socket
*/
public void select() throws IOException {
- untagged("0 EXISTS");
- untagged("0 RECENT");
+ untagged(numberOfMessages + " EXISTS");
+ untagged(numberOfRecentMessages + " RECENT");
ok();
}
@@ -254,8 +260,8 @@
* @throws IOException unable to read/write to socket
*/
public void examine() throws IOException {
- untagged("0 EXISTS");
- untagged("0 RECENT");
+ untagged(numberOfMessages + " EXISTS");
+ untagged(numberOfRecentMessages + " RECENT");
ok();
}
@@ -290,6 +296,15 @@
}
/**
+ * FETCH command.
+ *
+ * @throws IOException unable to read/write to socket
+ */
+ public void fetch() throws IOException {
+ ok(); // XXX
+ }
+
+ /**
* CLOSE command.
*
* @throws IOException unable to read/write to socket
diff -r 883bd1885628 -r 6a600a4eb6fc mail/src/test/java/com/sun/mail/imap/IMAPAlertTest.java
--- a/mail/src/test/java/com/sun/mail/imap/IMAPAlertTest.java Mon Jan 26 16:29:13 2015 -0800
+++ b/mail/src/test/java/com/sun/mail/imap/IMAPAlertTest.java Mon Jan 26 16:51:17 2015 -0800
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
- * Copyright (c) 2009-2014 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009-2015 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
@@ -42,6 +42,8 @@
import java.io.IOException;
import java.util.Properties;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
import javax.mail.Session;
import javax.mail.Store;
@@ -68,14 +70,13 @@
final IMAPHandler handler = new IMAPHandlerAlert();
server = new TestServer(handler);
server.start();
- Thread.sleep(1000);
final Properties properties = new Properties();
properties.setProperty("mail.imap.host", "localhost");
properties.setProperty("mail.imap.port", "" + server.getPort());
- //properties.setProperty("mail.debug.auth", "true");
final Session session = Session.getInstance(properties);
//session.setDebug(true);
+ final CountDownLatch latch = new CountDownLatch(1);
final Store store = session.getStore("imap");
store.addStoreListener(new StoreListener() {
@@ -84,6 +85,7 @@
if (e.getMessageType() == StoreEvent.ALERT) {
s = "ALERT: ";
gotAlert = true;
+ latch.countDown();
} else
s = "NOTICE: ";
//System.out.println(s + e.getMessage());
@@ -91,7 +93,8 @@
});
try {
store.connect("test", "test");
- Thread.sleep(1000); // time for event to be delivered
+ // time for event to be delivered
+ latch.await(5, TimeUnit.SECONDS);
assertTrue(gotAlert);
} catch (Exception ex) {
diff -r 883bd1885628 -r 6a600a4eb6fc mail/src/test/java/com/sun/mail/imap/IMAPAuthDebugTest.java
--- a/mail/src/test/java/com/sun/mail/imap/IMAPAuthDebugTest.java Mon Jan 26 16:29:13 2015 -0800
+++ b/mail/src/test/java/com/sun/mail/imap/IMAPAuthDebugTest.java Mon Jan 26 16:51:17 2015 -0800
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
- * Copyright (c) 2009-2014 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009-2015 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
@@ -105,7 +105,6 @@
final IMAPHandler handler = new IMAPHandler();
server = new TestServer(handler);
server.start();
- Thread.sleep(1000);
properties.setProperty("mail.imap.host", "localhost");
properties.setProperty("mail.imap.port", "" + server.getPort());
diff -r 883bd1885628 -r 6a600a4eb6fc mail/src/test/java/com/sun/mail/imap/IMAPCloseFailureTest.java
--- a/mail/src/test/java/com/sun/mail/imap/IMAPCloseFailureTest.java Mon Jan 26 16:29:13 2015 -0800
+++ b/mail/src/test/java/com/sun/mail/imap/IMAPCloseFailureTest.java Mon Jan 26 16:51:17 2015 -0800
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
- * Copyright (c) 2009-2014 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009-2015 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
@@ -98,7 +98,6 @@
try {
server = new TestServer(handler);
server.start();
- Thread.sleep(1000);
Properties properties = new Properties();
properties.setProperty("mail.imap.host", HOST);
diff -r 883bd1885628 -r 6a600a4eb6fc mail/src/test/java/com/sun/mail/imap/IMAPIdleStateTest.java
--- a/mail/src/test/java/com/sun/mail/imap/IMAPIdleStateTest.java Mon Jan 26 16:29:13 2015 -0800
+++ b/mail/src/test/java/com/sun/mail/imap/IMAPIdleStateTest.java Mon Jan 26 16:51:17 2015 -0800
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
- * Copyright (c) 2009-2014 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009-2015 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
@@ -42,6 +42,7 @@
import java.io.IOException;
import java.util.Properties;
+import java.util.concurrent.CountDownLatch;
import javax.mail.Session;
import javax.mail.Store;
@@ -67,10 +68,9 @@
public void test() {
TestServer server = null;
try {
- final IMAPHandler handler = new IMAPHandlerIdleBye();
+ final IMAPHandlerIdleBye handler = new IMAPHandlerIdleBye();
server = new TestServer(handler);
server.start();
- Thread.sleep(1000);
final Properties properties = new Properties();
properties.setProperty("mail.imap.host", "localhost");
@@ -92,7 +92,7 @@
}
};
t.start();
- Thread.sleep(20); // give it time to IDLE
+ handler.waitForIdle();
// Now break it out of idle.
// Need to use a method that doesn't check that the Store
@@ -122,11 +122,18 @@
* to abort an IDLE.
*/
private static final class IMAPHandlerIdleBye extends IMAPHandler {
+ CountDownLatch latch = new CountDownLatch(1);
+
@Override
public void idle() throws IOException {
cont();
+ latch.countDown();
// don't wait for DONE, just close the connection now
bye("closing");
}
+
+ public void waitForIdle() throws InterruptedException {
+ latch.await();
+ }
}
}
diff -r 883bd1885628 -r 6a600a4eb6fc mail/src/test/java/com/sun/mail/imap/IMAPIdleUntaggedResponseTest.java
--- a/mail/src/test/java/com/sun/mail/imap/IMAPIdleUntaggedResponseTest.java Mon Jan 26 16:29:13 2015 -0800
+++ b/mail/src/test/java/com/sun/mail/imap/IMAPIdleUntaggedResponseTest.java Mon Jan 26 16:51:17 2015 -0800
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
- * Copyright (c) 2009-2014 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009-2015 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
@@ -42,11 +42,13 @@
import java.io.IOException;
import java.util.Properties;
+import java.util.concurrent.CountDownLatch;
import javax.mail.Folder;
import javax.mail.Session;
import javax.mail.Store;
import javax.mail.Message;
+import javax.mail.FetchProfile;
import com.sun.mail.test.TestServer;
@@ -69,10 +71,9 @@
public void test() {
TestServer server = null;
try {
- final IMAPHandler handler = new IMAPHandlerIdleExists();
+ final IMAPHandlerIdleExists handler = new IMAPHandlerIdleExists();
server = new TestServer(handler);
server.start();
- Thread.sleep(1000);
final Properties properties = new Properties();
properties.setProperty("mail.imap.host", "localhost");
@@ -92,8 +93,11 @@
Thread t = new Thread() {
public void run() {
try {
- Thread.sleep(1000);
- folder.getMessageCount();
+ handler.waitForIdle();
+ // now do something that is sure to touch the server
+ FetchProfile fp = new FetchProfile();
+ fp.add(FetchProfile.Item.ENVELOPE);
+ folder.fetch(folder.getMessages(), fp);
} catch (Exception ex) {
}
}
@@ -129,14 +133,27 @@
* sure the notification of the new message is seen.
*/
private static final class IMAPHandlerIdleExists extends IMAPHandler {
+ CountDownLatch latch = new CountDownLatch(1);
+
+ @Override
+ public void examine() throws IOException {
+ numberOfMessages = 1;
+ super.examine();
+ }
+
@Override
public void idle() throws IOException {
untagged("1 EXISTS");
untagged("1 RECENT");
cont();
untagged("1 FETCH (FLAGS (\\Recent \\Seen))");
+ latch.countDown();
idleWait();
ok();
}
+
+ public void waitForIdle() throws InterruptedException {
+ latch.await();
+ }
}
}
diff -r 883bd1885628 -r 6a600a4eb6fc mail/src/test/java/com/sun/mail/imap/IMAPLoginFailureTest.java
--- a/mail/src/test/java/com/sun/mail/imap/IMAPLoginFailureTest.java Mon Jan 26 16:29:13 2015 -0800
+++ b/mail/src/test/java/com/sun/mail/imap/IMAPLoginFailureTest.java Mon Jan 26 16:51:17 2015 -0800
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
- * Copyright (c) 2009-2014 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009-2015 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
@@ -76,7 +76,6 @@
};
server = new TestServer(handler);
server.start();
- Thread.sleep(1000);
SavedSocketFactory ssf = new SavedSocketFactory();
Properties properties = new Properties();
diff -r 883bd1885628 -r 6a600a4eb6fc mail/src/test/java/com/sun/mail/imap/IMAPSaslLoginTest.java
--- a/mail/src/test/java/com/sun/mail/imap/IMAPSaslLoginTest.java Mon Jan 26 16:29:13 2015 -0800
+++ b/mail/src/test/java/com/sun/mail/imap/IMAPSaslLoginTest.java Mon Jan 26 16:51:17 2015 -0800
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
- * Copyright (c) 2009-2014 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009-2015 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
@@ -67,7 +67,6 @@
IMAPHandler handler = new IMAPSaslHandler();
server = new TestServer(handler);
server.start();
- Thread.sleep(1000);
Properties properties = new Properties();
properties.setProperty("mail.imap.host", "localhost");
diff -r 6a600a4eb6fc -r 72cc130aae7c mail/src/main/java/com/sun/mail/iap/Protocol.java
--- a/mail/src/main/java/com/sun/mail/iap/Protocol.java Mon Jan 26 16:51:17 2015 -0800
+++ b/mail/src/main/java/com/sun/mail/iap/Protocol.java Mon Jan 26 16:58:09 2015 -0800
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
- * Copyright (c) 1997-2014 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997-2015 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
@@ -319,6 +319,7 @@
// convert this into a BYE response
r = Response.byeResponse(ioex);
} catch (ProtocolException pex) {
+ logger.log(Level.FINE, "ignoring bad response", pex);
continue; // skip this response
}
diff -r 6a600a4eb6fc -r 72cc130aae7c mail/src/main/java/com/sun/mail/imap/protocol/FetchResponse.java
--- a/mail/src/main/java/com/sun/mail/imap/protocol/FetchResponse.java Mon Jan 26 16:51:17 2015 -0800
+++ b/mail/src/main/java/com/sun/mail/imap/protocol/FetchResponse.java Mon Jan 26 16:58:09 2015 -0800
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
- * Copyright (c) 1997-2014 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997-2015 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
@@ -201,7 +201,8 @@
v.add(i);
else if (!parseExtensionItem())
throw new ParsingException(
- "error in FETCH parsing, unrecognized item at index " + index);
+ "error in FETCH parsing, unrecognized item at index " +
+ index + ", starts with \"" + next20() + "\"");
} while (buffer[index] != ')');
index++; // skip ')'
@@ -209,6 +210,16 @@
}
/**
+ * Return the next 20 characters in the buffer, for exception messages.
+ */
+ private String next20() {
+ if (index + 20 > size)
+ return ASCIIUtility.toString(buffer, index, index + size);
+ else
+ return ASCIIUtility.toString(buffer, index, index + 20) + "...";
+ }
+
+ /**
* Parse the item at the current position in the buffer,
* skipping over the item if successful. Otherwise, return null
* and leave the buffer position unmodified.
diff -r 72cc130aae7c -r e89dc4f35a9f doc/release/CHANGES.txt
--- a/doc/release/CHANGES.txt Mon Jan 26 16:58:09 2015 -0800
+++ b/doc/release/CHANGES.txt Fri Jan 30 14:49:07 2015 -0800
@@ -28,7 +28,8 @@
K 6638 attachment filenames aren't being encoded by default
K 6657 SharedFileInputStream has problems with 2GB+ files
K 6667 MimeBodyPart with copied DataHandler doesn't always set encoding
-K 6668 skip unusable Store and Transport classes
+K 6668 skip unusable Store and Transport classes
+K 6687 long parameter values should be split using RFC 2231
CHANGES IN THE 1.5.2 RELEASE
diff -r 72cc130aae7c -r e89dc4f35a9f mail/src/main/java/javax/mail/internet/ParameterList.java
--- a/mail/src/main/java/javax/mail/internet/ParameterList.java Mon Jan 26 16:58:09 2015 -0800
+++ b/mail/src/main/java/javax/mail/internet/ParameterList.java Fri Jan 30 14:49:07 2015 -0800
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
- * Copyright (c) 1997-2014 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997-2015 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
@@ -151,6 +151,9 @@
PropUtil.getBooleanSystemProperty("mail.mime.windowsfilenames", false);
private static final boolean parametersStrict =
PropUtil.getBooleanSystemProperty("mail.mime.parameters.strict", true);
+ private static final boolean splitLongParameters =
+ PropUtil.getBooleanSystemProperty(
+ "mail.mime.splitlongparameters", true);
/**
@@ -622,22 +625,61 @@
Iterator e = list.keySet().iterator();
while (e.hasNext()) {
- String name = (String)e.next();
+ String name = (String)e.next();
+ String value;
Object v = list.get(name);
if (v instanceof MultiValue) {
MultiValue vv = (MultiValue)v;
- String ns = name + "*";
+ name += "*";
for (int i = 0; i < vv.size(); i++) {
Object va = vv.get(i);
- if (va instanceof Value)
- sb.addNV(ns + i + "*", ((Value)va).encodedValue);
- else
- sb.addNV(ns + i, (String)va);
+ String ns;
+ if (va instanceof Value) {
+ ns = name + i + "*";
+ value = ((Value)va).encodedValue;
+ } else {
+ ns = name + i;
+ value = (String)va;
+ }
+ sb.addNV(ns, quote(value));
}
- } else if (v instanceof Value)
- sb.addNV(name + "*", ((Value)v).encodedValue);
- else
- sb.addNV(name, (String)v);
+ } else if (v instanceof Value) {
+ /*
+ * XXX - We could split the encoded value into multiple
+ * segments if it's too long, but that's more difficult.
+ */
+ name += "*";
+ value = ((Value)v).encodedValue;
+ sb.addNV(name, quote(value));
+ } else {
+ value = (String)v;
+ /*
+ * If this value is "long", split it into a multi-segment
+ * parameter. Only do this if we've enabled RFC2231 style
+ * encoded parameters.
+ *
+ * Note that we check the length before quoting the value.
+ * Quoting might make the string longer, although typically
+ * not much, so we allow a little slop in the calculation.
+ * In the worst case, a 60 character string will turn into
+ * 122 characters when quoted, which is long but not
+ * outrageous.
+ */
+ if (value.length() > 60 &&
+ splitLongParameters && encodeParameters) {
+ int seg = 0;
+ name += "*";
+ while (value.length() > 60) {
+ sb.addNV(name + seg, quote(value.substring(0, 60)));
+ value = value.substring(60);
+ seg++;
+ }
+ if (value.length() > 0)
+ sb.addNV(name + seg, quote(value));
+ } else {
+ sb.addNV(name, quote(value));
+ }
+ }
}
return sb.toString();
}
@@ -656,7 +698,6 @@
}
public void addNV(String name, String value) {
- value = quote(value);
sb.append("; ");
used += 2;
int len = name.length() + value.length() + 1;
diff -r 72cc130aae7c -r e89dc4f35a9f mail/src/test/java/javax/mail/internet/ParameterListTests.java
--- a/mail/src/test/java/javax/mail/internet/ParameterListTests.java Mon Jan 26 16:58:09 2015 -0800
+++ b/mail/src/test/java/javax/mail/internet/ParameterListTests.java Fri Jan 30 14:49:07 2015 -0800
@@ -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-2015 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
@@ -42,6 +42,7 @@
import org.junit.*;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
/**
* XXX - add more tests
@@ -64,4 +65,32 @@
ParameterList pl = new ParameterList("; filename=\"\\a\\b\\c.txt\"");
assertEquals(pl.get("filename"), "abc.txt");
}
+
+ /**
+ * Test that a long parameter that's been split into segments
+ * is parsed correctly.
+ */
+ @Test
+ public void testLongParse() throws Exception {
+ String p0 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
+ String p1 = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb";
+ ParameterList pl = new ParameterList("; p*0="+p0+"; p*1="+p1);
+ assertEquals(p0 + p1, pl.get("p"));
+ }
+
+ /**
+ * Test that a long parameter that's set programmatically is split
+ * into segments.
+ */
+ @Test
+ public void testLongSet() throws Exception {
+ String p0 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
+ String p1 = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb";
+ ParameterList pl = new ParameterList();
+ pl.set("p", p0 + p1);
+ assertEquals(p0 + p1, pl.get("p"));
+ String pls = pl.toString();
+ assertTrue(pls.indexOf("p*0=") >= 0);
+ assertTrue(pls.indexOf("p*1=") >= 0);
+ }
}
diff -r e89dc4f35a9f -r 18e19a150c62 dsn/src/main/java/com/sun/mail/dsn/MultipartReport.java
--- a/dsn/src/main/java/com/sun/mail/dsn/MultipartReport.java Fri Jan 30 14:49:07 2015 -0800
+++ b/dsn/src/main/java/com/sun/mail/dsn/MultipartReport.java Fri Jan 30 17:02:33 2015 -0800
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
- * Copyright (c) 1997-2013 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997-2015 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
@@ -293,6 +293,7 @@
* @exception MessagingException for failures
* @deprecated use getReport instead
*/
+ @Deprecated
public synchronized DeliveryStatus getDeliveryStatus()
throws MessagingException {
if (getCount() < 2)
diff -r e89dc4f35a9f -r 18e19a150c62 mail/pom.xml
--- a/mail/pom.xml Fri Jan 30 14:49:07 2015 -0800
+++ b/mail/pom.xml Fri Jan 30 17:02:33 2015 -0800
@@ -3,7 +3,7 @@
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
- Copyright (c) 1997-2014 Oracle and/or its affiliates. All rights reserved.
+ Copyright (c) 1997-2015 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
@@ -97,6 +97,41 @@
</resources>
<plugins>
<!--
+ Configure compiler plugin to print lint warnings.
+ -->
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>default-compile</id>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ <fork>true</fork>
+ <!--
+ ignore some of the errors that are
+ too hard to fix for now
+ -->
+ <compilerArguments>
+ <Xlint:all/>
+ <Xlint:-rawtypes/>
+ <Xlint:-unchecked/>
+ <Xlint:-finally/>
+ </compilerArguments>
+ <showWarnings>true</showWarnings>
+ </configuration>
+ </execution>
+ <execution>
+ <id>default-testCompile</id>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
+ <!--
Configure test plugin to find *TestSuite classes.
-->
<plugin>
diff -r e89dc4f35a9f -r 18e19a150c62 mail/src/main/java/com/sun/mail/handlers/text_xml.java
--- a/mail/src/main/java/com/sun/mail/handlers/text_xml.java Fri Jan 30 14:49:07 2015 -0800
+++ b/mail/src/main/java/com/sun/mail/handlers/text_xml.java Fri Jan 30 17:02:33 2015 -0800
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
- * Copyright (c) 1997-2013 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997-2015 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
@@ -83,7 +83,7 @@
* @return the DataFlavors
*/
public DataFlavor[] getTransferDataFlavors() { // throws Exception;
- return (DataFlavor[])flavors.clone();
+ return flavors.clone();
}
/**
diff -r e89dc4f35a9f -r 18e19a150c62 mail/src/main/java/com/sun/mail/imap/IMAPFolder.java
--- a/mail/src/main/java/com/sun/mail/imap/IMAPFolder.java Fri Jan 30 14:49:07 2015 -0800
+++ b/mail/src/main/java/com/sun/mail/imap/IMAPFolder.java Fri Jan 30 17:02:33 2015 -0800
@@ -326,6 +326,7 @@
*
* @deprecated
*/
+ @Deprecated
public static final FetchProfileItem SIZE =
new FetchProfileItem("SIZE");
@@ -372,7 +373,7 @@
this.separator = separator;
logger = new MailLogger(this.getClass(),
"DEBUG IMAP", store.getSession());
- connectionPoolLogger = ((IMAPStore)store).getConnectionPoolLogger();
+ connectionPoolLogger = store.getConnectionPoolLogger();
/*
* Work around apparent bug in Exchange. Exchange
@@ -2834,8 +2835,7 @@
checkExists();
if (attributes == null)
exists(); // do a LIST to set the attributes
- return attributes == null ? new String[0] :
- (String[])(attributes.clone());
+ return attributes == null ? new String[0] : attributes.clone();
}
/**
diff -r e89dc4f35a9f -r 18e19a150c62 mail/src/main/java/com/sun/mail/imap/IMAPMessage.java
--- a/mail/src/main/java/com/sun/mail/imap/IMAPMessage.java Fri Jan 30 14:49:07 2015 -0800
+++ b/mail/src/main/java/com/sun/mail/imap/IMAPMessage.java Fri Jan 30 17:02:33 2015 -0800
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
- * Copyright (c) 1997-2014 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997-2015 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
@@ -514,7 +514,7 @@
return super.getContentLanguage();
loadBODYSTRUCTURE();
if (bs.language != null)
- return (String[])(bs.language).clone();
+ return bs.language.clone();
else
return null;
}
@@ -1109,6 +1109,7 @@
* @param fp the FetchProfile
* @param fitems the FETCH items
*/
+ @SuppressWarnings("deprecation") // for FetchProfile.Item.SIZE
public FetchProfileCondition(FetchProfile fp, FetchItem[] fitems) {
if (fp.contains(FetchProfile.Item.ENVELOPE))
needEnvelope = true;
@@ -1591,7 +1592,7 @@
if (aa == null)
return null;
else
- return (InternetAddress[])aa.clone();
+ return aa.clone();
}
private Flags _getFlags() {
diff -r e89dc4f35a9f -r 18e19a150c62 mail/src/main/java/com/sun/mail/imap/protocol/ENVELOPE.java
--- a/mail/src/main/java/com/sun/mail/imap/protocol/ENVELOPE.java Fri Jan 30 14:49:07 2015 -0800
+++ b/mail/src/main/java/com/sun/mail/imap/protocol/ENVELOPE.java Fri Jan 30 17:02:33 2015 -0800
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
- * Copyright (c) 1997-2014 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997-2015 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
@@ -249,6 +249,6 @@
public InternetAddress[] getGroup(boolean strict) throws AddressException {
if (grouplist == null)
return null;
- return (InternetAddress[])grouplist.clone();
+ return grouplist.clone();
}
}
diff -r e89dc4f35a9f -r 18e19a150c62 mail/src/main/java/com/sun/mail/imap/protocol/FetchResponse.java
--- a/mail/src/main/java/com/sun/mail/imap/protocol/FetchResponse.java Fri Jan 30 14:49:07 2015 -0800
+++ b/mail/src/main/java/com/sun/mail/imap/protocol/FetchResponse.java Fri Jan 30 17:02:33 2015 -0800
@@ -224,6 +224,7 @@
* skipping over the item if successful. Otherwise, return null
* and leave the buffer position unmodified.
*/
+ @SuppressWarnings("empty")
private Item parseItem() throws ParsingException {
switch (buffer[index]) {
case 'E': case 'e':
diff -r e89dc4f35a9f -r 18e19a150c62 mail/src/main/java/com/sun/mail/imap/protocol/IMAPProtocol.java
--- a/mail/src/main/java/com/sun/mail/imap/protocol/IMAPProtocol.java Fri Jan 30 14:49:07 2015 -0800
+++ b/mail/src/main/java/com/sun/mail/imap/protocol/IMAPProtocol.java Fri Jan 30 17:02:33 2015 -0800
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
- * Copyright (c) 1997-2014 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997-2015 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
@@ -856,6 +856,7 @@
* {_at_link #id(Map<String,String>)}
* @since JavaMail 1.4.4
*/
+ @Deprecated
public void id(String guid) throws ProtocolException {
// support this for now, but remove it soon
Map<String,String> gmap = new HashMap<String,String>();
@@ -1944,7 +1945,7 @@
private int[] search(String msgSequence, SearchTerm term)
throws ProtocolException, SearchException {
// Check if the search "text" terms contain only ASCII chars
- if (getSearchSequence().isAscii(term)) {
+ if (SearchSequence.isAscii(term)) {
try {
return issueSearch(msgSequence, term, null);
} catch (IOException ioex) { /* will not happen */ }
diff -r e89dc4f35a9f -r 18e19a150c62 mail/src/main/java/com/sun/mail/pop3/Protocol.java
--- a/mail/src/main/java/com/sun/mail/pop3/Protocol.java Fri Jan 30 14:49:07 2015 -0800
+++ b/mail/src/main/java/com/sun/mail/pop3/Protocol.java Fri Jan 30 17:02:33 2015 -0800
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
- * Copyright (c) 1997-2013 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997-2015 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,7 +68,7 @@
private String host; // host we're connected to
private Properties props; // session properties
private String prefix; // protocol name prefix, for props
- private DataInputStream input; // input buf
+ private BufferedReader input; // input buf
private PrintWriter output; // output buf
private TraceInputStream traceInput;
private TraceOutputStream traceOutput;
@@ -168,11 +168,12 @@
new TraceOutputStream(socket.getOutputStream(), traceLogger);
traceOutput.setQuote(quote);
- input = new DataInputStream(new BufferedInputStream(traceInput));
+ // should be US-ASCII, but not all JDK's support it so use iso-8859-1
+ input = new BufferedReader(new InputStreamReader(traceInput,
+ "iso-8859-1"));
output = new PrintWriter(
new BufferedWriter(
new OutputStreamWriter(traceOutput, "iso-8859-1")));
- // should be US-ASCII, but not all JDK's support
}
protected void finalize() throws Throwable {
@@ -714,7 +715,7 @@
private Response readResponse() throws IOException {
String line = null;
try {
- line = input.readLine(); // XXX - readLine is deprecated
+ line = input.readLine();
} catch (InterruptedIOException iioex) {
/*
* If we get a timeout while using the socket, we have no idea
diff -r e89dc4f35a9f -r 18e19a150c62 mail/src/main/java/com/sun/mail/smtp/DigestMD5.java
--- a/mail/src/main/java/com/sun/mail/smtp/DigestMD5.java Fri Jan 30 14:49:07 2015 -0800
+++ b/mail/src/main/java/com/sun/mail/smtp/DigestMD5.java Fri Jan 30 17:02:33 2015 -0800
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
- * Copyright (c) 1997-2013 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997-2015 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
@@ -168,6 +168,7 @@
*
* @return Hashtable containing key/value pairs from server
*/
+ @SuppressWarnings("fallthrough")
private Hashtable tokenize(String serverResponse) throws IOException {
Hashtable map = new Hashtable();
byte[] bytes = serverResponse.getBytes("iso-8859-1"); // really ASCII?
diff -r e89dc4f35a9f -r 18e19a150c62 mail/src/main/java/com/sun/mail/smtp/SMTPTransport.java
--- a/mail/src/main/java/com/sun/mail/smtp/SMTPTransport.java Fri Jan 30 14:49:07 2015 -0800
+++ b/mail/src/main/java/com/sun/mail/smtp/SMTPTransport.java Fri Jan 30 17:02:33 2015 -0800
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
- * Copyright (c) 1997-2013 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997-2015 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
@@ -427,7 +427,7 @@
}
if (saslMechanisms == null)
return null;
- return (String[])saslMechanisms.clone();
+ return saslMechanisms.clone();
}
/**
@@ -441,7 +441,7 @@
*/
public synchronized void setSASLMechanisms(String[] mechanisms) {
if (mechanisms != null)
- mechanisms = (String[])mechanisms.clone();
+ mechanisms = mechanisms.clone();
this.saslMechanisms = mechanisms;
}
diff -r e89dc4f35a9f -r 18e19a150c62 mail/src/main/java/com/sun/mail/util/MailSSLSocketFactory.java
--- a/mail/src/main/java/com/sun/mail/util/MailSSLSocketFactory.java Fri Jan 30 14:49:07 2015 -0800
+++ b/mail/src/main/java/com/sun/mail/util/MailSSLSocketFactory.java Fri Jan 30 17:02:33 2015 -0800
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
- * Copyright (c) 1997-2013 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997-2015 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
@@ -133,14 +133,14 @@
sslcontext.init(keyManagers, trustManagers, secureRandom);
// Get SocketFactory and save it in our instance var
- adapteeFactory = (SSLSocketFactory)sslcontext.getSocketFactory();
+ adapteeFactory = sslcontext.getSocketFactory();
}
/**
* @return the keyManagers
*/
public synchronized KeyManager[] getKeyManagers() {
- return (KeyManager[])keyManagers.clone();
+ return keyManagers.clone();
}
/**
@@ -149,7 +149,7 @@
*/
public synchronized void setKeyManagers(KeyManager[] keyManagers)
throws GeneralSecurityException {
- this.keyManagers = (KeyManager[])keyManagers.clone();
+ this.keyManagers = keyManagers.clone();
newAdapteeFactory();
}
@@ -205,14 +205,14 @@
* @return the trusted hosts
*/
public synchronized String[] getTrustedHosts() {
- return (String[])trustedHosts.clone();
+ return trustedHosts.clone();
}
/**
* @param trustedHosts the hosts to trust
*/
public synchronized void setTrustedHosts(String[] trustedHosts) {
- this.trustedHosts = (String[])trustedHosts.clone();
+ this.trustedHosts = trustedHosts.clone();
}
/**
diff -r e89dc4f35a9f -r 18e19a150c62 mail/src/main/java/javax/mail/internet/InternetAddress.java
--- a/mail/src/main/java/javax/mail/internet/InternetAddress.java Fri Jan 30 14:49:07 2015 -0800
+++ b/mail/src/main/java/javax/mail/internet/InternetAddress.java Fri Jan 30 17:02:33 2015 -0800
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
- * Copyright (c) 1997-2014 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997-2015 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
@@ -671,6 +671,7 @@
*
* XXX - Deal with encoded Headers too.
*/
+ @SuppressWarnings("fallthrough")
private static InternetAddress[] parse(String s, boolean strict,
boolean parseHdr) throws AddressException {
int start, end, index, nesting;
diff -r e89dc4f35a9f -r 18e19a150c62 mail/src/main/java/javax/mail/internet/ParameterList.java
--- a/mail/src/main/java/javax/mail/internet/ParameterList.java Fri Jan 30 14:49:07 2015 -0800
+++ b/mail/src/main/java/javax/mail/internet/ParameterList.java Fri Jan 30 17:02:33 2015 -0800
@@ -180,6 +180,9 @@
* Until then the value field contains an empty string as a placeholder.
*/
private static class MultiValue extends ArrayList {
+ // keep lint happy
+ private static final long serialVersionUID = 699561094618751023L;
+
String value;
}
@@ -460,8 +463,12 @@
} catch (UnsupportedEncodingException uex) {
if (decodeParametersStrict)
throw new ParseException(uex.toString());
- // convert as if ASCII
- mv.value = bos.toString(0);
+ // convert as if iso-8859-1
+ try {
+ mv.value = bos.toString("iso-8859-1");
+ } catch (UnsupportedEncodingException ex) {
+ // should never happen
+ }
}
list.put(name, mv);
}
diff -r e89dc4f35a9f -r 18e19a150c62 mail/src/main/java/javax/mail/search/AndTerm.java
--- a/mail/src/main/java/javax/mail/search/AndTerm.java Fri Jan 30 14:49:07 2015 -0800
+++ b/mail/src/main/java/javax/mail/search/AndTerm.java Fri Jan 30 17:02:33 2015 -0800
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
- * Copyright (c) 1997-2013 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997-2015 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
@@ -90,7 +90,7 @@
* @return the search terms
*/
public SearchTerm[] getTerms() {
- return (SearchTerm[])terms.clone();
+ return terms.clone();
}
/**
diff -r e89dc4f35a9f -r 18e19a150c62 mail/src/main/java/javax/mail/search/OrTerm.java
--- a/mail/src/main/java/javax/mail/search/OrTerm.java Fri Jan 30 14:49:07 2015 -0800
+++ b/mail/src/main/java/javax/mail/search/OrTerm.java Fri Jan 30 17:02:33 2015 -0800
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
- * Copyright (c) 1997-2013 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997-2015 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
@@ -89,7 +89,7 @@
* @return the search terms
*/
public SearchTerm[] getTerms() {
- return (SearchTerm[])terms.clone();
+ return terms.clone();
}
/**
diff -r 18e19a150c62 -r c486a03660b2 doc/release/CHANGES.txt
--- a/doc/release/CHANGES.txt Fri Jan 30 17:02:33 2015 -0800
+++ b/doc/release/CHANGES.txt Fri Jan 30 17:15:17 2015 -0800
@@ -18,6 +18,7 @@
----------------------------
The following bugs have been fixed in the 1.5.3 release.
+K 6379 Make constructor of POP3Folder protected to allow subclassing
K 6407 calling IdleManager.watch twice on same folder fails
K 6430 NPE in IMAPFolder.copyUIDMessages when COPYUID not returned
K 6496 Message-Id leaks current user/hostname of the Java process (security)
diff -r 18e19a150c62 -r c486a03660b2 mail/src/main/java/com/sun/mail/pop3/POP3Folder.java
--- a/mail/src/main/java/com/sun/mail/pop3/POP3Folder.java Fri Jan 30 17:02:33 2015 -0800
+++ b/mail/src/main/java/com/sun/mail/pop3/POP3Folder.java Fri Jan 30 17:15:17 2015 -0800
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
- * Copyright (c) 1997-2013 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997-2015 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
@@ -80,7 +80,7 @@
MailLogger logger; // package private, for POP3Message
- POP3Folder(POP3Store store, String name) {
+ protected POP3Folder(POP3Store store, String name) {
super(store);
this.name = name;
this.store = store;
diff -r c486a03660b2 -r b02d119e7836 doc/release/CHANGES.txt
--- a/doc/release/CHANGES.txt Fri Jan 30 17:15:17 2015 -0800
+++ b/doc/release/CHANGES.txt Fri Feb 13 15:10:08 2015 -0800
@@ -26,6 +26,7 @@
K 6526 Date search terms result in wrong greater-than SEARCH commands for IMAP
K 6535 address similar to (x)<y>(z) will throw StringIndexOutOfBoundsException
K 6551 Update logging demos to use the new 1.5.2 features
+K 6552 Use classloader ergonomics in the MailHandler
K 6638 attachment filenames aren't being encoded by default
K 6657 SharedFileInputStream has problems with 2GB+ files
K 6667 MimeBodyPart with copied DataHandler doesn't always set encoding
diff -r c486a03660b2 -r b02d119e7836 mail/src/main/java/com/sun/mail/util/logging/MailHandler.java
--- a/mail/src/main/java/com/sun/mail/util/logging/MailHandler.java Fri Jan 30 17:15:17 2015 -0800
+++ b/mail/src/main/java/com/sun/mail/util/logging/MailHandler.java Fri Feb 13 15:10:08 2015 -0800
@@ -1,8 +1,8 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
- * Copyright (c) 2009-2014 Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2009-2014 Jason Mehrens. All rights reserved.
+ * Copyright (c) 2009-2015 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009-2015 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
@@ -53,10 +53,7 @@
import java.util.*;
import java.util.logging.*;
import java.util.logging.Formatter;
-import javax.activation.DataHandler;
-import javax.activation.DataSource;
-import javax.activation.FileTypeMap;
-import javax.activation.MimetypesFileTypeMap;
+import javax.activation.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.mail.util.ByteArrayDataSource;
@@ -373,11 +370,14 @@
*/
private static final int offValue = Level.OFF.intValue();
/**
- * The action to get and set the context class loader.
- * Load this before it is loaded in the close method.
+ * The action to set the context class loader for use with the JavaMail API.
+ * Load and pin this before it is loaded in the close method. The field is
+ * declared as java.security.PrivilegedAction so
+ * WebappClassLoader.clearReferencesStaticFinal() method will ignore this
+ * field.
*/
- private static final GetAndSetContext GET_AND_SET_CCL =
- new GetAndSetContext(MailHandler.class);
+ private static final PrivilegedAction<Object> MAILHANDLER_LOADER
+ = new GetAndSetContext(MailHandler.class);
/**
* A thread local mutex used to prevent logging loops.
* The MUTEX has 3 states:
@@ -414,7 +414,7 @@
/**
* Holds the session object used to generate emails.
* Sessions can be shared by multiple threads.
- * See BUGID 6228391
+ * See BUGID 6228391 and K 6278.
*/
private Session session;
/**
@@ -578,6 +578,7 @@
* will push to ensure that all published records are sent.
* See close().
*/
+
if (tryMutex()) {
try {
if (isLoggable(record)) {
@@ -641,18 +642,18 @@
if (record != null) {
final SimpleFormatter f = new SimpleFormatter();
msg = "Log record " + record.getSequenceNumber()
- + " was not published. "
- + head(f) + format(f, record) + tail(f, "");
+ + " was not published. "
+ + head(f) + format(f, record) + tail(f, "");
} else {
msg = null;
}
Exception e = new IllegalStateException(
- "Recursive publish detected by thread "
- + Thread.currentThread());
+ "Recursive publish detected by thread "
+ + Thread.currentThread());
reportError(msg, e, ErrorManager.WRITE_FAILURE);
- } finally {
+ } finally {
MUTEX.set(MUTEX_PUBLISH);
- }
+ }
}
}
@@ -682,6 +683,36 @@
}
/**
+ * A callback method for when this object is about to be placed into
+ * commission. This contract is defined by the
+ * {_at_code org.glassfish.hk2.api.PostConstruct} interface. If this class is
+ * loaded via a lifecycle managed environment other than HK2 then it is
+ * recommended that this method is called either directly or through
+ * extending this class to signal that this object is ready for use.
+ *
+ * @since JavaMail 1.5.3
+ */
+ public void postConstruct() {
+ }
+
+ /**
+ * A callback method for when this object is about to be decommissioned.
+ * This contract is defined by the {_at_code org.glassfish.hk2.api.PreDestory}
+ * interface. If this class is loaded via a lifecycle managed environment
+ * other than HK2 then it is recommended that this method is called either
+ * directly or through extending this class to signal that this object will
+ * be destroyed.
+ *
+ * @since JavaMail 1.5.3
+ */
+ public void preDestroy() {
+ /**
+ * Close can require permissions so just trigger a push.
+ */
+ push(false, ErrorManager.CLOSE_FAILURE);
+ }
+
+ /**
* Pushes any buffered records to the email server as high importance with
* urgent priority. The internal buffer is then cleared. Does nothing if
* called from inside a push.
@@ -715,38 +746,32 @@
* @see #flush()
*/
public void close() {
- checkAccess(); //Security check first.
- //The LogManager$Cleaner has a context class loader set to null.
- //Set the CCL to this class loader for loading content handlers.
- final Object ccl = getAndSetContextClassLoader();
- try {
- Message msg = null;
- synchronized (this) {
- try {
- msg = writeLogRecords(ErrorManager.CLOSE_FAILURE);
- } finally {
- super.setLevel(Level.OFF); //Change level after formatting.
- /**
- * The sign bit of the capacity is set to ensure that records
- * that have passed isLoggable, but have yet to be added to
- * the internal buffer, are immediately pushed as an email.
- */
- if (this.capacity > 0) {
- this.capacity = -this.capacity;
- }
+ checkAccess(); //Ensure setLevel works before clearing the buffer.
+ Message msg = null;
+ synchronized (this) {
+ try {
+ msg = writeLogRecords(ErrorManager.CLOSE_FAILURE);
+ } finally { //Change level after formatting.
+ super.setLevel(Level.OFF);
+ /**
+ * The sign bit of the capacity is set to ensure that
+ * records that have passed isLoggable, but have yet to be
+ * added to the internal buffer, are immediately pushed as
+ * an email.
+ */
+ if (this.capacity > 0) {
+ this.capacity = -this.capacity;
+ }
- //Ensure not inside a push.
- if (size == 0 && data.length != 1) {
- this.data = new LogRecord[1];
- }
+ //Ensure not inside a push.
+ if (size == 0 && data.length != 1) {
+ this.data = new LogRecord[1];
}
}
+ }
- if (msg != null) {
- send(msg, false, ErrorManager.CLOSE_FAILURE);
- }
- } finally {
- setContextClassLoader(ccl);
+ if (msg != null) {
+ send(msg, false, ErrorManager.CLOSE_FAILURE);
}
}
@@ -1243,10 +1268,17 @@
*/
@Override
protected void reportError(String msg, Exception ex, int code) {
- if (msg != null) {
- super.reportError(Level.SEVERE.getName() + ": " + msg, ex, code);
- } else {
- super.reportError(null, ex, code);
+ try {
+ if (msg != null) {
+ super.reportError(Level.SEVERE.getName()
+ .concat(": ").concat(msg), ex, code);
+ } else {
+ super.reportError(null, ex, code);
+ }
+ } catch (final RuntimeException GLASSFISH_21258) {
+ reportLinkageError(GLASSFISH_21258, code);
+ } catch (final LinkageError GLASSFISH_21258) {
+ reportLinkageError(GLASSFISH_21258, code);
}
}
@@ -1303,6 +1335,7 @@
cause = cause.getCause();
}
+ final Object ccl = getAndSetContextClassLoader(MAILHANDLER_LOADER);
try {
msg.writeTo(new ByteArrayOutputStream(MIN_HEADER_SIZE));
} catch (final RuntimeException RE) {
@@ -1310,8 +1343,10 @@
} catch (final Exception noContent) {
final String txt = noContent.getMessage();
if (!isEmpty(txt) && noContent.getClass() == t.getClass()) {
- return txt.equals(t.getMessage());
+ return txt.equals(t.getMessage());
}
+ } finally {
+ getAndSetContextClassLoader(ccl);
}
return false;
}
@@ -1327,10 +1362,75 @@
private void reportError(Message msg, Exception ex, int code) {
try { //Use super call so we do not prefix raw email.
super.reportError(toRawString(msg), ex, code);
- } catch (final MessagingException rawMe) {
- reportError(toMsgString(rawMe), ex, code);
- } catch (final IOException rawIo) {
- reportError(toMsgString(rawIo), ex, code);
+ } catch (final RuntimeException re) {
+ reportError(toMsgString(re), ex, code);
+ } catch (final Exception e) {
+
[truncated due to length]