james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject svn commit: r635185 - 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/MimeTokenStreamBodyDescriptorTest.java
Date Sun, 09 Mar 2008 07:42:13 GMT
Author: rdonkin
Date: Sat Mar  8 23:42:10 2008
New Revision: 635185

URL: http://svn.apache.org/viewvc?rev=635185&view=rev
Log:
Allow getBodyDescriptor when in preamble or epilogue

Added:
    james/mime4j/trunk/src/test/java/org/apache/james/mime4j/MimeTokenStreamBodyDescriptorTest.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=635185&r1=635184&r2=635185&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 Mar
 8 23:42:10 2008
@@ -824,14 +824,22 @@
     }
     
     /**
-     * This method is valid, if {@link #getState()} returns
-     * {@link #T_BODY}, or {@link #T_START_MULTIPART}. It returns the current
-     * entities body descriptor.
+     * <p>Gets a descriptor for the current entity.
+     * This method is valid if {@link #getState()} returns:</p>
+     * <ul>
+     * <li>{@link #T_BODY}</li>
+     * <li>{@link #T_START_MULTIPART}</li>
+     * <li>{@link #T_EPILOGUE}</li>
+     * <li>{@link #T_PREAMBLE}</li>
+     * </ul>
+     * @return <code>BodyDescriptor</code>, not nulls
      */
     public BodyDescriptor getBodyDescriptor() {
         switch (getState()) {
             case T_BODY:
             case T_START_MULTIPART:
+            case T_PREAMBLE:
+            case T_EPILOGUE:
                 return ((Entity) currentStateMachine).body;
             default:
                 throw new IllegalStateException("Expected state to be T_BODY.");

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=635185&r1=635184&r2=635185&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 Mar  8 23:42:10
2008
@@ -207,6 +207,28 @@
     public static final String MIME_MIXED_MULTIPART_VARIOUS_ENCODINGS_END = 
             "\r\n--1729--\r\n";
     
+    public static final String MIME_MIXED_ALTERNATIVE = 
+        "From: Timothy Tayler <timothy@example.org>\r\n" +
+        "To: Samual Smith <samual@example.org>\r\n" +
+        "Date: Thu, 14 Feb 2008 12:00:00 +0000 (GMT)\r\n" +
+        "Subject: A Multipart Email\r\n" +
+        "Content-Type: multipart/alternative;boundary=1729\r\n\r\n" +
+        "Start with a preamble\r\n" +
+        "\r\n--1729\r\n" +
+        "Content-Type: applcation/xhtml+xml\r\n\r\n" +
+        "<!DOCTYPE html\r\n" +
+        "PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\r\n" +
+        "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\r\n" +
+        "<html><head><title>Rhubarb</title></head><body>Rhubarb!</body></html>\r\n"
+
+        "\r\n--1729\r\n" +
+        "Content-Type: text/plain; charset=US-ASCII\r\n\r\n" +
+        "Rhubarb!\r\n" +
+        "\r\n--1729\r\n" +
+        "Content-Type: text/html; charset=US-ASCII\r\n\r\n" +
+        "<html><head><title>Rhubarb</title></head><body>Rhubarb!</body></html>\r\n"
+
+        "\r\n--1729--\r\n" +
+        "This is the epilogue\r\n";
+    
     private static final byte[][] MIME_MIXED_MULTIPART_VARIOUS_ENCODINGS_BYTE_ARRAYS = {
         ascii(MIME_MIXED_MULTIPART_VARIOUS_ENCODINGS_ONE),
         ascii(MIME_MIXED_MULTIPART_VARIOUS_ENCODINGS_7BIT),
@@ -216,6 +238,7 @@
         EncodeUtils.toBase64(ascii(MIME_MIXED_MULTIPART_VARIOUS_ENCODINGS_BASE64)),
         ascii(MIME_MIXED_MULTIPART_VARIOUS_ENCODINGS_END),
     };
+    public static final byte[] MIME_MIXED_ALTERNATIVE_BYTES = ascii(MIME_MIXED_ALTERNATIVE);
     public static final byte[] MIME_MIXED_MULTIPART_VARIOUS_ENCODINGS_BYTES = join(MIME_MIXED_MULTIPART_VARIOUS_ENCODINGS_BYTE_ARRAYS);
     public static final byte[] ONE_PART_MIME_QUOTED_PRINTABLE_ASCII_BYTES = ascii(ONE_PART_MIME_QUOTED_PRINTABLE_ASCII);
     public static final byte[] ONE_PART_MIME_BASE64_LATIN1_BYTES = join(ascii(ONE_PART_MIME_BASE64_LATIN1_HEADERS),
ONE_PART_MIME_BASE64_LATIN1_ENCODED);

Added: james/mime4j/trunk/src/test/java/org/apache/james/mime4j/MimeTokenStreamBodyDescriptorTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/src/test/java/org/apache/james/mime4j/MimeTokenStreamBodyDescriptorTest.java?rev=635185&view=auto
==============================================================================
--- james/mime4j/trunk/src/test/java/org/apache/james/mime4j/MimeTokenStreamBodyDescriptorTest.java
(added)
+++ james/mime4j/trunk/src/test/java/org/apache/james/mime4j/MimeTokenStreamBodyDescriptorTest.java
Sat Mar  8 23:42:10 2008
@@ -0,0 +1,90 @@
+/*
+ * 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 MimeTokenStreamBodyDescriptorTest extends TestCase {
+
+    MimeTokenStream parser;
+    
+    protected void setUp() throws Exception {
+        super.setUp();
+        parser = new MimeTokenStream();
+        parser.parse(new ByteArrayInputStream(ExampleMail.MIME_MIXED_ALTERNATIVE_BYTES));
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    public void testShouldReturnValidDescriptorForPreamble() throws Exception {
+        assertEquals(MimeTokenStream.stateToString(MimeTokenStream.T_START_HEADER), MimeTokenStream.stateToString(parser.next()));
+        assertEquals(MimeTokenStream.stateToString(MimeTokenStream.T_FIELD), MimeTokenStream.stateToString(parser.next()));
+        assertEquals(MimeTokenStream.stateToString(MimeTokenStream.T_FIELD), MimeTokenStream.stateToString(parser.next()));
+        assertEquals(MimeTokenStream.stateToString(MimeTokenStream.T_FIELD), MimeTokenStream.stateToString(parser.next()));
+        assertEquals(MimeTokenStream.stateToString(MimeTokenStream.T_FIELD), MimeTokenStream.stateToString(parser.next()));
+        assertEquals(MimeTokenStream.stateToString(MimeTokenStream.T_FIELD), MimeTokenStream.stateToString(parser.next()));
+        assertEquals(MimeTokenStream.stateToString(MimeTokenStream.T_END_HEADER), MimeTokenStream.stateToString(parser.next()));
+        assertEquals(MimeTokenStream.stateToString(MimeTokenStream.T_START_MULTIPART), MimeTokenStream.stateToString(parser.next()));
+        assertEquals(MimeTokenStream.stateToString(MimeTokenStream.T_PREAMBLE), MimeTokenStream.stateToString(parser.next()));
+        BodyDescriptor descriptor = parser.getBodyDescriptor();
+        assertNotNull(descriptor);
+        assertEquals("1729", descriptor.getBoundary());
+        assertEquals( "multipart/alternative", descriptor.getMimeType());
+    }
+    
+    public void testShouldReturnValidDescriptorForEpilogue() throws Exception {
+        assertEquals(MimeTokenStream.stateToString(MimeTokenStream.T_START_HEADER), MimeTokenStream.stateToString(parser.next()));
+        assertEquals(MimeTokenStream.stateToString(MimeTokenStream.T_FIELD), MimeTokenStream.stateToString(parser.next()));
+        assertEquals(MimeTokenStream.stateToString(MimeTokenStream.T_FIELD), MimeTokenStream.stateToString(parser.next()));
+        assertEquals(MimeTokenStream.stateToString(MimeTokenStream.T_FIELD), MimeTokenStream.stateToString(parser.next()));
+        assertEquals(MimeTokenStream.stateToString(MimeTokenStream.T_FIELD), MimeTokenStream.stateToString(parser.next()));
+        assertEquals(MimeTokenStream.stateToString(MimeTokenStream.T_FIELD), MimeTokenStream.stateToString(parser.next()));
+        assertEquals(MimeTokenStream.stateToString(MimeTokenStream.T_END_HEADER), MimeTokenStream.stateToString(parser.next()));
+        assertEquals(MimeTokenStream.stateToString(MimeTokenStream.T_START_MULTIPART), MimeTokenStream.stateToString(parser.next()));
+        assertEquals(MimeTokenStream.stateToString(MimeTokenStream.T_PREAMBLE), MimeTokenStream.stateToString(parser.next()));
+        assertEquals(MimeTokenStream.stateToString(MimeTokenStream.T_START_BODYPART), MimeTokenStream.stateToString(parser.next()));
+        assertEquals(MimeTokenStream.stateToString(MimeTokenStream.T_START_HEADER), MimeTokenStream.stateToString(parser.next()));
+        assertEquals(MimeTokenStream.stateToString(MimeTokenStream.T_FIELD), MimeTokenStream.stateToString(parser.next()));
+        assertEquals(MimeTokenStream.stateToString(MimeTokenStream.T_END_HEADER), MimeTokenStream.stateToString(parser.next()));
+        assertEquals(MimeTokenStream.stateToString(MimeTokenStream.T_BODY), MimeTokenStream.stateToString(parser.next()));
+        assertEquals(MimeTokenStream.stateToString(MimeTokenStream.T_END_BODYPART), MimeTokenStream.stateToString(parser.next()));
+        assertEquals(MimeTokenStream.stateToString(MimeTokenStream.T_START_BODYPART), MimeTokenStream.stateToString(parser.next()));
+        assertEquals(MimeTokenStream.stateToString(MimeTokenStream.T_START_HEADER), MimeTokenStream.stateToString(parser.next()));
+        assertEquals(MimeTokenStream.stateToString(MimeTokenStream.T_FIELD), MimeTokenStream.stateToString(parser.next()));
+        assertEquals(MimeTokenStream.stateToString(MimeTokenStream.T_END_HEADER), MimeTokenStream.stateToString(parser.next()));
+        assertEquals(MimeTokenStream.stateToString(MimeTokenStream.T_BODY), MimeTokenStream.stateToString(parser.next()));
+        assertEquals(MimeTokenStream.stateToString(MimeTokenStream.T_END_BODYPART), MimeTokenStream.stateToString(parser.next()));
+        assertEquals(MimeTokenStream.stateToString(MimeTokenStream.T_START_BODYPART), MimeTokenStream.stateToString(parser.next()));
+        assertEquals(MimeTokenStream.stateToString(MimeTokenStream.T_START_HEADER), MimeTokenStream.stateToString(parser.next()));
+        assertEquals(MimeTokenStream.stateToString(MimeTokenStream.T_FIELD), MimeTokenStream.stateToString(parser.next()));
+        assertEquals(MimeTokenStream.stateToString(MimeTokenStream.T_END_HEADER), MimeTokenStream.stateToString(parser.next()));
+        assertEquals(MimeTokenStream.stateToString(MimeTokenStream.T_BODY), MimeTokenStream.stateToString(parser.next()));
+        assertEquals(MimeTokenStream.stateToString(MimeTokenStream.T_END_BODYPART), MimeTokenStream.stateToString(parser.next()));
+        assertEquals(MimeTokenStream.stateToString(MimeTokenStream.T_EPILOGUE), MimeTokenStream.stateToString(parser.next()));
+
+        BodyDescriptor descriptor = parser.getBodyDescriptor();
+        assertNotNull(descriptor);
+        assertEquals("1729", descriptor.getBoundary());
+        assertEquals( "multipart/alternative", descriptor.getMimeType());
+    }
+}



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