james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject svn commit: r674229 - in /james/mime4j/trunk/src: main/java/org/apache/james/mime4j/MimeTokenStream.java test/java/org/apache/james/mime4j/ExampleMail.java test/java/org/apache/james/mime4j/MimeTokenStreamTest.java
Date Sat, 05 Jul 2008 19:23:13 GMT
Author: rdonkin
Date: Sat Jul  5 12:23:12 2008
New Revision: 674229

URL: http://svn.apache.org/viewvc?rev=674229&view=rev
Log:
Fix NullPointerException

Added:
    james/mime4j/trunk/src/test/java/org/apache/james/mime4j/MimeTokenStreamTest.java
Modified:
    james/mime4j/trunk/src/main/java/org/apache/james/mime4j/MimeTokenStream.java
    james/mime4j/trunk/src/test/java/org/apache/james/mime4j/ExampleMail.java

Modified: james/mime4j/trunk/src/main/java/org/apache/james/mime4j/MimeTokenStream.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/src/main/java/org/apache/james/mime4j/MimeTokenStream.java?rev=674229&r1=674228&r2=674229&view=diff
==============================================================================
--- james/mime4j/trunk/src/main/java/org/apache/james/mime4j/MimeTokenStream.java (original)
+++ james/mime4j/trunk/src/main/java/org/apache/james/mime4j/MimeTokenStream.java Sat Jul
 5 12:23:12 2008
