james-mime4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1092053 - in /james/mime4j/trunk: core/src/main/java/org/apache/james/mime4j/io/ core/src/main/java/org/apache/james/mime4j/stream/ core/src/test/java/org/apache/james/mime4j/stream/ core/src/test/resources/testmsgs/ dom/src/main/java/org/...
Date Thu, 14 Apr 2011 08:30:12 GMT
Author: olegk
Date: Thu Apr 14 08:30:11 2011
New Revision: 1092053

URL: http://svn.apache.org/viewvc?rev=1092053&view=rev
Log:
MIME4J-187: Fixed inconsistency in handling of empty preambles and epilogues

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/stream/MimeTokenEmbeddedMessageTest.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/MultipartStreamTest.java
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/MultipartTokensTest.java
    james/mime4j/trunk/core/src/test/resources/testmsgs/example.xml
    james/mime4j/trunk/core/src/test/resources/testmsgs/example_decoded.xml
    james/mime4j/trunk/core/src/test/resources/testmsgs/missing-boundary.xml
    james/mime4j/trunk/core/src/test/resources/testmsgs/missing-boundary_decoded.xml
    james/mime4j/trunk/core/src/test/resources/testmsgs/missing-inner-boundary.xml
    james/mime4j/trunk/core/src/test/resources/testmsgs/missing-inner-boundary_decoded.xml
    james/mime4j/trunk/core/src/test/resources/testmsgs/missing-inner-start-boundary.xml
    james/mime4j/trunk/core/src/test/resources/testmsgs/missing-inner-start-boundary_decoded.xml
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MimeWriter.java
    james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MultipartFormTest.java

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=1092053&r1=1092052&r2=1092053&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
Thu Apr 14 08:30:11 2011
@@ -234,6 +234,10 @@ public class MimeBoundaryInputStream ext
         return initialLength == 0;
     }
     
+    public boolean isFullyConsumed() {
+        return completed && !buffer.hasBufferedData();
+    }
+    
     private void calculateBoundaryLen() throws IOException {
         boundaryLen = boundary.length;
         int len = limit - buffer.pos();

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=1092053&r1=1092052&r2=1092053&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 Thu
Apr 14 08:30:11 2011
@@ -170,7 +170,8 @@ class MimeEntity extends AbstractEntity 
                 createMimePartStream();
                 state = EntityState.T_PREAMBLE;
 
-                if (!currentMimePartStream.isEmptyStream()) break;
+                boolean empty = currentMimePartStream.isEmptyStream();
+                if (!empty) break;
                 // continue to next state
             }
         case T_PREAMBLE:
@@ -187,9 +188,11 @@ class MimeEntity extends AbstractEntity 
                     return nextMimeEntity();
                 }
             }
+            boolean empty = currentMimePartStream.isFullyConsumed();
             clearMimePartStream();
             state = EntityState.T_EPILOGUE;
