james-mime4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1124803 - in /james/mime4j/trunk: core/src/main/java/org/apache/james/mime4j/parser/ core/src/main/java/org/apache/james/mime4j/stream/ core/src/test/java/org/apache/james/mime4j/parser/ core/src/test/java/org/apache/james/mime4j/stream/ d...
Date Thu, 19 May 2011 14:05:11 GMT
Author: olegk
Date: Thu May 19 14:05:09 2011
New Revision: 1124803

URL: http://svn.apache.org/viewvc?rev=1124803&view=rev
Log:
MIME4J-116: duplicate parsing of header fields can now be avoided by passing an instance of FieldParser to the MimeTokenStream. The field parser can choose to parse fields either eagerly or lazily. Lazy parsing is used per default

Added:
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/FieldParser.java
      - copied, changed from r1124735, james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/FieldParser.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MinimalBodyDescriptor.java   (with props)
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MinimalBodyDescriptorFactory.java   (with props)
Removed:
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/FieldParser.java
Modified:
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/parser/MimeStreamParser.java
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/AbstractEntity.java
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/DefaultBodyDescriptor.java
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/MimeEntity.java
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/MimeTokenStream.java
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/parser/DefaultBodyDescriptorTest.java
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/BaseTestForBodyDescriptors.java
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/MimeEntityTest.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/dom/field/ContentTypeField.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/AddressListFieldImpl.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentDispositionFieldImpl.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentTransferEncodingFieldImpl.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentTypeFieldImpl.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/DateTimeFieldImpl.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/DefaultFieldParser.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/DelegatingFieldParser.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/Fields.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/MailboxFieldImpl.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/MailboxListFieldImpl.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/UnstructuredFieldImpl.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/EntityBuilder.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MaximalBodyDescriptor.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MessageBuilderImpl.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MimeBuilder.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/SimpleContentHandler.java
    james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/ContentTypeFieldTest.java
    james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/message/MaximalBodyDescriptorTest.java

Modified: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/parser/MimeStreamParser.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/parser/MimeStreamParser.java?rev=1124803&r1=1124802&r2=1124803&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/parser/MimeStreamParser.java (original)
+++ james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/parser/MimeStreamParser.java Thu May 19 14:05:09 2011
@@ -26,6 +26,7 @@ import org.apache.james.mime4j.MimeExcep
 import org.apache.james.mime4j.codec.DecodeMonitor;
 import org.apache.james.mime4j.stream.BodyDescriptor;
 import org.apache.james.mime4j.stream.EntityState;
+import org.apache.james.mime4j.stream.FieldParser;
 import org.apache.james.mime4j.stream.MimeEntityConfig;
 import org.apache.james.mime4j.stream.MimeTokenStream;
 import org.apache.james.mime4j.stream.MutableBodyDescriptorFactory;
@@ -65,8 +66,9 @@ public class MimeStreamParser {
             final MimeEntityConfig config, 
             boolean clone,
             final DecodeMonitor monitor,
+            final FieldParser<?> fieldParser,
             final MutableBodyDescriptorFactory bodyDescFactory) {
-        this(new MimeTokenStream(clone ? config.clone() : config, monitor, bodyDescFactory));
+        this(new MimeTokenStream(clone ? config.clone() : config, monitor, fieldParser, bodyDescFactory));
     }
 
     public MimeStreamParser(final MimeEntityConfig config, boolean clone) {
@@ -76,17 +78,18 @@ public class MimeStreamParser {
     public MimeStreamParser(
             final MimeEntityConfig config,
             final DecodeMonitor monitor,
+            final FieldParser<?> fieldParser,
             final MutableBodyDescriptorFactory bodyDescFactory) {
         this(config != null ? config : new MimeEntityConfig(), config != null, 
-                monitor, bodyDescFactory);
+                monitor, fieldParser, bodyDescFactory);
     }
 
     public MimeStreamParser(final MimeEntityConfig config) {
-        this(config, null, null);
+        this(config, null, null, null);
     }
 
     public MimeStreamParser() {
-        this(new MimeEntityConfig(), false, null, null);
+        this(new MimeEntityConfig(), false, null, null, null);
     }
     
     /**

Modified: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/AbstractEntity.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/AbstractEntity.java?rev=1124803&r1=1124802&r2=1124803&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/AbstractEntity.java (original)
+++ james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/AbstractEntity.java Thu May 19 14:05:09 2011
@@ -39,6 +39,7 @@ abstract class AbstractEntity implements
     protected final MimeEntityConfig config;
     protected final DecodeMonitor monitor;
     protected final FieldBuilder fieldBuilder;
+    protected final FieldParser<?> fieldParser;
     protected final MutableBodyDescriptor body;
 
     private final ByteArrayBuffer linebuf;
@@ -55,6 +56,7 @@ abstract class AbstractEntity implements
             EntityState endState,
             DecodeMonitor monitor,
             FieldBuilder fieldBuilder,
+            FieldParser<?> fieldParser,
             MutableBodyDescriptor body) {
         this.config = config;
         this.state = startState;
@@ -62,8 +64,8 @@ abstract class AbstractEntity implements
         this.endState = endState;
         this.monitor = monitor;
         this.fieldBuilder = fieldBuilder;
+        this.fieldParser = fieldParser;
         this.body = body;
-
         this.linebuf = new ByteArrayBuffer(64);
         this.lineCount = 0;
         this.endOfHeader = false;
@@ -141,13 +143,18 @@ abstract class AbstractEntity implements
             readRawField();
             try {
                 RawField rawfield = fieldBuilder.build();
-                field = rawfield;
                 if (rawfield == null) {
                     continue;
                 }
                 if (rawfield.getDelimiterIdx() != rawfield.getName().length()) {
                     monitor(Event.OBSOLETE_HEADER);
                 }
+                if (fieldParser != null) {
+                    field = fieldParser.parse(
+                            rawfield.getName(), rawfield.getBody(), rawfield.getRaw(), monitor);
+                } else {
+                    field = rawfield;
+                }
                 body.addField(field);
                 return true;
             } catch (MimeException e) {

Modified: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/DefaultBodyDescriptor.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/DefaultBodyDescriptor.java?rev=1124803&r1=1124802&r2=1124803&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/DefaultBodyDescriptor.java (original)
+++ james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/DefaultBodyDescriptor.java Thu May 19 14:05:09 2011
@@ -31,7 +31,7 @@ import org.apache.james.mime4j.util.Mime
  * Encapsulates the values of the MIME-specific header fields 
  * (which starts with <code>Content-</code>). 
  */
-public class DefaultBodyDescriptor implements MutableBodyDescriptor {
+class DefaultBodyDescriptor implements MutableBodyDescriptor {
     private static final String US_ASCII = "us-ascii";
 
     private static final String SUB_TYPE_EMAIL = "rfc822";

Copied: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/FieldParser.java (from r1124735, james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/FieldParser.java)
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/FieldParser.java?p2=james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/FieldParser.java&p1=james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/FieldParser.java&r1=1124735&r2=1124803&rev=1124803&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/FieldParser.java (original)
+++ james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/FieldParser.java Thu May 19 14:05:09 2011
@@ -17,14 +17,13 @@
  * under the License.                                           *
  ****************************************************************/
 
-package org.apache.james.mime4j.field;
+package org.apache.james.mime4j.stream;
 
 import org.apache.james.mime4j.codec.DecodeMonitor;
-import org.apache.james.mime4j.dom.field.ParsedField;
 import org.apache.james.mime4j.util.ByteSequence;
 
-public interface FieldParser<T extends ParsedField> {
+public interface FieldParser<T extends Field> {
     
-    T parse(final String name, final String body, final ByteSequence raw, DecodeMonitor monitor);
+    T parse(String name, String body, ByteSequence raw, DecodeMonitor monitor);
     
 }

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=1124803&r1=1124802&r2=1124803&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 May 19 14:05:09 2011
@@ -53,8 +53,9 @@ class MimeEntity extends AbstractEntity 
             EntityState endState,
             DecodeMonitor monitor,
             FieldBuilder fieldBuilder,
+            FieldParser<?> fieldParser,
             MutableBodyDescriptor body) {
-        super(config, startState, endState, monitor, fieldBuilder, body);
+        super(config, startState, endState, monitor, fieldBuilder, fieldParser, body);
         this.lineSource = lineSource;
         this.inbuffer = new BufferedLineReaderInputStream(
                 instream,
@@ -74,7 +75,7 @@ class MimeEntity extends AbstractEntity 
             MutableBodyDescriptor body) {
         this(lineSource, instream, config, startState, endState,
                 config.isStrictParsing() ? DecodeMonitor.STRICT : DecodeMonitor.SILENT,
-                new DefaultFieldBuilder(config.getMaxHeaderLen()), body);
+                new DefaultFieldBuilder(config.getMaxHeaderLen()), null, body);
     }
 
     MimeEntity(
@@ -85,18 +86,19 @@ class MimeEntity extends AbstractEntity 
         this(lineSource, instream, config,
                 EntityState.T_START_MESSAGE, EntityState.T_END_MESSAGE,
                 config.isStrictParsing() ? DecodeMonitor.STRICT : DecodeMonitor.SILENT,
-                new DefaultFieldBuilder(config.getMaxHeaderLen()), body);
+                new DefaultFieldBuilder(config.getMaxHeaderLen()), null, body);
     }
 
     MimeEntity(
             LineNumberSource lineSource,
             InputStream instream,
             FieldBuilder fieldBuilder,
+            FieldParser<?> fieldParser,
             MutableBodyDescriptor body) {
         this(lineSource, instream, new MimeEntityConfig(),
                 EntityState.T_START_MESSAGE, EntityState.T_END_MESSAGE,
                 DecodeMonitor.SILENT,
-                fieldBuilder, body);
+                fieldBuilder, fieldParser, body);
     }
 
     MimeEntity(
@@ -106,7 +108,7 @@ class MimeEntity extends AbstractEntity 
         this(lineSource, instream, new MimeEntityConfig(),
                 EntityState.T_START_MESSAGE, EntityState.T_END_MESSAGE,
                 DecodeMonitor.SILENT,
-                new DefaultFieldBuilder(-1), body);
+                new DefaultFieldBuilder(-1), null, body);
     }
 
     public RecursionMode getRecursionMode() {
@@ -276,6 +278,7 @@ class MimeEntity extends AbstractEntity 
                     endState,
                     monitor,
                     fieldBuilder,
+                    fieldParser,
                     body.newChild());
             mimeentity.setRecursionMode(recursionMode);
             return mimeentity;