@@ -213,7 +213,9 @@
      */
     public void setRecursionMode(int mode) {
         recursionMode = mode;
-        currentStateMachine.setRecursionMode(mode);
+        if (currentStateMachine != null) {
+            currentStateMachine.setRecursionMode(mode);
+        }
     }
 
     /**

Modified: james/mime4j/trunk/src/test/java/org/apache/james/mime4j/ExampleMail.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/src/test/java/org/apache/james/mime4j/ExampleMail.java?rev=674229&r1=674228&r2=674229&view=diff
==============================================================================
--- james/mime4j/trunk/src/test/java/org/apache/james/mime4j/ExampleMail.java (original)
+++ james/mime4j/trunk/src/test/java/org/apache/james/mime4j/ExampleMail.java Sat Jul  5 12:23:12
2008
@@ -300,7 +300,40 @@
     "Delivered-To: robertburrelldonkin@gmail.com\r\n" +
     "\r\n" + ONE_PART_MIME_ASCII_BODY;
     
-    
+    public static final String INNER_MAIL = "From: Timothy Tayler <tim@example.org>\r\n"
+
+    "To: Joshua Tetley <joshua@example.org>\r\n" +
+    "Date: Tue, 12 Feb 2008 17:34:09 +0000 (GMT)\r\n" +
+    "Subject: Multipart Without RFC822 Part\r\n" +
+    "Content-Type: multipart/mixed;boundary=42\r\n\r\n" +
+    "--42\r\n" +
+    "Content-Type:text/plain; charset=US-ASCII\r\n\r\n" +
+    "First part of this mail\r\n" +
+    "--42\r\n" +
+    "Content-Type:text/plain; charset=US-ASCII\r\n\r\n" +
+    "Second part of this mail\r\n" +
+    "--42--\r\n";
+
+    public static final String MAIL_WITH_RFC822_PART = "MIME-Version: 1.0\r\n" +
+    "From: Timothy Tayler <tim@example.org>\r\n" +
+    "To: Joshua Tetley <joshua@example.org>\r\n" +
+    "Date: Tue, 12 Feb 2008 17:34:09 +0000 (GMT)\r\n" +
+    "Subject: Multipart With RFC822 Part\r\n" +
+    "Content-Type: multipart/mixed;boundary=1729\r\n\r\n" +
+    "A short premable\r\n" +
+    "--1729\r\n\r\n" +
+    "First part has no headers\r\n" +
+    "--1729\r\n" +
+    "Content-Type: text/plain; charset=US-ASCII\r\n\r\n" +
+    "Second part is plain text\r\n" +
+    "--1729\r\n" +
+    "Content-Type: message/rfc822\r\n\r\n" +
+    INNER_MAIL +
+    "--1729\r\n" +
+    "Content-Type: text/plain; charset=US-ASCII\r\n\r\n" +
+    "Last part is plain text\r\n" +
+    "--1729--\r\n" +
+    "The End";
+        
     public static final String ONE_PART_MIME_8859 = "Received: by 10.114.126.16 with HTTP;
Thu, 6 Mar 2008 10:02:03 -0800 (PST)\r\n" +
     "Message-ID: <f470f68e0803061002n22bc4124he14015a4b6d6327f@mail.gmail.com>\r\n"
+
     "Date: Thu, 6 Mar 2008 18:02:03 +0000\r\n" +
@@ -488,7 +521,7 @@
     public static final byte[] MULTIPART_WITH_BINARY_ATTACHMENTS_BYTES = US_ASCII.encode(MULTIPART_WITH_BINARY_ATTACHMENTS).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);
 
     public static final byte[] ascii(String text) {
         

Added: james/mime4j/trunk/src/test/java/org/apache/james/mime4j/MimeTokenStreamTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/src/test/java/org/apache/james/mime4j/MimeTokenStreamTest.java?rev=674229&view=auto
==============================================================================
--- james/mime4j/trunk/src/test/java/org/apache/james/mime4j/MimeTokenStreamTest.java (added)
+++ james/mime4j/trunk/src/test/java/org/apache/james/mime4j/MimeTokenStreamTest.java Sat
Jul  5 12:23:12 2008
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.james.mime4j;
+
+import java.io.ByteArrayInputStream;
+
+import junit.framework.TestCase;
+
+public class MimeTokenStreamTest extends TestCase {
+
+    MimeTokenStream stream;
+    
+    public void setUp() throws Exception {
+        stream = new MimeTokenStream();
+    }
+    
+    public void testSetRecursionModeBeforeParse() throws Exception {
+        stream.setRecursionMode(RecursionMode.M_NO_RECURSE);
+        stream.parse(new ByteArrayInputStream(ExampleMail.MAIL_WITH_RFC822_PART_BYTES));
+        checkNextIs(EntityStates.T_START_HEADER);
+        checkNextIs(EntityStates.T_FIELD);
+        checkNextIs(EntityStates.T_FIELD);
+        checkNextIs(EntityStates.T_FIELD);
+        checkNextIs(EntityStates.T_FIELD);
+        checkNextIs(EntityStates.T_FIELD);
+        checkNextIs(EntityStates.T_FIELD);
+        checkNextIs(EntityStates.T_END_HEADER);
+        checkNextIs(EntityStates.T_START_MULTIPART);
+        checkNextIs(EntityStates.T_PREAMBLE);
+        checkNextIs(EntityStates.T_START_BODYPART);
+        checkNextIs(EntityStates.T_START_HEADER);
+        checkNextIs(EntityStates.T_END_HEADER);
+        checkNextIs(EntityStates.T_BODY);
+        checkNextIs(EntityStates.T_END_BODYPART);
+        checkNextIs(EntityStates.T_START_BODYPART);
+        checkNextIs(EntityStates.T_START_HEADER);
+        checkNextIs(EntityStates.T_FIELD);
+        checkNextIs(EntityStates.T_END_HEADER);
+        checkNextIs(EntityStates.T_BODY);
+        checkNextIs(EntityStates.T_END_BODYPART);
+        checkNextIs(EntityStates.T_START_BODYPART);
+        checkNextIs(EntityStates.T_START_HEADER);
+        checkNextIs(EntityStates.T_FIELD);
+        checkNextIs(EntityStates.T_END_HEADER);
+        checkNextIs(EntityStates.T_BODY);
+        checkNextIs(EntityStates.T_END_BODYPART);
+        checkNextIs(EntityStates.T_START_BODYPART);
+        checkNextIs(EntityStates.T_START_HEADER);
+        checkNextIs(EntityStates.T_FIELD);
+        checkNextIs(EntityStates.T_END_HEADER);
+        checkNextIs(EntityStates.T_BODY);
+        checkNextIs(EntityStates.T_END_BODYPART);
+        checkNextIs(EntityStates.T_EPILOGUE);
+        checkNextIs(EntityStates.T_END_MULTIPART);
+        checkNextIs(EntityStates.T_END_MESSAGE);
+        checkNextIs(EntityStates.T_END_OF_STREAM);
+    }
+    
+    private void checkNextIs(int expected) throws Exception {
+        assertEquals(MimeTokenStream.stateToString(expected), MimeTokenStream.stateToString(stream.next()));
       
+    }
+}



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