james-mime4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1556608 - in /james/mime4j/trunk: core/src/main/java/org/apache/james/mime4j/stream/ core/src/test/java/org/apache/james/mime4j/stream/ dom/src/main/java/org/apache/james/mime4j/message/ dom/src/test/java/org/apache/james/mime4j/message/
Date Wed, 08 Jan 2014 19:16:38 GMT
Author: olegk
Date: Wed Jan  8 19:16:38 2014
New Revision: 1556608

URL: http://svn.apache.org/r1556608
Log:
MIME4J-235: Content-Type fields containing RFC 2231 formatted boundary attribute cause NPE

Modified:
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/FallbackBodyDescriptorBuilder.java
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/MimeEntity.java
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/FallbackBodyDescriptorBuilderTest.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/DefaultBodyDescriptorBuilder.java
    james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/message/MaximalBodyDescriptorTest.java

Modified: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/FallbackBodyDescriptorBuilder.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/FallbackBodyDescriptorBuilder.java?rev=1556608&r1=1556607&r2=1556608&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/FallbackBodyDescriptorBuilder.java
(original)
+++ james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/FallbackBodyDescriptorBuilder.java
Wed Jan  8 19:16:38 2014
@@ -184,9 +184,8 @@ class FallbackBodyDescriptorBuilder impl
         }
         String b = params.get("boundary");
 
-        if (main != null
-                && ((main.startsWith("multipart/") && b != null)
-                        || !main.startsWith("multipart/"))) {
+        boolean multipart = main != null && main.startsWith("multipart/");
+        if (multipart && b != null || !multipart) {
             mimeType = main;
             mediaType = type;
             subType = subtype;

Modified: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/MimeEntity.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/MimeEntity.java?rev=1556608&r1=1556607&r2=1556608&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/MimeEntity.java (original)
+++ james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/MimeEntity.java Wed
Jan  8 19:16:38 2014
@@ -362,6 +362,9 @@ class MimeEntity implements EntityStateM
 
     private void createMimePartStream() throws MimeException, IOException {
         String boundary = body.getBoundary();
+        if (boundary == null) {
+            throw new MimeException("Multipart body does not have a valid boundary");
+        }
         try {
             currentMimePartStream = new MimeBoundaryInputStream(inbuffer, boundary,
                     config.isStrictParsing());

Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/FallbackBodyDescriptorBuilderTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/FallbackBodyDescriptorBuilderTest.java?rev=1556608&r1=1556607&r2=1556608&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/FallbackBodyDescriptorBuilderTest.java
(original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/FallbackBodyDescriptorBuilderTest.java
Wed Jan  8 19:16:38 2014
@@ -134,6 +134,13 @@ public class FallbackBodyDescriptorBuild
 
     }
 
+    public void testMultipartNoBoundary() throws Exception {
+        BodyDescriptorBuilder builder = new FallbackBodyDescriptorBuilder();
+        builder.addField(new RawField("Content-Type", "multipart/yada; "));
+        BodyDescriptor bd = builder.build();
+        assertEquals("text/plain", bd.getMimeType());
+    }
+
     public void testGetContentLength() throws Exception {
         BodyDescriptorBuilder builder = new FallbackBodyDescriptorBuilder();
         BodyDescriptor bd = builder.build();

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/DefaultBodyDescriptorBuilder.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/DefaultBodyDescriptorBuilder.java?rev=1556608&r1=1556607&r2=1556608&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/DefaultBodyDescriptorBuilder.java
(original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/DefaultBodyDescriptorBuilder.java
Wed Jan  8 19:16:38 2014
@@ -108,6 +108,13 @@ public class DefaultBodyDescriptorBuilde
             actualSubType = contentTypeField.getSubType();
             actualCharset = contentTypeField.getCharset();
             actualBoundary = contentTypeField.getBoundary();
+
+            boolean multipart = actualMediaType != null && actualMediaType.equalsIgnoreCase("multipart");
+            if (multipart && actualBoundary == null) {
+                actualMimeType = null;
+                actualMediaType = null;
+                actualSubType = null;
+            }
         }
         if (actualMimeType == null) {
             if (MimeUtil.isSameMimeType("multipart/digest", parentMimeType)) {

Modified: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/message/MaximalBodyDescriptorTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/message/MaximalBodyDescriptorTest.java?rev=1556608&r1=1556607&r2=1556608&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/message/MaximalBodyDescriptorTest.java
(original)
+++ james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/message/MaximalBodyDescriptorTest.java
Wed Jan  8 19:16:38 2014
@@ -177,6 +177,14 @@ public class MaximalBodyDescriptorTest {
     }
 
     @Test
+    public void testMultipartNoBoundary() throws Exception {
+        BodyDescriptorBuilder builder = new DefaultBodyDescriptorBuilder();
+        builder.addField(new RawField("Content-Type", "multipart/yada; "));
+        BodyDescriptor bd = builder.build();
+        assertEquals("text/plain", bd.getMimeType());
+    }
+
+    @Test
     public void testDoDefaultToUsAsciiWhenUntyped() throws Exception {
         BodyDescriptorBuilder builder = new DefaultBodyDescriptorBuilder();
         builder.addField(new RawField("To", "me@example.org"));



Mime
View raw message