Modified: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/MimeTokenStream.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/MimeTokenStream.java?rev=1124803&r1=1124802&r2=1124803&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/MimeTokenStream.java (original)
+++ james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/MimeTokenStream.java Thu May 19 14:05:09 2011
@@ -75,6 +75,7 @@ public class MimeTokenStream {
     private final MimeEntityConfig config;
     private final DecodeMonitor monitor;
     private final FieldBuilder fieldBuilder;
+    private final FieldParser<?> fieldParser;
     private final MutableBodyDescriptorFactory bodyDescFactory;
     private final LinkedList<EntityStateMachine> entities = new LinkedList<EntityStateMachine>();
     
@@ -96,31 +97,35 @@ public class MimeTokenStream {
     }
 
     public MimeTokenStream(final MimeEntityConfig config) {
-        this(config, null, null, null);
+        this(config, null, null, null, null);
     }
         
     public MimeTokenStream(
             final MimeEntityConfig config, 
+            final FieldParser<?> fieldParser,
             final MutableBodyDescriptorFactory bodyDescFactory) {
-        this(config, null, null, bodyDescFactory);
+        this(config, null, null, fieldParser, bodyDescFactory);
     }
 
     public MimeTokenStream(
             final MimeEntityConfig config, 
             final DecodeMonitor monitor,
+            final FieldParser<?> fieldParser,
             final MutableBodyDescriptorFactory bodyDescFactory) {
-        this(config, monitor, null, bodyDescFactory);
+        this(config, monitor, null, fieldParser, bodyDescFactory);
     }
 
     public MimeTokenStream(
             final MimeEntityConfig config, 
             final DecodeMonitor monitor,
             final FieldBuilder fieldBuilder,
+            final FieldParser<?> fieldParser,
             final MutableBodyDescriptorFactory bodyDescFactory) {
         super();
         this.config = config;
         this.fieldBuilder = fieldBuilder != null ? fieldBuilder : 
             new DefaultFieldBuilder(config.getMaxHeaderLen());
+        this.fieldParser = fieldParser;
         this.monitor = monitor != null ? monitor : 
             (config.isStrictParsing() ? DecodeMonitor.STRICT : DecodeMonitor.SILENT);
         this.bodyDescFactory = bodyDescFactory;
@@ -198,6 +203,7 @@ public class MimeTokenStream {
                 EntityState.T_END_MESSAGE,
                 monitor,
                 fieldBuilder,
+                fieldParser,
                 newBodyDescriptor);
 
         rootentity.setRecursionMode(recursionMode);

Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/parser/DefaultBodyDescriptorTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/parser/DefaultBodyDescriptorTest.java?rev=1124803&r1=1124802&r2=1124803&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/parser/DefaultBodyDescriptorTest.java (original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/parser/DefaultBodyDescriptorTest.java Thu May 19 14:05:09 2011
@@ -1,37 +0,0 @@
-/****************************************************************
- * 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.parser;
-
-import org.apache.james.mime4j.stream.BaseTestForBodyDescriptors;
-import org.apache.james.mime4j.stream.BodyDescriptor;
-import org.apache.james.mime4j.stream.DefaultBodyDescriptor;
-import org.apache.james.mime4j.stream.MutableBodyDescriptor;
-
-public class DefaultBodyDescriptorTest extends BaseTestForBodyDescriptors {
-    @Override
-    protected MutableBodyDescriptor newBodyDescriptor() {
-        return new DefaultBodyDescriptor();
-    }
-
-    @Override
-    protected MutableBodyDescriptor newBodyDescriptor(BodyDescriptor parent) {
-        return new DefaultBodyDescriptor(parent, null);
-    }
-}

Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/BaseTestForBodyDescriptors.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/BaseTestForBodyDescriptors.java?rev=1124803&r1=1124802&r2=1124803&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/BaseTestForBodyDescriptors.java (original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/BaseTestForBodyDescriptors.java Thu May 19 14:05:09 2011
@@ -53,15 +53,6 @@ public abstract class BaseTestForBodyDes
         assertEquals(2, bd.getContentTypeParameters().size());
         assertEquals(" value with\tspaces ", bd.getContentTypeParameters().get("param1"));
         assertEquals("\"value4 with escaped \" \"", bd.getContentTypeParameters().get("param2"));
-        
-        /*
-         * Make sure escaped characters (except ") are still escaped.
-         * The parameter value should be \n\"
-         */
-        bd = newBodyDescriptor();
-        bd.addField(new RawField("Content-Type ", "text/plain; param=\"\\n\\\\\\\"\""));
-        assertEquals(1, bd.getContentTypeParameters().size());
-        assertEquals("\\n\\\"", bd.getContentTypeParameters().get("param"));
     }
     
     public void testAddField() throws Exception {
@@ -73,10 +64,10 @@ public abstract class BaseTestForBodyDes
         bd = newBodyDescriptor();
         bd.addField(new RawField("Content-Type ", "text/plain; charset=ISO-8859-1"));
         assertEquals("text/plain", bd.getMimeType());
-        assertEquals("iso-8859-1", bd.getCharset());
+        assertEquals("ISO-8859-1", bd.getCharset());
         bd.addField(new RawField("Content-Type ", "text/html; charset=us-ascii"));
         assertEquals("text/plain", bd.getMimeType());
-        assertEquals("iso-8859-1", bd.getCharset());
+        assertEquals("ISO-8859-1", bd.getCharset());
     }
     
     public void testGetMimeType() throws Exception {
@@ -144,7 +135,7 @@ public abstract class BaseTestForBodyDes
         bd = newBodyDescriptor();
         assertEquals("us-ascii", bd.getCharset());
         bd.addField(new RawField("Content-Type ", "text/type; charset=ISO-8859-1"));
-        assertEquals("iso-8859-1", bd.getCharset());
+        assertEquals("ISO-8859-1", bd.getCharset());
         
         bd = newBodyDescriptor();
         assertEquals("us-ascii", bd.getCharset());
@@ -162,18 +153,6 @@ public abstract class BaseTestForBodyDes
         bd.addField(new RawField("Content-Type", "multipart/yada; boundary=yada"));
         assertEquals("yada", bd.getBoundary());
 
-        /*
-         * Test some weird parameters.
-         */
-        bd = newBodyDescriptor();
-        bd.addField(new RawField("Content-Type", "multipart/yada; boundary=yada yada"));
-        assertEquals("yada yada", bd.getBoundary());
-        
-        bd = newBodyDescriptor();
-        bd.addField(new RawField("Content-Type", "multipart/yada; boUNdarY= ya:*da; \tcharset\t =  big5"));
-        assertEquals("ya:*da", bd.getBoundary());
-        assertEquals("big5", bd.getCharset());
-        
         bd = newBodyDescriptor();
         bd.addField(new RawField("Content-Type", "multipart/yada; boUNdarY= \"ya \\\"\\\"\tda \\\"\"; "
                             + "\tcharset\t =  \"\\\"hepp\\\"  =us\t-ascii\""));

Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/MimeEntityTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/MimeEntityTest.java?rev=1124803&r1=1124802&r2=1124803&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/MimeEntityTest.java (original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/MimeEntityTest.java Thu May 19 14:05:09 2011
@@ -666,7 +666,7 @@ public class MimeEntityTest extends Test
 
         MimeEntity entity = new MimeEntity(
                 lineInput,
-                rawstream, fieldBuilder, new DefaultBodyDescriptor());
+                rawstream, fieldBuilder, null, new DefaultBodyDescriptor());
 
 
         assertEquals(EntityState.T_START_MESSAGE, entity.getState());

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/dom/field/ContentTypeField.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/dom/field/ContentTypeField.java?rev=1124803&r1=1124802&r2=1124803&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/dom/field/ContentTypeField.java (original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/dom/field/ContentTypeField.java Thu May 19 14:05:09 2011
@@ -44,6 +44,16 @@ public interface ContentTypeField extend
     String getMimeType();
 
     /**
+     * Gets the media type defined in this Content-Type field.
+     */
+    String getMediaType();
+
+    /**
+     * Gets the subtype defined in this Content-Type field.
+     */
+    String getSubType();
+    
+    /**
      * Gets the value of a parameter. Parameter names are case-insensitive.
      * 
      * @param name

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/AddressListFieldImpl.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/AddressListFieldImpl.java?rev=1124803&r1=1124802&r2=1124803&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/AddressListFieldImpl.java (original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/AddressListFieldImpl.java Thu May 19 14:05:09 2011
@@ -21,8 +21,10 @@ package org.apache.james.mime4j.field;
 
 import org.apache.james.mime4j.codec.DecodeMonitor;
 import org.apache.james.mime4j.dom.address.AddressList;
+import org.apache.james.mime4j.dom.field.AddressListField;
 import org.apache.james.mime4j.field.address.AddressBuilder;
 import org.apache.james.mime4j.field.address.ParseException;
+import org.apache.james.mime4j.stream.FieldParser;
 import org.apache.james.mime4j.util.ByteSequence;
 
 /**
@@ -72,8 +74,8 @@ public class AddressListFieldImpl extend
         parsed = true;
     }
 
-    static final FieldParser<AddressListFieldImpl> PARSER = new FieldParser<AddressListFieldImpl>() {
-        public AddressListFieldImpl parse(final String name, final String body,
+    public static final FieldParser<AddressListField> PARSER = new FieldParser<AddressListField>() {
+        public AddressListField parse(final String name, final String body,
                 final ByteSequence raw, DecodeMonitor monitor) {
             return new AddressListFieldImpl(name, body, raw, monitor);
         }

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentDispositionFieldImpl.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentDispositionFieldImpl.java?rev=1124803&r1=1124802&r2=1124803&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentDispositionFieldImpl.java (original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentDispositionFieldImpl.java Thu May 19 14:05:09 2011
@@ -28,10 +28,12 @@ import java.util.Locale;
 import java.util.Map;
 
 import org.apache.james.mime4j.codec.DecodeMonitor;
+import org.apache.james.mime4j.dom.field.ContentDispositionField;
 import org.apache.james.mime4j.field.contentdisposition.parser.ContentDispositionParser;
 import org.apache.james.mime4j.field.contentdisposition.parser.ParseException;
 import org.apache.james.mime4j.field.contentdisposition.parser.TokenMgrError;
 import org.apache.james.mime4j.field.datetime.parser.DateTimeParser;
+import org.apache.james.mime4j.stream.FieldParser;
 import org.apache.james.mime4j.util.ByteSequence;
 
 /**
@@ -244,8 +246,8 @@ public class ContentDispositionFieldImpl
         parsed = true;
     }
 
-    static final FieldParser<ContentDispositionFieldImpl> PARSER = new FieldParser<ContentDispositionFieldImpl>() {
-        public ContentDispositionFieldImpl parse(final String name, final String body,
+    public static final FieldParser<ContentDispositionField> PARSER = new FieldParser<ContentDispositionField>() {
+        public ContentDispositionField parse(final String name, final String body,
                 final ByteSequence raw, DecodeMonitor monitor) {
             return new ContentDispositionFieldImpl(name, body, raw, monitor);
         }

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentTransferEncodingFieldImpl.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentTransferEncodingFieldImpl.java?rev=1124803&r1=1124802&r2=1124803&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentTransferEncodingFieldImpl.java (original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentTransferEncodingFieldImpl.java Thu May 19 14:05:09 2011
@@ -21,6 +21,7 @@ package org.apache.james.mime4j.field;
 
 import org.apache.james.mime4j.codec.DecodeMonitor;
 import org.apache.james.mime4j.dom.field.ContentTransferEncodingField;
+import org.apache.james.mime4j.stream.FieldParser;
 import org.apache.james.mime4j.util.ByteSequence;
 import org.apache.james.mime4j.util.MimeUtil;
 
@@ -56,8 +57,8 @@ public class ContentTransferEncodingFiel
         return MimeUtil.ENC_7BIT;
     }
 
-    static final FieldParser<ContentTransferEncodingFieldImpl> PARSER = new FieldParser<ContentTransferEncodingFieldImpl>() {
-        public ContentTransferEncodingFieldImpl parse(final String name, final String body,
+    public static final FieldParser<ContentTransferEncodingField> PARSER = new FieldParser<ContentTransferEncodingField>() {
+        public ContentTransferEncodingField parse(final String name, final String body,
                 final ByteSequence raw, DecodeMonitor monitor) {
             return new ContentTransferEncodingFieldImpl(name, body, raw, monitor);
         }

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentTypeFieldImpl.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentTypeFieldImpl.java?rev=1124803&r1=1124802&r2=1124803&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentTypeFieldImpl.java (original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentTypeFieldImpl.java Thu May 19 14:05:09 2011
@@ -30,6 +30,7 @@ import org.apache.james.mime4j.dom.field
 import org.apache.james.mime4j.field.contenttype.parser.ContentTypeParser;
 import org.apache.james.mime4j.field.contenttype.parser.ParseException;
 import org.apache.james.mime4j.field.contenttype.parser.TokenMgrError;
+import org.apache.james.mime4j.stream.FieldParser;
 import org.apache.james.mime4j.util.ByteSequence;
 
 /**
@@ -38,7 +39,9 @@ import org.apache.james.mime4j.util.Byte
 public class ContentTypeFieldImpl extends AbstractField implements ContentTypeField {
     private boolean parsed = false;
 
-    private String mimeType = "";
+    private String mimeType = null;
+    private String mediaType = null;
+    private String subType = null;
     private Map<String, String> parameters = new HashMap<String, String>();
     private ParseException parseException;
 
@@ -68,6 +71,26 @@ public class ContentTypeFieldImpl extend
     }
 
     /**
+     * @see org.apache.james.mime4j.dom.field.ContentTypeField#getMediaType()
+     */
+    public String getMediaType() {
+        if (!parsed)
+            parse();
+
+        return mediaType;
+    }
+
+    /**
+     * @see org.apache.james.mime4j.dom.field.ContentTypeField#getSubType()
+     */
+    public String getSubType() {
+        if (!parsed)
+            parse();
+
+        return subType;
+    }
+
+    /**
      * @see org.apache.james.mime4j.dom.field.ContentTypeField#getParameter(java.lang.String)
      */
     public String getParameter(String name) {
@@ -94,7 +117,7 @@ public class ContentTypeFieldImpl extend
         if (!parsed)
             parse();
 
-        return this.mimeType.equalsIgnoreCase(mimeType);
+        return this.mimeType != null && this.mimeType.equalsIgnoreCase(mimeType);
     }
 
     /**
@@ -104,7 +127,7 @@ public class ContentTypeFieldImpl extend
         if (!parsed)
             parse();
 
-        return mimeType.startsWith(TYPE_MULTIPART_PREFIX);
+        return this.mimeType != null && mimeType.startsWith(TYPE_MULTIPART_PREFIX);
     }
 
     /**
@@ -135,7 +158,7 @@ public class ContentTypeFieldImpl extend
      */
     public static String getMimeType(ContentTypeField child,
             ContentTypeField parent) {
-        if (child == null || child.getMimeType().length() == 0
+        if (child == null || child.getMimeType() == null
                 || child.isMultipart() && child.getBoundary() == null) {
 
             if (parent != null && parent.isMimeType(TYPE_MULTIPART_DIGEST)) {
@@ -177,11 +200,11 @@ public class ContentTypeFieldImpl extend
             parseException = new ParseException(e.getMessage());
         }
 
-        final String type = parser.getType();
-        final String subType = parser.getSubType();
+        mediaType = parser.getType();
+        subType = parser.getSubType();
 
-        if (type != null && subType != null) {
-            mimeType = (type + "/" + subType).toLowerCase();
+        if (mediaType != null && subType != null) {
+            mimeType = (mediaType + "/" + subType).toLowerCase();
 
             List<String> paramNames = parser.getParamNames();
             List<String> paramValues = parser.getParamValues();
@@ -199,8 +222,8 @@ public class ContentTypeFieldImpl extend
         parsed = true;
     }
 
-    static final FieldParser<ContentTypeFieldImpl> PARSER = new FieldParser<ContentTypeFieldImpl>() {
-        public ContentTypeFieldImpl parse(final String name, final String body,
+    public static final FieldParser<ContentTypeField> PARSER = new FieldParser<ContentTypeField>() {
+        public ContentTypeField parse(final String name, final String body,
                 final ByteSequence raw, DecodeMonitor monitor) {
             return new ContentTypeFieldImpl(name, body, raw, monitor);
         }

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/DateTimeFieldImpl.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/DateTimeFieldImpl.java?rev=1124803&r1=1124802&r2=1124803&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/DateTimeFieldImpl.java (original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/DateTimeFieldImpl.java Thu May 19 14:05:09 2011
@@ -23,9 +23,11 @@ import java.io.StringReader;
 import java.util.Date;
 
 import org.apache.james.mime4j.codec.DecodeMonitor;
+import org.apache.james.mime4j.dom.field.DateTimeField;
 import org.apache.james.mime4j.field.datetime.parser.DateTimeParser;
 import org.apache.james.mime4j.field.datetime.parser.ParseException;
 import org.apache.james.mime4j.field.datetime.parser.TokenMgrError;
+import org.apache.james.mime4j.stream.FieldParser;
 import org.apache.james.mime4j.util.ByteSequence;
 
 /**
@@ -77,8 +79,8 @@ public class DateTimeFieldImpl extends A
         parsed = true;
     }
 
-    static final FieldParser<DateTimeFieldImpl> PARSER = new FieldParser<DateTimeFieldImpl>() {
-        public DateTimeFieldImpl parse(final String name, final String body,
+    public static final FieldParser<DateTimeField> PARSER = new FieldParser<DateTimeField>() {
+        public DateTimeField parse(final String name, final String body,
                 final ByteSequence raw, DecodeMonitor monitor) {
             return new DateTimeFieldImpl(name, body, raw, monitor);
         }

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/DefaultFieldParser.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/DefaultFieldParser.java?rev=1124803&r1=1124802&r2=1124803&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/DefaultFieldParser.java (original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/DefaultFieldParser.java Thu May 19 14:05:09 2011
@@ -21,9 +21,14 @@ package org.apache.james.mime4j.field;
 
 import org.apache.james.mime4j.MimeException;
 import org.apache.james.mime4j.codec.DecodeMonitor;
+import org.apache.james.mime4j.dom.field.AddressListField;
+import org.apache.james.mime4j.dom.field.DateTimeField;
 import org.apache.james.mime4j.dom.field.FieldName;
+import org.apache.james.mime4j.dom.field.MailboxField;
+import org.apache.james.mime4j.dom.field.MailboxListField;
 import org.apache.james.mime4j.dom.field.ParsedField;
 import org.apache.james.mime4j.stream.Field;
+import org.apache.james.mime4j.stream.FieldParser;
 import org.apache.james.mime4j.stream.RawField;
 import org.apache.james.mime4j.stream.RawFieldParser;
 import org.apache.james.mime4j.util.ByteSequence;
@@ -121,19 +126,19 @@ public class DefaultFieldParser extends 
         setFieldParser(FieldName.CONTENT_DISPOSITION,
                 ContentDispositionFieldImpl.PARSER);
 
-        final FieldParser<DateTimeFieldImpl> dateTimeParser = DateTimeFieldImpl.PARSER;
+        final FieldParser<DateTimeField> dateTimeParser = DateTimeFieldImpl.PARSER;
         setFieldParser(FieldName.DATE, dateTimeParser);
         setFieldParser(FieldName.RESENT_DATE, dateTimeParser);
 
-        final FieldParser<MailboxListFieldImpl> mailboxListParser = MailboxListFieldImpl.PARSER;
+        final FieldParser<MailboxListField> mailboxListParser = MailboxListFieldImpl.PARSER;
         setFieldParser(FieldName.FROM, mailboxListParser);
         setFieldParser(FieldName.RESENT_FROM, mailboxListParser);
 
-        final FieldParser<MailboxFieldImpl> mailboxParser = MailboxFieldImpl.PARSER;
+        final FieldParser<MailboxField> mailboxParser = MailboxFieldImpl.PARSER;
         setFieldParser(FieldName.SENDER, mailboxParser);
         setFieldParser(FieldName.RESENT_SENDER, mailboxParser);
 
-        final FieldParser<AddressListFieldImpl> addressListParser = AddressListFieldImpl.PARSER;
+        final FieldParser<AddressListField> addressListParser = AddressListFieldImpl.PARSER;
         setFieldParser(FieldName.TO, addressListParser);
         setFieldParser(FieldName.RESENT_TO, addressListParser);
         setFieldParser(FieldName.CC, addressListParser);

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/DelegatingFieldParser.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/DelegatingFieldParser.java?rev=1124803&r1=1124802&r2=1124803&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/DelegatingFieldParser.java (original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/DelegatingFieldParser.java Thu May 19 14:05:09 2011
@@ -24,10 +24,12 @@ import java.util.Map;
 
 import org.apache.james.mime4j.codec.DecodeMonitor;
 import org.apache.james.mime4j.dom.field.ParsedField;
+import org.apache.james.mime4j.dom.field.UnstructuredField;
+import org.apache.james.mime4j.stream.FieldParser;
 import org.apache.james.mime4j.util.ByteSequence;
 
 public class DelegatingFieldParser implements FieldParser<ParsedField> {
-    private static final FieldParser<UnstructuredFieldImpl> DEFAULT_PARSER = UnstructuredFieldImpl.PARSER;
+    private static final FieldParser<UnstructuredField> DEFAULT_PARSER = UnstructuredFieldImpl.PARSER;
 
     private Map<String, FieldParser<? extends ParsedField>> parsers = new HashMap<String, FieldParser<? extends ParsedField>>();
 

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/Fields.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/Fields.java?rev=1124803&r1=1124802&r2=1124803&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/Fields.java (original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/Fields.java Thu May 19 14:05:09 2011
@@ -43,6 +43,7 @@ import org.apache.james.mime4j.dom.field
 import org.apache.james.mime4j.dom.field.UnstructuredField;
 import org.apache.james.mime4j.field.address.AddressFormatter;
 import org.apache.james.mime4j.stream.Field;
+import org.apache.james.mime4j.stream.FieldParser;
 import org.apache.james.mime4j.stream.RawField;
 import org.apache.james.mime4j.util.MimeUtil;
 

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/MailboxFieldImpl.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/MailboxFieldImpl.java?rev=1124803&r1=1124802&r2=1124803&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/MailboxFieldImpl.java (original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/MailboxFieldImpl.java Thu May 19 14:05:09 2011
@@ -22,8 +22,10 @@ package org.apache.james.mime4j.field;
 import org.apache.james.mime4j.codec.DecodeMonitor;
 import org.apache.james.mime4j.dom.address.Mailbox;
 import org.apache.james.mime4j.dom.address.MailboxList;
+import org.apache.james.mime4j.dom.field.MailboxField;
 import org.apache.james.mime4j.field.address.AddressBuilder;
 import org.apache.james.mime4j.field.address.ParseException;
+import org.apache.james.mime4j.stream.FieldParser;
 import org.apache.james.mime4j.util.ByteSequence;
 
 /**
@@ -75,8 +77,8 @@ public class MailboxFieldImpl extends Ab
         parsed = true;
     }
 
-    static final FieldParser<MailboxFieldImpl> PARSER = new FieldParser<MailboxFieldImpl>() {
-        public MailboxFieldImpl parse(final String name, final String body,
+    public static final FieldParser<MailboxField> PARSER = new FieldParser<MailboxField>() {
+        public MailboxField parse(final String name, final String body,
                 final ByteSequence raw, DecodeMonitor monitor) {
             return new MailboxFieldImpl(name, body, raw, monitor);
         }

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/MailboxListFieldImpl.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/MailboxListFieldImpl.java?rev=1124803&r1=1124802&r2=1124803&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/MailboxListFieldImpl.java (original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/MailboxListFieldImpl.java Thu May 19 14:05:09 2011
@@ -21,8 +21,10 @@ package org.apache.james.mime4j.field;
 
 import org.apache.james.mime4j.codec.DecodeMonitor;
 import org.apache.james.mime4j.dom.address.MailboxList;
+import org.apache.james.mime4j.dom.field.MailboxListField;
 import org.apache.james.mime4j.field.address.AddressBuilder;
 import org.apache.james.mime4j.field.address.ParseException;
+import org.apache.james.mime4j.stream.FieldParser;
 import org.apache.james.mime4j.util.ByteSequence;
 
 /**
@@ -71,8 +73,8 @@ public class MailboxListFieldImpl extend
         parsed = true;
     }
 
-    static final FieldParser<MailboxListFieldImpl> PARSER = new FieldParser<MailboxListFieldImpl>() {
-        public MailboxListFieldImpl parse(final String name, final String body,
+    public static final FieldParser<MailboxListField> PARSER = new FieldParser<MailboxListField>() {
+        public MailboxListField parse(final String name, final String body,
                 final ByteSequence raw, DecodeMonitor monitor) {
             return new MailboxListFieldImpl(name, body, raw, monitor);
         }

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/UnstructuredFieldImpl.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/UnstructuredFieldImpl.java?rev=1124803&r1=1124802&r2=1124803&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/UnstructuredFieldImpl.java (original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/UnstructuredFieldImpl.java Thu May 19 14:05:09 2011
@@ -21,6 +21,8 @@ package org.apache.james.mime4j.field;
 
 import org.apache.james.mime4j.codec.DecodeMonitor;
 import org.apache.james.mime4j.codec.DecoderUtil;
+import org.apache.james.mime4j.dom.field.UnstructuredField;
+import org.apache.james.mime4j.stream.FieldParser;
 import org.apache.james.mime4j.util.ByteSequence;
 
 /**
@@ -53,8 +55,8 @@ public class UnstructuredFieldImpl exten
         parsed = true;
     }
 
-    static final FieldParser<UnstructuredFieldImpl> PARSER = new FieldParser<UnstructuredFieldImpl>() {
-        public UnstructuredFieldImpl parse(final String name, final String body,
+    public static final FieldParser<UnstructuredField> PARSER = new FieldParser<UnstructuredField>() {
+        public UnstructuredField parse(final String name, final String body,
                 final ByteSequence raw, DecodeMonitor monitor) {
             return new UnstructuredFieldImpl(name, body, raw, monitor);
         }

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/EntityBuilder.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/EntityBuilder.java?rev=1124803&r1=1124802&r2=1124803&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/EntityBuilder.java (original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/EntityBuilder.java Thu May 19 14:05:09 2011
@@ -30,10 +30,12 @@ import org.apache.james.mime4j.dom.Entit
 import org.apache.james.mime4j.dom.Header;
 import org.apache.james.mime4j.dom.Message;
 import org.apache.james.mime4j.dom.Multipart;
+import org.apache.james.mime4j.dom.field.ParsedField;
 import org.apache.james.mime4j.field.DefaultFieldParser;
 import org.apache.james.mime4j.parser.ContentHandler;
 import org.apache.james.mime4j.stream.BodyDescriptor;
 import org.apache.james.mime4j.stream.Field;
+import org.apache.james.mime4j.stream.FieldParser;
 import org.apache.james.mime4j.stream.RawField;
 import org.apache.james.mime4j.util.ByteArrayBuffer;
 import org.apache.james.mime4j.util.ByteSequence;
@@ -45,22 +47,25 @@ import org.apache.james.mime4j.util.Byte
 class EntityBuilder implements ContentHandler {
 
     private final Entity entity;
-    private final BodyFactory bodyFactory;
     private final Stack<Object> stack;
+    private final FieldParser<? extends ParsedField> fieldParser; 
+    private final BodyFactory bodyFactory;
     private final DecodeMonitor monitor;
     
     public EntityBuilder(Entity entity) {
-        this(entity, null, null);
+        this(entity, null, null, null);
     }
     
     public EntityBuilder(
             final Entity entity, 
+            final FieldParser<? extends ParsedField> fieldParser, 
             final BodyFactory bodyFactory, 
             final DecodeMonitor monitor) {
         this.entity = entity;
         this.stack = new Stack<Object>();
-        this.monitor = monitor != null ? monitor : DecodeMonitor.SILENT;
+        this.fieldParser = fieldParser != null ? fieldParser : DefaultFieldParser.getParser();
         this.bodyFactory = bodyFactory != null ? bodyFactory : new BasicBodyFactory();
+        this.monitor = monitor != null ? monitor : DecodeMonitor.SILENT;
     }
     
     private void expect(Class<?> c) {
@@ -105,7 +110,12 @@ class EntityBuilder implements ContentHa
      */
     public void field(Field field) throws MimeException {
         expect(Header.class);
-        Field parsedField = DefaultFieldParser.parse(field, monitor); 
+        ParsedField parsedField;
+        if (field instanceof ParsedField) {
+            parsedField = (ParsedField) field;
+        } else {
+            parsedField = fieldParser.parse(field.getName(), field.getBody(), field.getRaw(), monitor);
+        }
         ((Header) stack.peek()).addField(parsedField);
     }
     

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MaximalBodyDescriptor.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MaximalBodyDescriptor.java?rev=1124803&r1=1124802&r2=1124803&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MaximalBodyDescriptor.java (original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MaximalBodyDescriptor.java Thu May 19 14:05:09 2011
@@ -35,7 +35,6 @@ import org.apache.james.mime4j.field.lan
 import org.apache.james.mime4j.field.mimeversion.parser.MimeVersionParser;
 import org.apache.james.mime4j.field.structured.parser.StructuredFieldParser;
 import org.apache.james.mime4j.stream.BodyDescriptor;
-import org.apache.james.mime4j.stream.DefaultBodyDescriptor;
 import org.apache.james.mime4j.stream.RawBody;
 import org.apache.james.mime4j.stream.MutableBodyDescriptor;
 import org.apache.james.mime4j.stream.NameValuePair;
@@ -48,7 +47,7 @@ import org.apache.james.mime4j.util.Mime
  * Parses and stores values for standard MIME header values.
  * 
  */
-public class MaximalBodyDescriptor extends DefaultBodyDescriptor {
+public class MaximalBodyDescriptor extends MinimalBodyDescriptor {
 
     private static final int DEFAULT_MINOR_VERSION = 0;
     private static final int DEFAULT_MAJOR_VERSION = 1;

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MessageBuilderImpl.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MessageBuilderImpl.java?rev=1124803&r1=1124802&r2=1124803&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MessageBuilderImpl.java (original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MessageBuilderImpl.java Thu May 19 14:05:09 2011
@@ -26,6 +26,8 @@ import org.apache.james.mime4j.MimeExcep
 import org.apache.james.mime4j.codec.DecodeMonitor;
 import org.apache.james.mime4j.dom.Message;
 import org.apache.james.mime4j.dom.MessageBuilder;
+import org.apache.james.mime4j.dom.field.ParsedField;
+import org.apache.james.mime4j.stream.FieldParser;
 import org.apache.james.mime4j.stream.MimeEntityConfig;
 import org.apache.james.mime4j.stream.MutableBodyDescriptorFactory;
 
@@ -36,6 +38,7 @@ import org.apache.james.mime4j.stream.Mu
 public class MessageBuilderImpl implements MessageBuilder {
 
     private MimeBuilder mimeBuilder = null;
+    private FieldParser<? extends ParsedField> fieldParser = null;
     private BodyFactory bodyFactory = null;
     private MimeEntityConfig mimeEntityConfig = null;
     private MutableBodyDescriptorFactory mutableBodyDescriptorFactory = null;
@@ -67,12 +70,17 @@ public class MessageBuilderImpl implemen
         return getMimeBuilder().parse(source, 
                 mimeEntityConfig,
                 decodeMonitor,
+                fieldParser,
                 bodyFactory, 
                 mutableBodyDescriptorFactory, 
                 contentDecoding,
                 flatMode);
     }
     
+    public void setFieldParser(FieldParser<? extends ParsedField> fieldParser) {
+        this.fieldParser = fieldParser;
+    }
+
     public void setBodyFactory(BodyFactory bodyFactory) {
         this.bodyFactory = bodyFactory;
     }

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MimeBuilder.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MimeBuilder.java?rev=1124803&r1=1124802&r2=1124803&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MimeBuilder.java (original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MimeBuilder.java Thu May 19 14:05:09 2011
@@ -32,10 +32,12 @@ import org.apache.james.mime4j.dom.Heade
 import org.apache.james.mime4j.dom.Message;
 import org.apache.james.mime4j.dom.Multipart;
 import org.apache.james.mime4j.dom.SingleBody;
+import org.apache.james.mime4j.dom.field.ParsedField;
 import org.apache.james.mime4j.field.DefaultFieldParser;
 import org.apache.james.mime4j.parser.AbstractContentHandler;
 import org.apache.james.mime4j.parser.MimeStreamParser;
 import org.apache.james.mime4j.stream.Field;
+import org.apache.james.mime4j.stream.FieldParser;
 import org.apache.james.mime4j.stream.MimeEntityConfig;
 import org.apache.james.mime4j.stream.MutableBodyDescriptorFactory;
 
@@ -202,6 +204,7 @@ public class MimeBuilder {
      */
     public Header parse(
             final InputStream is,
+            final FieldParser<? extends ParsedField> fieldParser,
             final DecodeMonitor monitor) throws IOException, MimeIOException {
         final HeaderImpl header = new HeaderImpl();
         final MimeStreamParser parser = new MimeStreamParser();
@@ -212,7 +215,13 @@ public class MimeBuilder {
             }
             @Override
             public void field(Field field) throws MimeException {
-                Field parsedField = DefaultFieldParser.parse(field, monitor); 
+                ParsedField parsedField;
+                if (field instanceof ParsedField) {
+                    parsedField = (ParsedField) field;
+                } else {
+                    parsedField = fieldParser.parse(
+                            field.getName(), field.getBody(), field.getRaw(), monitor);
+                }
                 header.addField(parsedField);
             }
         });
@@ -246,6 +255,7 @@ public class MimeBuilder {
             final InputStream is, 
             final MimeEntityConfig config,
             final DecodeMonitor monitor,
+            final FieldParser<? extends ParsedField> fieldParser,
             final BodyFactory bodyFactory, 
             final MutableBodyDescriptorFactory bodyDescFactory,
             final boolean contentDecoding,
@@ -253,8 +263,12 @@ public class MimeBuilder {
         try {
             MessageImpl message = new MessageImpl();
             DecodeMonitor mon = monitor != null ? monitor : DecodeMonitor.SILENT;
-            MimeStreamParser parser = new MimeStreamParser(config, mon, bodyDescFactory);
-            parser.setContentHandler(new EntityBuilder(message, bodyFactory, mon));
+            FieldParser<? extends ParsedField> fp = fieldParser != null ? fieldParser : 
+                DefaultFieldParser.getParser();
+            MutableBodyDescriptorFactory bdf = bodyDescFactory != null ? bodyDescFactory :
+                new MinimalBodyDescriptorFactory();
+            MimeStreamParser parser = new MimeStreamParser(config, mon, fp, bdf);
+            parser.setContentHandler(new EntityBuilder(message, fp, bodyFactory, mon));
             parser.setContentDecoding(contentDecoding);
             if (flatMode) {
                 parser.setFlat();
@@ -290,24 +304,27 @@ public class MimeBuilder {
             final InputStream is, 
             final MimeEntityConfig config,
             final DecodeMonitor monitor,
+            final FieldParser<? extends ParsedField> fieldParser,
             final BodyFactory bodyFactory, 
             final MutableBodyDescriptorFactory bodyDescFactory) throws IOException, MimeIOException {
-        return parse(is, config, monitor, bodyFactory, bodyDescFactory, true, false);
+        return parse(is, config, monitor, fieldParser, bodyFactory, bodyDescFactory, true, false);
     }
     
     public Message parse(
             final InputStream is, 
             final MimeEntityConfig config,
+            final FieldParser<? extends ParsedField> fieldParser,
             final BodyFactory bodyFactory, 
             final MutableBodyDescriptorFactory bodyDescFactory) throws IOException, MimeIOException {
-        return parse(is, config, null, bodyFactory, bodyDescFactory);
+        return parse(is, config, null, fieldParser, bodyFactory, bodyDescFactory);
     }
 
     public Message parse(
             final InputStream is, 
             final MimeEntityConfig config,
+            final FieldParser<? extends ParsedField> fieldParser,
             final BodyFactory bodyFactory) throws IOException, MimeIOException {
-        return parse(is, config, null, bodyFactory, null);
+        return parse(is, config, null, fieldParser, bodyFactory, null);
     }
 
     /**
@@ -322,7 +339,7 @@ public class MimeBuilder {
      *             on MIME protocol violations.
      */
     public Message parse(InputStream is) throws IOException, MimeIOException {
-        return parse(is, null, null);
+        return parse(is, null, null, null);
     }
 
     /**
@@ -338,7 +355,7 @@ public class MimeBuilder {
      */
     public Message parse(InputStream is, MimeEntityConfig config) throws IOException,
             MimeIOException {
-        return parse(is, config, null);
+        return parse(is, config, null, null);
     }
     
 }

Added: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MinimalBodyDescriptor.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MinimalBodyDescriptor.java?rev=1124803&view=auto
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MinimalBodyDescriptor.java (added)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MinimalBodyDescriptor.java Thu May 19 14:05:09 2011
@@ -0,0 +1,247 @@
+/****************************************************************
+ * 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.message;
+
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+
+import org.apache.james.mime4j.MimeException;
+import org.apache.james.mime4j.codec.DecodeMonitor;
+import org.apache.james.mime4j.dom.field.ContentTransferEncodingField;
+import org.apache.james.mime4j.dom.field.ContentTypeField;
+import org.apache.james.mime4j.field.ContentTransferEncodingFieldImpl;
+import org.apache.james.mime4j.field.ContentTypeFieldImpl;
+import org.apache.james.mime4j.stream.BodyDescriptor;
+import org.apache.james.mime4j.stream.Field;
+import org.apache.james.mime4j.stream.MutableBodyDescriptor;
+import org.apache.james.mime4j.util.MimeUtil;
+
+/**
+ * Encapsulates the values of the MIME-specific header fields 
+ * (which starts with <code>Content-</code>). 
+ */
+public class MinimalBodyDescriptor implements MutableBodyDescriptor {
+    
+    private static final String US_ASCII = "us-ascii";
+
+    private static final String SUB_TYPE_EMAIL = "rfc822";
+
+    private static final String MEDIA_TYPE_TEXT = "text";
+
+    private static final String MEDIA_TYPE_MESSAGE = "message";
+
+    private static final String EMAIL_MESSAGE_MIME_TYPE = MEDIA_TYPE_MESSAGE + "/" + SUB_TYPE_EMAIL;
+
+    private static final String DEFAULT_SUB_TYPE = "plain";
+
+    private static final String DEFAULT_MEDIA_TYPE = MEDIA_TYPE_TEXT;
+
+    private static final String DEFAULT_MIME_TYPE = DEFAULT_MEDIA_TYPE + "/" + DEFAULT_SUB_TYPE;
+
+    private final DecodeMonitor monitor;
+    
+    private String mediaType = DEFAULT_MEDIA_TYPE;
+    private String subType = DEFAULT_SUB_TYPE;
+    private String mimeType = DEFAULT_MIME_TYPE;
+    private String boundary = null;
+    private String charset = US_ASCII;
+    private String transferEncoding = "7bit";
+    private Map<String, String> parameters = new HashMap<String, String>();
+    private boolean contentTypeSet;
+    private boolean contentTransferEncSet;
+    private long contentLength = -1;
+    
+    /**
+     * Creates a new root <code>BodyDescriptor</code> instance.
+     */
+    public MinimalBodyDescriptor() {
+        this(null, null);
+    }
+
+    /**
+     * Creates a new <code>BodyDescriptor</code> instance.
+     * 
+     * @param parent the descriptor of the parent or <code>null</code> if this
+     *        is the root descriptor.
+     */
+    public MinimalBodyDescriptor(final BodyDescriptor parent, final DecodeMonitor monitor) {
+        if (parent != null && MimeUtil.isSameMimeType("multipart/digest", parent.getMimeType())) {
+            this.mimeType = EMAIL_MESSAGE_MIME_TYPE;
+            this.subType = SUB_TYPE_EMAIL;
+            this.mediaType = MEDIA_TYPE_MESSAGE;
+        } else {
+            this.mimeType = DEFAULT_MIME_TYPE;
+            this.subType = DEFAULT_SUB_TYPE;
+            this.mediaType = DEFAULT_MEDIA_TYPE;
+        }
+        this.monitor = monitor != null ? monitor : DecodeMonitor.SILENT;
+    }
+    
+    protected DecodeMonitor getDecodeMonitor() {
+        return monitor;
+    }
+    
+    public MutableBodyDescriptor newChild() {
+		return new MinimalBodyDescriptor(this, getDecodeMonitor());
+    }
+    
+    /**
+     * Should be called for each <code>Content-</code> header field of 
+     * a MIME message or part.
+     * 
+     * @param field the MIME field.
+     */
+    public void addField(Field field) throws MimeException {
+        String name = field.getName().toLowerCase(Locale.US);
+        
+        if (name.equals("content-transfer-encoding") && !contentTransferEncSet) {
+            parseContentTransferEncoding(field);
+        } else if (name.equals("content-length") && contentLength == -1) {
+            parseContentLength(field);
+        } else if (name.equals("content-type") && !contentTypeSet) {
+            parseContentType(field);
+        }
+    }
+
+    private void parseContentTransferEncoding(Field field) throws MimeException {
+        contentTransferEncSet = true;
+        ContentTransferEncodingField f;
+        if (field instanceof ContentTransferEncodingField) {
+            f = (ContentTransferEncodingField) field;
+        } else {
+            f = ContentTransferEncodingFieldImpl.PARSER.parse(
+                    field.getName(), field.getBody(), field.getRaw(), monitor);
+        }
+        transferEncoding = f.getEncoding();
+    }
+
+    private void parseContentLength(Field field) throws MimeException {
+        String value = field.getBody();
+        if (value != null) {
+            try {
+                long v = Long.parseLong(value);
+                if (v < 0) {
+                    if (monitor.warn("Negative content length: " + value, 
+                            "ignoring Content-Length header")) {
+                        throw new MimeException("Negative Content-Length header: " + value);
+                    }
+                } else {
+                    contentLength = v;
+                }
+            } catch (NumberFormatException e) {
+                if (monitor.warn("Invalid content length: " + value, 
+                        "ignoring Content-Length header")) {
+                    throw new MimeException("Invalid Content-Length header: " + value);
+                }
+            }
+        }
+    }
+
+    private void parseContentType(Field field) throws MimeException {
+        contentTypeSet = true;
+        ContentTypeField f;
+        if (field instanceof ContentTypeField) {
+            f = (ContentTypeField) field;
+        } else {
+            f = ContentTypeFieldImpl.PARSER.parse(
+                    field.getName(), field.getBody(), field.getRaw(), monitor);
+        }
+        String mimetype = f.getMimeType();
+        if (mimetype != null) {
+            mimeType = mimetype;
+            mediaType = f.getMediaType();
+            subType = f.getSubType();
+        }
+        if (MimeUtil.isMultipart(mimeType)) {
+            boundary = f.getBoundary();
+        }
+        charset = f.getCharset();
+        if (charset == null && MEDIA_TYPE_TEXT.equalsIgnoreCase(mediaType)) {
+            charset = US_ASCII;
+        }
+        parameters.putAll(f.getParameters());
+        parameters.remove("charset");
+        parameters.remove("boundary");
+    }
+
+    /**
+     * Return the MimeType 
+     * 
+     * @return mimeType
+     */
+    public String getMimeType() {
+        return mimeType;
+    }
+    
+    /**
+     * Return the boundary
+     * 
+     * @return boundary
+     */
+    public String getBoundary() {
+        return boundary;
+    }
+    
+    /**
+     * Return the charset
+     * 
+     * @return charset
+     */
+    public String getCharset() {
+        return charset;
+    }
+    
+    /**
+     * Return all parameters for the BodyDescriptor
+     * 
+     * @return parameters
+     */
+    public Map<String, String> getContentTypeParameters() {
+        return parameters;
+    }
+    
+    /**
+     * Return the TransferEncoding
+     * 
+     * @return transferEncoding
+     */
+    public String getTransferEncoding() {
+        return transferEncoding;
+    }
+    
+    @Override
+    public String toString() {
+        return mimeType;
+    }
+
+    public long getContentLength() {
+        return contentLength;
+    }
+
+    public String getMediaType() {
+        return mediaType;
+    }
+
+    public String getSubType() {
+        return subType;
+    }
+
+}

Propchange: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MinimalBodyDescriptor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MinimalBodyDescriptor.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MinimalBodyDescriptor.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MinimalBodyDescriptorFactory.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MinimalBodyDescriptorFactory.java?rev=1124803&view=auto
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MinimalBodyDescriptorFactory.java (added)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MinimalBodyDescriptorFactory.java Thu May 19 14:05:09 2011
@@ -0,0 +1,32 @@
+/****************************************************************
+ * 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.message;
+
+import org.apache.james.mime4j.codec.DecodeMonitor;
+import org.apache.james.mime4j.stream.MutableBodyDescriptor;
+import org.apache.james.mime4j.stream.MutableBodyDescriptorFactory;
+
+public class MinimalBodyDescriptorFactory implements MutableBodyDescriptorFactory {
+
+    public MutableBodyDescriptor newInstance(DecodeMonitor monitor) {
+        return new MinimalBodyDescriptor(null, monitor);
+    }
+    
+} 

Propchange: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MinimalBodyDescriptorFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MinimalBodyDescriptorFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MinimalBodyDescriptorFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/SimpleContentHandler.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/SimpleContentHandler.java?rev=1124803&r1=1124802&r2=1124803&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/SimpleContentHandler.java (original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/SimpleContentHandler.java Thu May 19 14:05:09 2011
@@ -22,9 +22,11 @@ package org.apache.james.mime4j.message;
 import org.apache.james.mime4j.MimeException;
 import org.apache.james.mime4j.codec.DecodeMonitor;
 import org.apache.james.mime4j.dom.Header;
+import org.apache.james.mime4j.dom.field.ParsedField;
 import org.apache.james.mime4j.field.DefaultFieldParser;
 import org.apache.james.mime4j.parser.AbstractContentHandler;
 import org.apache.james.mime4j.stream.Field;
+import org.apache.james.mime4j.stream.FieldParser;
 import org.apache.james.mime4j.stream.RawField;
 
 /**
@@ -36,15 +38,19 @@ import org.apache.james.mime4j.stream.Ra
  */
 public abstract class SimpleContentHandler extends AbstractContentHandler {
 
+    private final FieldParser<? extends ParsedField> fieldParser; 
     private final DecodeMonitor monitor;
     
-    public SimpleContentHandler(final DecodeMonitor monitor) {
+    public SimpleContentHandler(
+            final FieldParser<? extends ParsedField> fieldParser, 
+            final DecodeMonitor monitor) {
         super();
-        this.monitor = monitor;
+        this.fieldParser = fieldParser != null ? fieldParser : DefaultFieldParser.getParser();
+        this.monitor = monitor != null ? monitor : DecodeMonitor.SILENT;
     }
     
     public SimpleContentHandler() {
-        this(null);
+        this(null, null);
     }
     
     /**
@@ -69,7 +75,13 @@ public abstract class SimpleContentHandl
      */
     @Override
     public final void field(Field field) throws MimeException {
-        Field parsedField = DefaultFieldParser.parse(field, monitor); 
+        ParsedField parsedField;
+        if (field instanceof ParsedField) {
+            parsedField = (ParsedField) field;
+        } else {
+            parsedField = fieldParser.parse(
+                    field.getName(), field.getBody(), field.getRaw(), monitor);
+        }
         currHeader.addField(parsedField);
     }
 

Modified: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/ContentTypeFieldTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/ContentTypeFieldTest.java?rev=1124803&r1=1124802&r2=1124803&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/ContentTypeFieldTest.java (original)
+++ james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/ContentTypeFieldTest.java Thu May 19 14:05:09 2011
@@ -48,7 +48,7 @@ public class ContentTypeFieldTest extend
         assertEquals("x-app/yada", f.getMimeType());
         
         f = (ContentTypeField) DefaultFieldParser.parse("CONTENT-TYPE:   yada");
-        assertEquals("", f.getMimeType());
+        assertEquals(null, f.getMimeType());
     }
     
     public void testGetMimeTypeStatic() throws Exception {

Modified: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/message/MaximalBodyDescriptorTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/message/MaximalBodyDescriptorTest.java?rev=1124803&r1=1124802&r2=1124803&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/message/MaximalBodyDescriptorTest.java (original)
+++ james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/message/MaximalBodyDescriptorTest.java Thu May 19 14:05:09 2011
@@ -23,6 +23,7 @@ import java.io.ByteArrayInputStream;
 
 import org.apache.james.mime4j.ExampleMail;
 import org.apache.james.mime4j.dom.datetime.DateTime;
+import org.apache.james.mime4j.field.DefaultFieldParser;
 import org.apache.james.mime4j.message.MaximalBodyDescriptor;
 import org.apache.james.mime4j.message.MaximalBodyDescriptorFactory;
 import org.apache.james.mime4j.stream.BaseTestForBodyDescriptors;
@@ -41,7 +42,8 @@ public class MaximalBodyDescriptorTest e
         super.setUp();
         MimeEntityConfig config = new MimeEntityConfig();
         config.setStrictParsing(true);
-        parser = new MimeTokenStream(config, new MaximalBodyDescriptorFactory());
+        parser = new MimeTokenStream(config, 
+                DefaultFieldParser.getParser(), new MaximalBodyDescriptorFactory());
     }
 
     @Override



Mime
View raw message