james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject svn commit: r659956 - in /james/mime4j/trunk/src: main/java/org/apache/james/mime4j/message/Header.java main/java/org/apache/james/mime4j/message/Message.java test/java/org/apache/james/mime4j/message/MessageCompleteMailTest.java
Date Sun, 25 May 2008 10:56:27 GMT
Author: rdonkin
Date: Sun May 25 03:56:26 2008
New Revision: 659956

URL: http://svn.apache.org/viewvc?rev=659956&view=rev
Log:
Confirmed and fixed MIME4J-36 NullPointerException in Header.writeTo with missing Content-Type
https://issues.apache.org/jira/browse/MIME4J-36.

Modified:
    james/mime4j/trunk/src/main/java/org/apache/james/mime4j/message/Header.java
    james/mime4j/trunk/src/main/java/org/apache/james/mime4j/message/Message.java
    james/mime4j/trunk/src/test/java/org/apache/james/mime4j/message/MessageCompleteMailTest.java

Modified: james/mime4j/trunk/src/main/java/org/apache/james/mime4j/message/Header.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/src/main/java/org/apache/james/mime4j/message/Header.java?rev=659956&r1=659955&r2=659956&view=diff
==============================================================================
--- james/mime4j/trunk/src/main/java/org/apache/james/mime4j/message/Header.java (original)
+++ james/mime4j/trunk/src/main/java/org/apache/james/mime4j/message/Header.java Sun May 25
03:56:26 2008
@@ -167,11 +167,16 @@
     public void writeTo(final OutputStream out, int mode) throws IOException, MimeException
{
         Charset charset = null;
         if (mode == MessageUtils.LENIENT) {
-            ContentTypeField cf = ((ContentTypeField) getField(Field.CONTENT_TYPE));
-            if (cf != null && cf.getCharset() != null) {
-                charset = CharsetUtil.getCharset(cf.getCharset());
+            final ContentTypeField contentTypeField = ((ContentTypeField) getField(Field.CONTENT_TYPE));
+            if (contentTypeField == null) {
+                charset = MessageUtils.DEFAULT_CHARSET;
             } else {
-                charset = MessageUtils.ISO_8859_1;
+                final String contentTypeFieldCharset = contentTypeField.getCharset();
+                if (contentTypeField != null && contentTypeFieldCharset != null)
{
+                    charset = CharsetUtil.getCharset(contentTypeFieldCharset);
+                } else {
+                    charset = MessageUtils.ISO_8859_1;
+                }
             }
         } else {
             charset = MessageUtils.DEFAULT_CHARSET;

Modified: james/mime4j/trunk/src/main/java/org/apache/james/mime4j/message/Message.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/src/main/java/org/apache/james/mime4j/message/Message.java?rev=659956&r1=659955&r2=659956&view=diff
==============================================================================
--- james/mime4j/trunk/src/main/java/org/apache/james/mime4j/message/Message.java (original)
+++ james/mime4j/trunk/src/main/java/org/apache/james/mime4j/message/Message.java Sun May
25 03:56:26 2008
@@ -32,6 +32,7 @@
 import org.apache.james.mime4j.decoder.QuotedPrintableInputStream;
 import org.apache.james.mime4j.field.Field;
 import org.apache.james.mime4j.field.UnstructuredField;
+import org.apache.james.mime4j.util.MessageUtils;
 import org.apache.james.mime4j.util.MimeUtil;
 
 
@@ -103,6 +104,24 @@
         }
     }
     
+    /**
+     * Writes out the content of this message..
+     * @param out not null
+     * @param mode header out validation mode {@link MessageUtils}
+     * @throws MimeException 
+     * @see org.apache.james.mime4j.message.Entity#writeTo(java.io.OutputStream)
+     */
+    public void writeTo(OutputStream out, int mode) throws IOException, MimeException {
+        getHeader().writeTo(out, mode);
+
+        Body body = getBody();
+        if (body instanceof Multipart) {
+            Multipart mp = (Multipart) body;
+            mp.writeTo(out);
+        } else {
+            body.writeTo(out);
+        }
+    }
     
     private class MessageBuilder implements ContentHandler {
         private Stack stack = new Stack();

Modified: james/mime4j/trunk/src/test/java/org/apache/james/mime4j/message/MessageCompleteMailTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/src/test/java/org/apache/james/mime4j/message/MessageCompleteMailTest.java?rev=659956&r1=659955&r2=659956&view=diff
==============================================================================
--- james/mime4j/trunk/src/test/java/org/apache/james/mime4j/message/MessageCompleteMailTest.java
(original)
+++ james/mime4j/trunk/src/test/java/org/apache/james/mime4j/message/MessageCompleteMailTest.java
Sun May 25 03:56:26 2008
@@ -20,10 +20,10 @@
 
 import java.io.ByteArrayInputStream;
 
-import org.apache.james.mime4j.ExampleMail;
-
 import junit.framework.TestCase;
 
+import org.apache.james.mime4j.ExampleMail;
+
 public class MessageCompleteMailTest extends TestCase {
 
     protected void setUp() throws Exception {
@@ -47,7 +47,7 @@
         Multipart part = (Multipart)message.getBody();
         assertEquals("mixed", part.getSubType());
     }
-    
+
     private Message createMessage(byte[] octets) throws Exception {
         ByteArrayInputStream in = new ByteArrayInputStream(octets);
         Message message = new Message(in);



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message