-            break;
+            if (!empty) break;
+            // continue to next state
         case T_EPILOGUE:
             state = EntityState.T_END_MULTIPART;
             break;

Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/MimeTokenEmbeddedMessageTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/MimeTokenEmbeddedMessageTest.java?rev=1092053&r1=1092052&r2=1092053&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/MimeTokenEmbeddedMessageTest.java
(original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/MimeTokenEmbeddedMessageTest.java
Thu Apr 14 08:30:11 2011
@@ -106,7 +106,6 @@ public class MimeTokenEmbeddedMessageTes
         nextIs(EntityState.T_BODY);
         checkInputStream("CUSTARDCUSTARDCUSTARD\r\n");
         nextIs(EntityState.T_END_BODYPART);
-        nextIs(EntityState.T_EPILOGUE);
         nextIs(EntityState.T_END_MULTIPART);   
         nextIs(EntityState.T_END_MESSAGE);
         nextIs(EntityState.T_END_BODYPART);

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=1092053&r1=1092052&r2=1092053&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
Thu Apr 14 08:30:11 2011
@@ -108,11 +108,8 @@ public class MimeTokenNoRecurseTest exte
         nextIs(EntityState.T_FIELD);
         nextIs(EntityState.T_END_HEADER);
         nextIs(EntityState.T_START_MULTIPART);
-        // an empty preamble should not raise a T_PREAMBLE event
-        // nextIs(EntityStates.T_PREAMBLE);
         nextShouldBeStandardPart(true);
         nextShouldBeStandardPart(true);
-        nextIs(EntityState.T_EPILOGUE);
         nextIs(EntityState.T_END_MULTIPART);
         nextIs(EntityState.T_END_MESSAGE);
         nextIs(EntityState.T_END_BODYPART);

Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/MultipartStreamTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/MultipartStreamTest.java?rev=1092053&r1=1092052&r2=1092053&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/MultipartStreamTest.java
(original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/MultipartStreamTest.java
Thu Apr 14 08:30:11 2011
@@ -136,7 +136,6 @@ public class MultipartStreamTest extends
         checkState(EntityState.T_END_HEADER);
         checkState(EntityState.T_BODY);
         checkState(EntityState.T_END_BODYPART);
-        checkState(EntityState.T_EPILOGUE);
         checkState(EntityState.T_END_MULTIPART);
         checkState(EntityState.T_END_MESSAGE);
         checkState(EntityState.T_END_OF_STREAM);

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=1092053&r1=1092052&r2=1092053&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
Thu Apr 14 08:30:11 2011
@@ -39,7 +39,8 @@ public class MultipartTokensTest extends
                 "--1729\r\n" +
                 "Content-Type: text/plain; charset=US-ASCII\r\n\r\n" +
                 "Some more text\r\n" +
-                "--1729--\r\n";
+                "--1729--\r\n" +
+                "An Epilogue\r\n";
     public static final String MESSAGE = "To: Road Runner <runner@example.org>\r\n"
+
             "From: Wile E. Cayote <wile@example.org>\r\n" +
             "Date: Tue, 12 Feb 2008 17:34:09 +0000 (GMT)\r\n" +
@@ -64,7 +65,8 @@ public class MultipartTokensTest extends
     "\r\n" +
     "Custard!" +
     "\r\n" +
-    "--42--\r\n";
+    "--42--\r\n" +
+    "A little epilogue\r\n";
     
     public static final String COMPLEX_QP_MESSAGE = 
         "Content-Transfer-Encoding: quoted-printable\r\n" +
@@ -153,15 +155,11 @@ public class MultipartTokensTest extends
         checkState(EntityState.T_FIELD);
         checkState(EntityState.T_END_HEADER);
         checkState(EntityState.T_START_MULTIPART);
-        // an empty preamble should not rais a T_PREAMBLE event
-        // checkState(EntityStates.T_PREAMBLE);
         checkState(EntityState.T_START_BODYPART);
         checkState(EntityState.T_START_HEADER);
         checkState(EntityState.T_FIELD);
         checkState(EntityState.T_END_HEADER);
         checkState(EntityState.T_START_MULTIPART);
-        // an empty preamble should not rais a T_PREAMBLE event
-        // checkState(EntityStates.T_PREAMBLE);
         checkState(EntityState.T_START_BODYPART);
         checkState(EntityState.T_START_HEADER);
         checkState(EntityState.T_FIELD);
@@ -171,7 +169,6 @@ public class MultipartTokensTest extends
         checkState(EntityState.T_EPILOGUE);
         checkState(EntityState.T_END_MULTIPART);
         checkState(EntityState.T_END_BODYPART);
-        checkState(EntityState.T_EPILOGUE);
         checkState(EntityState.T_END_MULTIPART);
         checkState(EntityState.T_END_MESSAGE);
         checkState(EntityState.T_END_OF_STREAM);

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

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

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

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

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

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

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

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

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MimeWriter.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MimeWriter.java?rev=1092053&r1=1092052&r2=1092053&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MimeWriter.java (original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MimeWriter.java Thu
Apr 14 08:30:11 2011
@@ -177,8 +177,8 @@ public class MimeWriter {
         out.write(DASHES);
         writeBytes(boundary, out);
         out.write(DASHES);
+        out.write(CRLF);
         if (epilogue != null) {
-            out.write(CRLF);
             writeBytes(epilogue, out);
         }
     }

Modified: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MultipartFormTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MultipartFormTest.java?rev=1092053&r1=1092052&r2=1092053&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MultipartFormTest.java
(original)
+++ james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MultipartFormTest.java
Thu Apr 14 08:30:11 2011
@@ -82,7 +82,7 @@ public class MultipartFormTest extends T
             "Content-Type: text/plain\r\n" +
             "\r\n" +
             "all kind of stuff\r\n" +
-            "--foo--";
+            "--foo--\r\n";
         String s = out.toString("US-ASCII");
         assertEquals(expected, s);
     }



Mime
View raw message