james-mime4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject svn commit: r928280 - in /james/mime4j/trunk/core/src: main/java/org/apache/james/mime4j/io/ main/java/org/apache/james/mime4j/stream/ test/java/org/apache/james/mime4j/ test/java/org/apache/james/mime4j/stream/ test/resources/testmsgs/
Date Sat, 27 Mar 2010 21:13:15 GMT
Author: bago
Date: Sat Mar 27 21:13:15 2010
New Revision: 928280

URL: http://svn.apache.org/viewvc?rev=928280&view=rev
Log:
Altered parser to skip the T_PREAMBLE token when there is no preamble in the input message.
Updated tests to avoid expecting T_PREAMBLE. Updated roundtrip tests expectation with the
right results. (MIME4J-177)

Modified:
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/MimeBoundaryInputStream.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/ExampleMail.java
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/MimeTokenNoRecurseTest.java
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/MultipartTokensTest.java
    james/mime4j/trunk/core/src/test/resources/testmsgs/ending-boundaries.out
    james/mime4j/trunk/core/src/test/resources/testmsgs/ending-boundaries.xml
    james/mime4j/trunk/core/src/test/resources/testmsgs/ending-boundaries_decoded.xml
    james/mime4j/trunk/core/src/test/resources/testmsgs/misplaced-boundary.out
    james/mime4j/trunk/core/src/test/resources/testmsgs/misplaced-boundary.xml
    james/mime4j/trunk/core/src/test/resources/testmsgs/misplaced-boundary_decoded.xml

