Project: javamail
Repository: mercurial
Revision: 313
Author: shannon
Date: 2010-11-05 21:18:29 UTC
Link:
Log Message:
------------
Work around JDK bug 6995537 that causes iso-2022-jp decoding problems.
Add more information to exception message.
Updates from Jason:
FileErrorManager refactor to allow chaining.
FileErrorManager javadoc fixes
MailHandler don't assume SMTP during verify.
MailHandler getLocalAddress failure is reported by MimeMessage.setFrom()
maildemo.properties fix FileErrorManager package name
Revisions:
----------
311
312
313
Modified Paths:
---------------
doc/release/CHANGES.txt
mail/src/main/java/com/sun/mail/handlers/text_plain.java
mail/src/main/java/com/sun/mail/imap/MessageCache.java
logging/src/main/java/FileErrorManager.java
logging/src/main/java/maildemo.properties
mail/src/main/java/com/sun/mail/util/logging/MailHandler.java
Diffs:
------
diff -r 60282749aead -r 5cfdd06bc528 doc/release/CHANGES.txt
--- a/doc/release/CHANGES.txt Tue Oct 26 12:30:10 2010 -0700
+++ b/doc/release/CHANGES.txt Mon Nov 01 20:08:02 2010 -0700
@@ -23,6 +23,7 @@
6905730 MimeMessage.parse() is very slow on malformed message content
6910675 IMAP provider can lose track of message sequence numbers
6928566 Header violates RFC 2822 for multiple calls of addRecipient(s)
+6995537 Work around this JDK bug that causes iso-2022-jp decoding problems
G 11069 update the mail.jar manifest to include DynamicImport-Package
K 3442 make sure socket is closed if SMTP connect fails
<no id> add mail.mime.windowsfilenames System property to handle IE6 breakage
diff -r 60282749aead -r 5cfdd06bc528 mail/src/main/java/com/sun/mail/handlers/text_plain.java
--- a/mail/src/main/java/com/sun/mail/handlers/text_plain.java Tue Oct 26 12:30:10 2010 -0700
+++ b/mail/src/main/java/com/sun/mail/handlers/text_plain.java Mon Nov 01 20:08:02 2010 -0700
@@ -55,6 +55,19 @@
"text/plain",
"Text String");
+ /**
+ * An OuputStream wrapper that doesn't close the underlying stream.
+ */
+ private static class NoCloseOutputStream extends FilterOutputStream {
+ public NoCloseOutputStream(OutputStream os) {
+ super(os);
+ }
+
+ public void close() {
+ // do nothing
+ }
+ }
+
protected ActivationDataFlavor getDF() {
return myDF;
}
@@ -145,7 +158,7 @@
try {
enc = getCharset(type);
- osw = new OutputStreamWriter(os, enc);
+ osw = new OutputStreamWriter(new NoCloseOutputStream(os), enc);
} catch (IllegalArgumentException iex) {
/*
* An unknown charset of the form ISO-XXX-XXX will cause
@@ -160,7 +173,14 @@
String s = (String)obj;
osw.write(s, 0, s.length());
- osw.flush();
+ /*
+ * Have to call osw.close() instead of osw.flush() because
+ * some charset converts, such as the iso-2022-jp converter,
+ * don't output the "shift out" sequence unless they're closed.
+ * The NoCloseOutputStream wrapper prevents the underlying
+ * stream from being closed.
+ */
+ osw.close();
}
private String getCharset(String type) {
diff -r 5cfdd06bc528 -r e593aca29ee4 mail/src/main/java/com/sun/mail/imap/MessageCache.java
--- a/mail/src/main/java/com/sun/mail/imap/MessageCache.java Mon Nov 01 20:08:02 2010 -0700
+++ b/mail/src/main/java/com/sun/mail/imap/MessageCache.java Fri Nov 05 14:17:09 2010 -0700
@@ -121,7 +121,7 @@
// check range
if (msgnum < 1 || msgnum > size)
throw new ArrayIndexOutOfBoundsException(
- "message number out of bounds");
+ "message number (" + msgnum + ") out of bounds (" + size + ")");
IMAPMessage msg = messages[msgnum-1];
if (msg == null) {
if (debug)
diff -r e593aca29ee4 -r 12192f2eee28 logging/src/main/java/FileErrorManager.java
--- a/logging/src/main/java/FileErrorManager.java Fri Nov 05 14:17:09 2010 -0700
+++ b/logging/src/main/java/FileErrorManager.java Fri Nov 05 14:18:29 2010 -0700
@@ -50,15 +50,15 @@
* can be as simple as the following:
* <tt><pre>
* #Default FileErrorManager settings.
- * com.sun.mail.util.logging.FileErrorManager.pattern = path to directory
+ * FileErrorManager.pattern = path to directory
* </pre></tt>
*
* If properties are not defined, or contain invalid values, then the specified
* default values are used.
* <ul>
- * <li>com.sun.mail.util.logging.FileErrorManager.pattern the absolute file path
- * to the directory which will store any failed email messages. (defaults
- * to the value of the system property <tt>java.io.tmpdir</tt>)
+ * <li>FileErrorManager.pattern the absolute file path to the directory which
+ * will store any failed email messages. (defaults to the value of the system
+ * property <tt>java.io.tmpdir</tt>)
* </ul>
*
* @author Jason Mehrens
@@ -70,9 +70,9 @@
*/
private static final LogManager manager = LogManager.getLogManager();
/**
- * Used to report internal errors.
+ * Used to report errors that this error manager fails to report.
*/
- private final ErrorManager internal = new ErrorManager();
+ private final ErrorManager next = new ErrorManager();
/**
* Directory of the email store.
*/
@@ -110,9 +110,9 @@
* this method will store the email to the file system. If the message
* parameter is not a raw email then the message is forwarded to the super
* class. If an email is written to the filesystem without error, then the
- * orignal reported error is ignored.
+ * original reported error is ignored.
* @param msg String raw email or plain error message.
- * @param ex Exception that occured in the mail handler.
+ * @param ex Exception that occurred in the mail handler.
* @param code int error manager code.
*/
public void error(String msg, Exception ex, int code) {
@@ -120,18 +120,22 @@
try {
storeEmail(msg);
} catch (final IOException IOE) {
- super.error(msg, ex, code);
- internal.error(emailStore.toString(), IOE, ErrorManager.WRITE_FAILURE);
+ super.error(emailStore.toString(), IOE, ErrorManager.WRITE_FAILURE);
+ next.error(msg, ex, code);
} catch (final RuntimeException RE) {
- super.error(msg, ex, code);
- internal.error(emailStore.toString(), RE, ErrorManager.WRITE_FAILURE);
+ super.error(emailStore.toString(), RE, ErrorManager.WRITE_FAILURE);
+ next.error(msg, ex, code);
}
} else {
- super.error(msg, ex, code);
+ next.error(msg, ex, code);
}
}
private void init() {
+ if (next == null) {
+ throw new NullPointerException(ErrorManager.class.getName());
+ }
+
File dir = this.emailStore;
if (dir.getClass() != File.class) { //for security.
throw new IllegalArgumentException(dir.getClass().getName());
@@ -147,12 +151,12 @@
}
if (!dir.canRead()) { //Can throw under a security manager.
- internal.error(dir.getAbsolutePath(),
+ super.error(dir.getAbsolutePath(),
new SecurityException("read"), ErrorManager.OPEN_FAILURE);
}
if (!dir.canWrite()) { //Can throw under a security manager.
- internal.error(dir.getAbsolutePath(),
+ super.error(dir.getAbsolutePath(),
new SecurityException("write"), ErrorManager.OPEN_FAILURE);
}
}
@@ -204,7 +208,7 @@
try {
out.close();
} catch (IOException IOE) {
- internal.error(out.toString(), IOE, ErrorManager.CLOSE_FAILURE);
+ super.error(out.toString(), IOE, ErrorManager.CLOSE_FAILURE);
}
}
}
@@ -217,13 +221,13 @@
tmp.deleteOnExit();
} catch (final RuntimeException shutdown) {
if (!tmp.delete()) {
- internal.error(tmp.getAbsolutePath(), shutdown,
+ super.error(tmp.getAbsolutePath(), shutdown,
ErrorManager.CLOSE_FAILURE);
}
}
}
} catch (SecurityException SE) {
- internal.error(tmp.toString(), SE, ErrorManager.CLOSE_FAILURE);
+ super.error(tmp.toString(), SE, ErrorManager.CLOSE_FAILURE);
}
}
}
diff -r e593aca29ee4 -r 12192f2eee28 logging/src/main/java/maildemo.properties
--- a/logging/src/main/java/maildemo.properties Fri Nov 05 14:17:09 2010 -0700
+++ b/logging/src/main/java/maildemo.properties Fri Nov 05 14:18:29 2010 -0700
@@ -1,38 +1,38 @@
-# This can be used by setting the system property
-# -Djava.util.logging.config.file=path to this file
-
-# Taken from the JDK defaults.
-handlers= java.util.logging.ConsoleHandler
-.level= INFO
-java.util.logging.ConsoleHandler.level = INFO
-java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
-
-
-# Set the mail handler demo logger level
-MailHandlerDemo.level = ALL
-
-# Configure the MailHandler.
-com.sun.mail.util.logging.MailHandler.level = ALL
-com.sun.mail.util.logging.MailHandler.mail.host = my-mail-server
-com.sun.mail.util.logging.MailHandler.mail.from = me_at_example.com
-com.sun.mail.util.logging.MailHandler.mail.to = me_at_example.com
-com.sun.mail.util.logging.MailHandler.verify = local
-
-# Add attachments if needed.
-#com.sun.mail.util.logging.MailHandler.attachment.formatters = java.util.logging.SimpleFormatter, java.util.logging.XMLFormatter
-
-# No filters.
-#com.sun.mail.util.logging.MailHandler.attachment.filters = null, null
-
-# One formatter and one string.
-#com.sun.mail.util.logging.MailHandler.attachment.names = SummaryNameFormatter, error.xml
-
-
-# Store messages on error by installing the FileErrorManager (demo code).
-com.sun.mail.util.logging.MailHandler.errorManager = FileErrorManager
-
-# Configure the FileErrorManager for demo (not required).
-# com.sun.mail.demo.FileErrorManager.pattern = path-to-dir
-
-# Debug mail transport issues.
-mail.debug = false
+# This can be used by setting the system property
+# -Djava.util.logging.config.file=path to this file
+
+# Taken from the JDK defaults.
+handlers= java.util.logging.ConsoleHandler
+.level= INFO
+java.util.logging.ConsoleHandler.level = INFO
+java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
+
+
+# Set the mail handler demo logger level
+MailHandlerDemo.level = ALL
+
+# Configure the MailHandler.
+com.sun.mail.util.logging.MailHandler.level = ALL
+com.sun.mail.util.logging.MailHandler.mail.host = my-mail-server
+com.sun.mail.util.logging.MailHandler.mail.from = me_at_example.com
+com.sun.mail.util.logging.MailHandler.mail.to = me_at_example.com
+com.sun.mail.util.logging.MailHandler.verify = local
+
+# Add attachments if needed.
+#com.sun.mail.util.logging.MailHandler.attachment.formatters = java.util.logging.SimpleFormatter, java.util.logging.XMLFormatter
+
+# No filters.
+#com.sun.mail.util.logging.MailHandler.attachment.filters = null, null
+
+# One formatter and one string.
+#com.sun.mail.util.logging.MailHandler.attachment.names = SummaryNameFormatter, error.xml
+
+
+# Store messages on error by installing the FileErrorManager (demo code).
+com.sun.mail.util.logging.MailHandler.errorManager = FileErrorManager
+
+# Configure the FileErrorManager for demo (not required).
+# FileErrorManager.pattern = path-to-dir
+
+# Debug mail transport issues.
+mail.debug = false
diff -r e593aca29ee4 -r 12192f2eee28 mail/src/main/java/com/sun/mail/util/logging/MailHandler.java
--- a/mail/src/main/java/com/sun/mail/util/logging/MailHandler.java Fri Nov 05 14:17:09 2010 -0700
+++ b/mail/src/main/java/com/sun/mail/util/logging/MailHandler.java Fri Nov 05 14:18:29 2010 -0700
@@ -1816,23 +1816,19 @@
try {
if (all != null && all.length > 0) {
t = session.getTransport(all[0]);
+ session.getProperty("mail.transport.protocol"); //force copy
} else {
MessagingException me =
new MessagingException("No recipient addresses.");
reportError(msg, me, ErrorManager.OPEN_FAILURE);
throw me;
}
- } catch (final MessagingException smtp) {
+ } catch (final MessagingException protocol) {
try {
- t = session.getTransport("smtp");
- } catch (final MessagingException tryDefault) {
- try {
- t = session.getTransport();
- } catch (final MessagingException fail) {
- smtp.setNextException(tryDefault);
- tryDefault.setNextException(fail);
- throw smtp;
- }
+ t = session.getTransport();
+ } catch (final MessagingException fail) {
+ fail.setNextException(protocol);
+ throw fail;
}
}
@@ -1862,37 +1858,18 @@
Address[] from = abort.getFrom();
Address sender = abort.getSender();
-
- if (from == null || from.length == 0) {
- String noFromAddress = "No from address.";
- MessagingException me;
- try { //no from address, check security policy and host name.
- System.getProperty("user.name");
- if (InetAddress.getLocalHost().getHostName().length() == 0) {
- me = new MessagingException(noFromAddress,
- new UnknownHostException());
- } else {
- me = new MessagingException(noFromAddress);
- }
- } catch (final SecurityException SE) {
- me = new MessagingException(noFromAddress, SE);
- } catch (final IOException IOE) {
- me = new MessagingException(noFromAddress, IOE);
- }
- reportError(msg, me, ErrorManager.OPEN_FAILURE);
- } else {
- if (abort.getHeader("From", ",") != null) {
- for (int i = 0; i < from.length; ++i) {
- if (from[i].equals(sender)) {
- reportError(msg, new MessagingException(
- "Sender address equals from address."),
- ErrorManager.OPEN_FAILURE);
- break;
- }
+ if (abort.getHeader("From", ",") != null) {
+ assert from != null;
+ for (int i = 0; i < from.length; ++i) {
+ if (from[i].equals(sender)) {
+ reportError(msg, new MessagingException(
+ "Sender address equals from address."),
+ ErrorManager.OPEN_FAILURE);
+ break;
}
}
}
-
+
if (all != null) {
for (int i = 0; i < all.length; ++i) {
Address a = all[i];