james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nik...@apache.org
Subject svn commit: r675871 - in /james/mime4j/trunk/src: main/java/org/apache/james/mime4j/MimeEntity.java test/java/org/apache/james/mime4j/MultipartTokensTest.java
Date Fri, 11 Jul 2008 08:58:24 GMT
Author: niklas
Date: Fri Jul 11 01:58:23 2008
New Revision: 675871

URL: http://svn.apache.org/viewvc?rev=675871&view=rev
Log:
Resolved MIME4J-48: Messages containing qp or base64 encoded embedded messages should now
parse as expected.

Modified:
    james/mime4j/trunk/src/main/java/org/apache/james/mime4j/MimeEntity.java
    james/mime4j/trunk/src/test/java/org/apache/james/mime4j/MultipartTokensTest.java

Modified: james/mime4j/trunk/src/main/java/org/apache/james/mime4j/MimeEntity.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/src/main/java/org/apache/james/mime4j/MimeEntity.java?rev=675871&r1=675870&r2=675871&view=diff
==============================================================================
--- james/mime4j/trunk/src/main/java/org/apache/james/mime4j/MimeEntity.java (original)
+++ james/mime4j/trunk/src/main/java/org/apache/james/mime4j/MimeEntity.java Fri Jul 11 01:58:23
2008
@@ -191,14 +191,18 @@
     private EntityStateMachine nextMessage() {
         String transferEncoding = body.getTransferEncoding();
         InputStream instream;
+        InputBuffer buffer;
         if (MimeUtil.isBase64Encoding(transferEncoding)) {
             log.debug("base64 encoded message/rfc822 detected");
-            instream = new Base64InputStream(mimeStream);                    
+            instream = new Base64InputStream(dataStream);                    
+            buffer = new InputBuffer(instream, 4 * 1024);
         } else if (MimeUtil.isQuotedPrintableEncoded(transferEncoding)) {
             log.debug("quoted-printable encoded message/rfc822 detected");
-            instream = new QuotedPrintableInputStream(mimeStream);                    
+            instream = new QuotedPrintableInputStream(dataStream);                    
+            buffer = new InputBuffer(instream, 4 * 1024);
         } else {
             instream = dataStream;
+            buffer = inbuffer;
         }
         
         if (recursionMode == RecursionMode.M_RAW) {
@@ -208,7 +212,7 @@
             MimeEntity message = new MimeEntity(
                     rootStream, 
                     instream,
-                    inbuffer, 
+                    buffer, 
                     body, 
                     EntityStates.T_START_MESSAGE, 
                     EntityStates.T_END_MESSAGE,

Modified: james/mime4j/trunk/src/test/java/org/apache/james/mime4j/MultipartTokensTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/src/test/java/org/apache/james/mime4j/MultipartTokensTest.java?rev=675871&r1=675870&r2=675871&view=diff
==============================================================================
--- james/mime4j/trunk/src/test/java/org/apache/james/mime4j/MultipartTokensTest.java (original)
+++ james/mime4j/trunk/src/test/java/org/apache/james/mime4j/MultipartTokensTest.java Fri
Jul 11 01:58:23 2008
@@ -23,6 +23,8 @@
 import java.io.IOException;
 import java.nio.charset.Charset;
 
+import org.apache.commons.io.IOUtils;
+
 import junit.framework.TestCase;
 
 public class MultipartTokensTest extends TestCase {
@@ -62,6 +64,31 @@
     "\r\n" +
     "--42--\r\n";
     
+    public static final String COMPLEX_QP_MESSAGE = 
+        "Content-Transfer-Encoding: quoted-printable\r\n" +
+        "Content-Type: message/rfc822; charset=us-ascii\r\n" +
+        "\r\n" +
+        "Subject: The subject\r\n" +
+        "Content-Type: multipart/alternative;\r\n" +
+        "        boundary=3D=22----=3DNextPart=22\r\n" +
+        "\r\n" +
+        "This is a multi-part message in MIME format.\r\n" +
+        "\r\n" +
+        "------=3DNextPart\r\n" +
+        "Content-Type: text/plain;\r\n" +
+        "        charset=3D=22iso-8859-1=22\r\n" +
+        "\r\n" +
+        "Some text\r\n" +
+        "\r\n" +
+        "------=3DNextPart\r\n" +
+        "Content-Type: text/html;\r\n" +
+        "        charset=3D=22iso-8859-1=22\r\n" +
+        "\r\n" +
+        "<HTML><BODY>=3D Some HTML =3D</BODY></HTML>\r\n" +
+        "------=3DNextPart--\r\n" +
+        "\r\n" +
+        "\r\n";
+    
     MimeTokenStream parser;
     
     protected void setUp() throws Exception {
@@ -201,6 +228,46 @@
         checkState(MimeTokenStream.T_END_OF_STREAM);
     }
 
+    public void testShouldParseMessagesWithEmbeddedQuotedPrintableEncodedMessage() throws
Exception {
+        parser.parse(new ByteArrayInputStream(US_ASCII.encode(COMPLEX_QP_MESSAGE).array()));
+        checkState(MimeTokenStream.T_START_HEADER);
+        checkState(MimeTokenStream.T_FIELD);
+        checkState(MimeTokenStream.T_FIELD);
+        checkState(MimeTokenStream.T_END_HEADER);
+        checkState(MimeTokenStream.T_START_MESSAGE);
+        checkState(MimeTokenStream.T_START_HEADER);
+        checkState(MimeTokenStream.T_FIELD);
+        checkState(MimeTokenStream.T_FIELD);
+        checkState(MimeTokenStream.T_END_HEADER);
+        checkState(MimeTokenStream.T_START_MULTIPART);
+        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_BODY);
+        assertEquals("text/plain", parser.getBodyDescriptor().getMimeType());
+        assertEquals("iso-8859-1", parser.getBodyDescriptor().getCharset());
+        assertEquals("Some text\r\n", 
+                IOUtils.toString(parser.getInputStream()));
+        checkState(MimeTokenStream.T_END_BODYPART);
+        checkState(MimeTokenStream.T_START_BODYPART);
+        checkState(MimeTokenStream.T_START_HEADER);
+        checkState(MimeTokenStream.T_FIELD);
+        checkState(MimeTokenStream.T_END_HEADER);
+        checkState(MimeTokenStream.T_BODY);
+        assertEquals("text/html", parser.getBodyDescriptor().getMimeType());
+        assertEquals("iso-8859-1", parser.getBodyDescriptor().getCharset());
+        assertEquals("<HTML><BODY>= Some HTML =</BODY></HTML>", 
+                IOUtils.toString(parser.getInputStream()));
+        checkState(MimeTokenStream.T_END_BODYPART);
+        checkState(MimeTokenStream.T_EPILOGUE);
+        checkState(MimeTokenStream.T_END_MULTIPART);
+        checkState(MimeTokenStream.T_END_MESSAGE);
+        checkState(MimeTokenStream.T_END_MESSAGE);
+        checkState(MimeTokenStream.T_END_OF_STREAM);
+    }
+    
     public void testMultipartMessageWithoutHeader() throws Exception {
         parser.parseHeadless(new ByteArrayInputStream(US_ASCII.encode(BODY).array()), 
                 "multipart/mixed;boundary=1729");



---------------------------------------------------------------------
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