Modified: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/MimeBoundaryInputStream.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/MimeBoundaryInputStream.java?rev=928280&r1=928279&r2=928280&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/MimeBoundaryInputStream.java
(original)
+++ james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/MimeBoundaryInputStream.java
Sat Mar 27 21:13:15 2010
@@ -42,6 +42,13 @@ public class MimeBoundaryInputStream ext
     private BufferedLineReaderInputStream buffer;
 
     /**
+     * Store the first buffer length.
+     * Used to distinguish between an empty preamble and 
+     * no preamble. 
+     */
+    private int initialLength;
+
+    /**
      * Creates a new MimeBoundaryInputStream.
      * 
      * @param inbuffer The underlying stream.
@@ -61,6 +68,7 @@ public class MimeBoundaryInputStream ext
         this.atBoundary = false;
         this.boundaryLen = 0;
         this.lastPart = false;
+        this.initialLength = -1;
         this.completed = false;
         
         this.boundary = new byte[boundary.length() + 2];
@@ -222,9 +230,14 @@ public class MimeBoundaryInputStream ext
         return bytesRead;
     }
     
+    public boolean isEmptyStream() {
+        return initialLength == 0;
+    }
+    
     private void calculateBoundaryLen() throws IOException {
         boundaryLen = boundary.length;
         int len = limit - buffer.pos();
+        if (len >= 0 && initialLength == -1) initialLength = len;
         if (len > 0) {
             if (buffer.charAt(limit - 1) == '\n') {
                 boundaryLen++;

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=928280&r1=928279&r2=928280&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 Sat
Mar 27 21:13:15 2010
@@ -138,11 +138,14 @@ public class MimeEntity extends Abstract
             if (dataStream.isUsed()) {
                 advanceToBoundary();            
                 state = EntityStates.T_END_MULTIPART;
+                break;
             } else {
                 createMimePartStream();
                 state = EntityStates.T_PREAMBLE;
+                
+                if (!currentMimePartStream.isEmptyStream()) break;
+                // continue to next state
             }
-            break;
         case EntityStates.T_PREAMBLE:
         	// removed specific code. Fallback to T_IN_BODYPART that
         	// better handle missing parts.

Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/ExampleMail.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/ExampleMail.java?rev=928280&r1=928279&r2=928280&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/ExampleMail.java (original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/ExampleMail.java Sat Mar
27 21:13:15 2010
@@ -165,8 +165,8 @@ public class ExampleMail {
         "<html><head><title>Rhubarb</title></head><body>Rhubarb!</body></html>\r\n"
+
         "\r\n--1729--\r\n" +
         "This is the epilogue\r\n";
-    
-    public static final String MULTIPART_WITH_BINARY_ATTACHMENTS = 
+
+    public static final String MULTIPART_WITH_BINARY_ATTACHMENTS_HEADER = 
         "Return-Path: <robertburrelldonkin@blueyonder.co.uk>\r\n" +
         "Received: (qmail 18554 invoked from network); 25 May 2008 14:38:53 -0000\r\n" +
         "Received: from unknown (HELO p3presmtp01-16.prod.phx3.secureserver.net)\r\n" +
@@ -216,9 +216,9 @@ public class ExampleMail {
         "X-Nonspam: None\r\n" +
         "X-fetched-from: mail.xmlmapt.org\r\n" +
         "X-Evolution-Source: imap://rob@thebes/\r\n" +
-        "\r\n" +
-        "\r\n" +
-        "--=-tIdGYVstQJghyEDATnJ+\r\n" +
+        "\r\n";
+    
+    public static final String MULTIPART_WITH_BINARY_ATTACHMENTS_BODY = "--=-tIdGYVstQJghyEDATnJ+\r\n"
+
         "Content-Type: text/plain\r\n" +
         "Content-Transfer-Encoding: 7bit\r\n" +
         "\r\n" +
@@ -316,7 +316,19 @@ public class ExampleMail {
         "Rhubarb Rhubarb Rhubarb Rhubarb Rhubarb Rhubarb Rhubarb Rhubarb Rhubarb\r\n" +
         "\r\n" +
         "--=-tIdGYVstQJghyEDATnJ+--\r\n";
-    
+
+    public static final String MULTIPART_WITH_BINARY_ATTACHMENTS = MULTIPART_WITH_BINARY_ATTACHMENTS_HEADER
+
+        "\r\n" + MULTIPART_WITH_BINARY_ATTACHMENTS_BODY;
+
+    public static final String MULTIPART_WITH_BINARY_ATTACHMENTS_NOPREAMBLE = MULTIPART_WITH_BINARY_ATTACHMENTS_HEADER
+
+        MULTIPART_WITH_BINARY_ATTACHMENTS_BODY;
+
+    public static final String MULTIPART_WITH_BINARY_ATTACHMENTS_PREAMBLE_EPILOGUE = MULTIPART_WITH_BINARY_ATTACHMENTS_HEADER
+
+        "This is a preamble\r\n" +
+        "With 2 lines\r\n" + MULTIPART_WITH_BINARY_ATTACHMENTS_BODY +
+        "This is an epilogue\r\n" +
+        "With 2 lines\r\n";
+
     public static final String ONE_PART_MIME_ASCII_BODY = "A single part MIME mail.\r\n";
 
     public static final String RFC822_SIMPLE_BODY = "This is a very simple email.\r\n";
@@ -633,6 +645,8 @@ public class ExampleMail {
     public static final byte[] ONE_PART_MIME_ASCII_BYTES = US_ASCII.encode(ONE_PART_MIME_ASCII).array();
     public static final byte[] ONE_PART_MIME_8859_BYTES = LATIN1.encode(ONE_PART_MIME_8859).array();
     public static final byte[] MULTIPART_WITH_BINARY_ATTACHMENTS_BYTES = US_ASCII.encode(MULTIPART_WITH_BINARY_ATTACHMENTS).array();
+    public static final byte[] MULTIPART_WITH_BINARY_ATTACHMENTS_NOPREAMBLE_BYTES = US_ASCII.encode(MULTIPART_WITH_BINARY_ATTACHMENTS_NOPREAMBLE).array();
+    public static final byte[] MULTIPART_WITH_BINARY_ATTACHMENTS_PREAMBLE_EPILOGUE_BYTES
= US_ASCII.encode(MULTIPART_WITH_BINARY_ATTACHMENTS_PREAMBLE_EPILOGUE).array();
     public static final byte[] ONE_PART_MIME_ASCII_COMMENT_IN_MIME_VERSION_BYTES = US_ASCII.encode(ONE_PART_MIME_ASCII_COMMENT_IN_MIME_VERSION).array();
     public static final byte[] ONE_PART_MIME_ASCII_MIME_VERSION_SPANS_TWO_LINES_BYTES = US_ASCII.encode(ONE_PART_MIME_ASCII_MIME_VERSION_SPANS_TWO_LINES).array();
     public static final byte[] MAIL_WITH_RFC822_PART_BYTES = ascii(MAIL_WITH_RFC822_PART);

Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/MimeTokenNoRecurseTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/MimeTokenNoRecurseTest.java?rev=928280&r1=928279&r2=928280&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/MimeTokenNoRecurseTest.java
(original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/MimeTokenNoRecurseTest.java
Sat Mar 27 21:13:15 2010
@@ -108,7 +108,8 @@ public class MimeTokenNoRecurseTest exte
         nextIs(MimeTokenStream.T_FIELD);
         nextIs(MimeTokenStream.T_END_HEADER);
         nextIs(MimeTokenStream.T_START_MULTIPART);
-        nextIs(MimeTokenStream.T_PREAMBLE);
+        // an empty preamble should not raise a T_PREAMBLE event
+        // nextIs(MimeTokenStream.T_PREAMBLE);
         nextShouldBeStandardPart(true);
         nextShouldBeStandardPart(true);
         nextIs(MimeTokenStream.T_EPILOGUE);

Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/MultipartTokensTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/MultipartTokensTest.java?rev=928280&r1=928279&r2=928280&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/MultipartTokensTest.java
(original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/MultipartTokensTest.java
Sat Mar 27 21:13:15 2010
@@ -153,13 +153,15 @@ public class MultipartTokensTest extends
         checkState(MimeTokenStream.T_FIELD);
         checkState(MimeTokenStream.T_END_HEADER);
         checkState(MimeTokenStream.T_START_MULTIPART);
-        checkState(MimeTokenStream.T_PREAMBLE);
+        // an empty preamble should not rais a T_PREAMBLE event
+        // checkState(MimeTokenStream.T_PREAMBLE);
         checkState(MimeTokenStream.T_START_BODYPART);
         checkState(MimeTokenStream.T_START_HEADER);
         checkState(MimeTokenStream.T_FIELD);
         checkState(MimeTokenStream.T_END_HEADER);
         checkState(MimeTokenStream.T_START_MULTIPART);
-        checkState(MimeTokenStream.T_PREAMBLE);
+        // an empty preamble should not rais a T_PREAMBLE event
+        // checkState(MimeTokenStream.T_PREAMBLE);
         checkState(MimeTokenStream.T_START_BODYPART);
         checkState(MimeTokenStream.T_START_HEADER);
         checkState(MimeTokenStream.T_FIELD);

Modified: james/mime4j/trunk/core/src/test/resources/testmsgs/ending-boundaries.out
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/resources/testmsgs/ending-boundaries.out?rev=928280&r1=928279&r2=928280&view=diff
==============================================================================
Binary files - no diff available.

Modified: james/mime4j/trunk/core/src/test/resources/testmsgs/ending-boundaries.xml
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/resources/testmsgs/ending-boundaries.xml?rev=928280&r1=928279&r2=928280&view=diff
==============================================================================
Binary files - no diff available.

Modified: james/mime4j/trunk/core/src/test/resources/testmsgs/ending-boundaries_decoded.xml
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/resources/testmsgs/ending-boundaries_decoded.xml?rev=928280&r1=928279&r2=928280&view=diff
==============================================================================
Binary files - no diff available.

Modified: james/mime4j/trunk/core/src/test/resources/testmsgs/misplaced-boundary.out
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/resources/testmsgs/misplaced-boundary.out?rev=928280&r1=928279&r2=928280&view=diff
==============================================================================
Binary files - no diff available.

Modified: james/mime4j/trunk/core/src/test/resources/testmsgs/misplaced-boundary.xml
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/resources/testmsgs/misplaced-boundary.xml?rev=928280&r1=928279&r2=928280&view=diff
==============================================================================
Binary files - no diff available.

Modified: james/mime4j/trunk/core/src/test/resources/testmsgs/misplaced-boundary_decoded.xml
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/resources/testmsgs/misplaced-boundary_decoded.xml?rev=928280&r1=928279&r2=928280&view=diff
==============================================================================
Binary files - no diff available.



Mime
View raw message