james-mime4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1127570 - in /james/mime4j/trunk/dom/src: main/java/org/apache/james/mime4j/field/ test/java/org/apache/james/mime4j/field/
Date Wed, 25 May 2011 15:47:58 GMT
Author: olegk
Date: Wed May 25 15:47:57 2011
New Revision: 1127570

URL: http://svn.apache.org/viewvc?rev=1127570&view=rev
Log:
MIME4J-197: Added 'lenient' ContentTypeField implementation; added LenientFieldParser as an alternative to DefaultFieldParser

Added:
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentTypeFieldLenientImpl.java   (with props)
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/LenientFieldParser.java   (with props)
    james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/LenientContentTypeFieldTest.java   (with props)
Modified:
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/AbstractField.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/ContentDescriptionFieldImpl.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/ContentIdFieldImpl.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentLanguageFieldImpl.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentLengthFieldImpl.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentLocationFieldImpl.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentMD5FieldImpl.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/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/MimeVersionFieldImpl.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/UnstructuredFieldImpl.java
    james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/ContentTypeFieldTest.java

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/AbstractField.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/AbstractField.java?rev=1127570&r1=1127569&r2=1127570&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/AbstractField.java (original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/AbstractField.java Wed May 25 15:47:57 2011
@@ -22,6 +22,8 @@ package org.apache.james.mime4j.field;
 import org.apache.james.mime4j.codec.DecodeMonitor;
 import org.apache.james.mime4j.dom.field.ParseException;
 import org.apache.james.mime4j.dom.field.ParsedField;
+import org.apache.james.mime4j.stream.Field;
+import org.apache.james.mime4j.stream.RawField;
 import org.apache.james.mime4j.util.ByteSequence;
 
 /**
@@ -29,19 +31,11 @@ import org.apache.james.mime4j.util.Byte
  */
 public abstract class AbstractField implements ParsedField {
 
-    private final String name;
-    private final String body;
-    private final ByteSequence raw;
-    protected DecodeMonitor monitor;
+    protected final Field rawField;
+    protected final DecodeMonitor monitor;
     
-    protected AbstractField(
-            final String name, 
-            final String body, 
-            final ByteSequence raw, 
-            final DecodeMonitor monitor) {
-        this.name = name;
-        this.body = body;
-        this.raw = raw;
+    protected AbstractField(final Field rawField, final DecodeMonitor monitor) {
+        this.rawField = rawField;
         this.monitor = monitor != null ? monitor : DecodeMonitor.SILENT;
     }
     
@@ -52,7 +46,7 @@ public abstract class AbstractField impl
      * @return the field name.
      */
     public String getName() {
-        return name;
+        return rawField.getName();
     }
     
     /**
@@ -62,7 +56,7 @@ public abstract class AbstractField impl
      * @return the unfolded unparsed field body string.
      */
     public String getBody() {
-        return body;
+        return rawField.getBody();
     }
 
     /**
@@ -70,7 +64,7 @@ public abstract class AbstractField impl
      * <code>null</code> otherwise.
      */
     public ByteSequence getRaw() {
-        return raw;
+        return rawField.getRaw();
     }
 
     /**
@@ -86,10 +80,18 @@ public abstract class AbstractField impl
     public ParseException getParseException() {
         return null;
     }
-
+    
+    protected RawField getRawField() {
+        if (rawField instanceof RawField) {
+            return ((RawField) rawField);
+        } else {
+            return new RawField(rawField.getName(), rawField.getBody());
+        }
+    }
+    
     @Override
     public String toString() {
-        return name + ": " + body;
+        return rawField.toString();
     }
 
 }

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=1127570&r1=1127569&r2=1127570&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 Wed May 25 15:47:57 2011
@@ -26,7 +26,6 @@ import org.apache.james.mime4j.field.add
 import org.apache.james.mime4j.field.address.ParseException;
 import org.apache.james.mime4j.stream.Field;
 import org.apache.james.mime4j.stream.FieldParser;
-import org.apache.james.mime4j.util.ByteSequence;
 
 /**
  * Address list field such as <code>To</code> or <code>Reply-To</code>.
@@ -38,8 +37,8 @@ public class AddressListFieldImpl extend
     private AddressList addressList;
     private ParseException parseException;
 
-    AddressListFieldImpl(String name, String body, ByteSequence raw, DecodeMonitor monitor) {
-        super(name, body, raw, monitor);
+    AddressListFieldImpl(Field rawField, DecodeMonitor monitor) {
+        super(rawField, monitor);
     }
 
     /**
@@ -78,7 +77,7 @@ public class AddressListFieldImpl extend
     public static final FieldParser<AddressListField> PARSER = new FieldParser<AddressListField>() {
         
         public AddressListField parse(final Field rawField, final DecodeMonitor monitor) {
-            return new AddressListFieldImpl(rawField.getName(), rawField.getBody(), rawField.getRaw(), monitor);
+            return new AddressListFieldImpl(rawField, monitor);
         }
         
     };

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentDescriptionFieldImpl.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentDescriptionFieldImpl.java?rev=1127570&r1=1127569&r2=1127570&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentDescriptionFieldImpl.java (original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentDescriptionFieldImpl.java Wed May 25 15:47:57 2011
@@ -23,7 +23,6 @@ import org.apache.james.mime4j.codec.Dec
 import org.apache.james.mime4j.dom.field.ContentDescriptionField;
 import org.apache.james.mime4j.stream.Field;
 import org.apache.james.mime4j.stream.FieldParser;
-import org.apache.james.mime4j.util.ByteSequence;
 
 /**
  * Represents a <code>Content-Description</code> field.
@@ -33,8 +32,8 @@ public class ContentDescriptionFieldImpl
     private boolean parsed = false;
     private String description;
 
-    ContentDescriptionFieldImpl(String name, String body, ByteSequence raw, DecodeMonitor monitor) {
-        super(name, body, raw, monitor);
+    ContentDescriptionFieldImpl(Field rawField, DecodeMonitor monitor) {
+        super(rawField, monitor);
     }
 
     private void parse() {
@@ -57,7 +56,7 @@ public class ContentDescriptionFieldImpl
     public static final FieldParser<ContentDescriptionField> PARSER = new FieldParser<ContentDescriptionField>() {
         
         public ContentDescriptionField parse(final Field rawField, final DecodeMonitor monitor) {
-            return new ContentDescriptionFieldImpl(rawField.getName(), rawField.getBody(), rawField.getRaw(), monitor);
+            return new ContentDescriptionFieldImpl(rawField, 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=1127570&r1=1127569&r2=1127570&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 Wed May 25 15:47:57 2011
@@ -35,12 +35,11 @@ import org.apache.james.mime4j.field.con
 import org.apache.james.mime4j.field.datetime.parser.DateTimeParser;
 import org.apache.james.mime4j.stream.Field;
 import org.apache.james.mime4j.stream.FieldParser;
-import org.apache.james.mime4j.util.ByteSequence;
 
 /**
  * Represents a <code>Content-Disposition</code> field.
  */
-public class ContentDispositionFieldImpl extends AbstractField implements org.apache.james.mime4j.dom.field.ContentDispositionField {
+public class ContentDispositionFieldImpl extends AbstractField implements ContentDispositionField {
 
     private boolean parsed = false;
 
@@ -57,8 +56,8 @@ public class ContentDispositionFieldImpl
     private boolean readDateParsed;
     private Date readDate;
 
-    ContentDispositionFieldImpl(String name, String body, ByteSequence raw, DecodeMonitor monitor) {
-        super(name, body, raw, monitor);
+    ContentDispositionFieldImpl(Field rawField, DecodeMonitor monitor) {
+        super(rawField, monitor);
     }
 
     /**
@@ -250,7 +249,7 @@ public class ContentDispositionFieldImpl
     public static final FieldParser<ContentDispositionField> PARSER = new FieldParser<ContentDispositionField>() {
         
         public ContentDispositionField parse(final Field rawField, final DecodeMonitor monitor) {
-            return new ContentDispositionFieldImpl(rawField.getName(), rawField.getBody(), rawField.getRaw(), monitor);
+            return new ContentDispositionFieldImpl(rawField, monitor);
         }
         
     };

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentIdFieldImpl.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentIdFieldImpl.java?rev=1127570&r1=1127569&r2=1127570&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentIdFieldImpl.java (original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentIdFieldImpl.java Wed May 25 15:47:57 2011
@@ -23,7 +23,6 @@ import org.apache.james.mime4j.codec.Dec
 import org.apache.james.mime4j.dom.field.ContentIdField;
 import org.apache.james.mime4j.stream.Field;
 import org.apache.james.mime4j.stream.FieldParser;
-import org.apache.james.mime4j.util.ByteSequence;
 
 /**
  * Represents a <code>Content-Transfer-Encoding</code> field.
@@ -33,8 +32,8 @@ public class ContentIdFieldImpl extends 
     private boolean parsed = false;
     private String id;
 
-    ContentIdFieldImpl(String name, String body, ByteSequence raw, DecodeMonitor monitor) {
-        super(name, body, raw, monitor);
+    ContentIdFieldImpl(Field rawField, DecodeMonitor monitor) {
+        super(rawField, monitor);
     }
 
     private void parse() {
@@ -57,7 +56,7 @@ public class ContentIdFieldImpl extends 
     public static final FieldParser<ContentIdField> PARSER = new FieldParser<ContentIdField>() {
         
         public ContentIdField parse(final Field rawField, final DecodeMonitor monitor) {
-            return new ContentIdFieldImpl(rawField.getName(), rawField.getBody(), rawField.getRaw(), monitor);
+            return new ContentIdFieldImpl(rawField, monitor);
         }
         
     };

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentLanguageFieldImpl.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentLanguageFieldImpl.java?rev=1127570&r1=1127569&r2=1127570&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentLanguageFieldImpl.java (original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentLanguageFieldImpl.java Wed May 25 15:47:57 2011
@@ -29,7 +29,6 @@ import org.apache.james.mime4j.field.lan
 import org.apache.james.mime4j.field.language.parser.ParseException;
 import org.apache.james.mime4j.stream.Field;
 import org.apache.james.mime4j.stream.FieldParser;
-import org.apache.james.mime4j.util.ByteSequence;
 
 /**
  * Represents a <code>Content-Transfer-Encoding</code> field.
@@ -40,8 +39,8 @@ public class ContentLanguageFieldImpl ex
     private List<String> languages;
     private ParseException parseException;
 
-    ContentLanguageFieldImpl(String name, String body, ByteSequence raw, DecodeMonitor monitor) {
-        super(name, body, raw, monitor);
+    ContentLanguageFieldImpl(Field rawField, DecodeMonitor monitor) {
+        super(rawField, monitor);
     }
 
     private void parse() {
@@ -75,7 +74,7 @@ public class ContentLanguageFieldImpl ex
     public static final FieldParser<ContentLanguageField> PARSER = new FieldParser<ContentLanguageField>() {
         
         public ContentLanguageField parse(final Field rawField, final DecodeMonitor monitor) {
-            return new ContentLanguageFieldImpl(rawField.getName(), rawField.getBody(), rawField.getRaw(), monitor);
+            return new ContentLanguageFieldImpl(rawField, monitor);
         }
         
     };

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentLengthFieldImpl.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentLengthFieldImpl.java?rev=1127570&r1=1127569&r2=1127570&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentLengthFieldImpl.java (original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentLengthFieldImpl.java Wed May 25 15:47:57 2011
@@ -23,7 +23,6 @@ import org.apache.james.mime4j.codec.Dec
 import org.apache.james.mime4j.dom.field.ContentLengthField;
 import org.apache.james.mime4j.stream.Field;
 import org.apache.james.mime4j.stream.FieldParser;
-import org.apache.james.mime4j.util.ByteSequence;
 
 /**
  * Represents a <code>Content-Length</code> field.
@@ -33,8 +32,8 @@ public class ContentLengthFieldImpl exte
     private boolean parsed = false;
     private long contentLength;
 
-    ContentLengthFieldImpl(String name, String body, ByteSequence raw, DecodeMonitor monitor) {
-        super(name, body, raw, monitor);
+    ContentLengthFieldImpl(Field rawField, DecodeMonitor monitor) {
+        super(rawField, monitor);
     }
 
     private void parse() {
@@ -72,7 +71,7 @@ public class ContentLengthFieldImpl exte
     public static final FieldParser<ContentLengthField> PARSER = new FieldParser<ContentLengthField>() {
         
         public ContentLengthField parse(final Field rawField, final DecodeMonitor monitor) {
-            return new ContentLengthFieldImpl(rawField.getName(), rawField.getBody(), rawField.getRaw(), monitor);
+            return new ContentLengthFieldImpl(rawField, monitor);
         }
         
     };

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentLocationFieldImpl.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentLocationFieldImpl.java?rev=1127570&r1=1127569&r2=1127570&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentLocationFieldImpl.java (original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentLocationFieldImpl.java Wed May 25 15:47:57 2011
@@ -27,7 +27,6 @@ import org.apache.james.mime4j.field.str
 import org.apache.james.mime4j.field.structured.parser.StructuredFieldParser;
 import org.apache.james.mime4j.stream.Field;
 import org.apache.james.mime4j.stream.FieldParser;
-import org.apache.james.mime4j.util.ByteSequence;
 
 /**
  * Represents a <code>Content-Transfer-Encoding</code> field.
@@ -38,8 +37,8 @@ public class ContentLocationFieldImpl ex
     private String location;
     private ParseException parseException;
 
-    ContentLocationFieldImpl(String name, String body, ByteSequence raw, DecodeMonitor monitor) {
-        super(name, body, raw, monitor);
+    ContentLocationFieldImpl(Field rawField, DecodeMonitor monitor) {
+        super(rawField, monitor);
     }
 
     private void parse() {
@@ -81,7 +80,7 @@ public class ContentLocationFieldImpl ex
     public static final FieldParser<ContentLocationField> PARSER = new FieldParser<ContentLocationField>() {
         
         public ContentLocationField parse(final Field rawField, final DecodeMonitor monitor) {
-            return new ContentLocationFieldImpl(rawField.getName(), rawField.getBody(), rawField.getRaw(), monitor);
+            return new ContentLocationFieldImpl(rawField, monitor);
         }
         
     };

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentMD5FieldImpl.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentMD5FieldImpl.java?rev=1127570&r1=1127569&r2=1127570&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentMD5FieldImpl.java (original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentMD5FieldImpl.java Wed May 25 15:47:57 2011
@@ -23,7 +23,6 @@ import org.apache.james.mime4j.codec.Dec
 import org.apache.james.mime4j.dom.field.ContentMD5Field;
 import org.apache.james.mime4j.stream.Field;
 import org.apache.james.mime4j.stream.FieldParser;
-import org.apache.james.mime4j.util.ByteSequence;
 
 /**
  * Represents a <code>Content-MD5</code> field.
@@ -33,8 +32,8 @@ public class ContentMD5FieldImpl extends
     private boolean parsed = false;
     private String md5raw;
 
-    ContentMD5FieldImpl(String name, String body, ByteSequence raw, DecodeMonitor monitor) {
-        super(name, body, raw, monitor);
+    ContentMD5FieldImpl(Field rawField, DecodeMonitor monitor) {
+        super(rawField, monitor);
     }
 
     private void parse() {
@@ -57,7 +56,7 @@ public class ContentMD5FieldImpl extends
     public static final FieldParser<ContentMD5Field> PARSER = new FieldParser<ContentMD5Field>() {
         
         public ContentMD5Field parse(final Field rawField, final DecodeMonitor monitor) {
-            return new ContentMD5FieldImpl(rawField.getName(), rawField.getBody(), rawField.getRaw(), monitor);
+            return new ContentMD5FieldImpl(rawField, 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=1127570&r1=1127569&r2=1127570&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 Wed May 25 15:47:57 2011
@@ -25,7 +25,6 @@ import org.apache.james.mime4j.codec.Dec
 import org.apache.james.mime4j.dom.field.ContentTransferEncodingField;
 import org.apache.james.mime4j.stream.Field;
 import org.apache.james.mime4j.stream.FieldParser;
-import org.apache.james.mime4j.util.ByteSequence;
 import org.apache.james.mime4j.util.MimeUtil;
 
 /**
@@ -36,8 +35,8 @@ public class ContentTransferEncodingFiel
     private boolean parsed = false;
     private String encoding;
 
-    ContentTransferEncodingFieldImpl(String name, String body, ByteSequence raw, DecodeMonitor monitor) {
-        super(name, body, raw, monitor);
+    ContentTransferEncodingFieldImpl(Field rawField, DecodeMonitor monitor) {
+        super(rawField, monitor);
     }
 
     private void parse() {
@@ -77,7 +76,7 @@ public class ContentTransferEncodingFiel
     public static final FieldParser<ContentTransferEncodingField> PARSER = new FieldParser<ContentTransferEncodingField>() {
         
         public ContentTransferEncodingField parse(final Field rawField, final DecodeMonitor monitor) {
-            return new ContentTransferEncodingFieldImpl(rawField.getName(), rawField.getBody(), rawField.getRaw(), monitor);
+            return new ContentTransferEncodingFieldImpl(rawField, 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=1127570&r1=1127569&r2=1127570&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 Wed May 25 15:47:57 2011
@@ -32,7 +32,6 @@ import org.apache.james.mime4j.field.con
 import org.apache.james.mime4j.field.contenttype.parser.TokenMgrError;
 import org.apache.james.mime4j.stream.Field;
 import org.apache.james.mime4j.stream.FieldParser;
-import org.apache.james.mime4j.util.ByteSequence;
 
 /**
  * Represents a <code>Content-Type</code> field.
@@ -46,8 +45,8 @@ public class ContentTypeFieldImpl extend
     private Map<String, String> parameters = new HashMap<String, String>();
     private ParseException parseException;
 
-    ContentTypeFieldImpl(String name, String body, ByteSequence raw, DecodeMonitor monitor) {
-        super(name, body, raw, monitor);
+    ContentTypeFieldImpl(Field rawField, DecodeMonitor monitor) {
+        super(rawField, monitor);
     }
 
     /**
@@ -226,7 +225,7 @@ public class ContentTypeFieldImpl extend
     public static final FieldParser<ContentTypeField> PARSER = new FieldParser<ContentTypeField>() {
         
         public ContentTypeField parse(final Field rawField, final DecodeMonitor monitor) {
-            return new ContentTypeFieldImpl(rawField.getName(), rawField.getBody(), rawField.getRaw(), monitor);
+            return new ContentTypeFieldImpl(rawField, monitor);
         }
         
     };

Added: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentTypeFieldLenientImpl.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentTypeFieldLenientImpl.java?rev=1127570&view=auto
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentTypeFieldLenientImpl.java (added)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentTypeFieldLenientImpl.java Wed May 25 15:47:57 2011
@@ -0,0 +1,152 @@
+/****************************************************************
+ * 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.field;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+
+import org.apache.james.mime4j.codec.DecodeMonitor;
+import org.apache.james.mime4j.dom.field.ContentTypeField;
+import org.apache.james.mime4j.stream.Field;
+import org.apache.james.mime4j.stream.FieldParser;
+import org.apache.james.mime4j.stream.NameValuePair;
+import org.apache.james.mime4j.stream.RawBody;
+import org.apache.james.mime4j.stream.RawField;
+import org.apache.james.mime4j.stream.RawFieldParser;
+
+/**
+ * Represents a <code>Content-Type</code> field.
+ */
+public class ContentTypeFieldLenientImpl extends AbstractField implements ContentTypeField {
+    
+    private boolean parsed = false;
+
+    private String mimeType = null;
+    private String mediaType = null;
+    private String subType = null;
+    private Map<String, String> parameters = new HashMap<String, String>();
+
+    ContentTypeFieldLenientImpl(Field rawField, DecodeMonitor monitor) {
+        super(rawField, monitor);
+    }
+
+    public String getMimeType() {
+        if (!parsed) {
+            parse();
+        }
+        return mimeType;
+    }
+
+    public String getMediaType() {
+        if (!parsed) {
+            parse();
+        }
+        return mediaType;
+    }
+
+    public String getSubType() {
+        if (!parsed) {
+            parse();
+        }
+        return subType;
+    }
+
+    public String getParameter(String name) {
+        if (!parsed) {
+            parse();
+        }
+        return parameters.get(name.toLowerCase());
+    }
+
+    public Map<String, String> getParameters() {
+        if (!parsed) {
+            parse();
+        }
+        return Collections.unmodifiableMap(parameters);
+    }
+
+    public boolean isMimeType(String mimeType) {
+        if (!parsed) {
+            parse();
+        }
+        return this.mimeType != null && this.mimeType.equalsIgnoreCase(mimeType);
+    }
+
+    public boolean isMultipart() {
+        if (!parsed) {
+            parse();
+        }
+        return this.mimeType != null && mimeType.startsWith(TYPE_MULTIPART_PREFIX);
+    }
+
+    public String getBoundary() {
+        return getParameter(PARAM_BOUNDARY);
+    }
+
+    public String getCharset() {
+        return getParameter(PARAM_CHARSET);
+    }
+
+    private void parse() {
+        parsed = true;
+        RawField f = getRawField();
+        RawBody body = RawFieldParser.DEFAULT.parseRawBody(f);
+        String main = body.getValue();
+        String type = null;
+        String subtype = null;
+        if (main != null) {
+            main = main.toLowerCase().trim();
+            int index = main.indexOf('/');
+            boolean valid = false;
+            if (index != -1) {
+                type = main.substring(0, index).trim();
+                subtype = main.substring(index + 1).trim();
+                if (type.length() > 0 && subtype.length() > 0) {
+                    main = type + "/" + subtype;
+                    valid = true;
+                }
+            }
+            if (!valid) {
+                main = null;
+                type = null;
+                subtype = null;
+            }
+        }
+        mimeType = main;
+        mediaType = type;
+        subType = subtype;
+        parameters.clear();
+        for (NameValuePair nmp: body.getParams()) {
+            String name = nmp.getName().toLowerCase(Locale.US);
+            parameters.put(name, nmp.getValue());
+        }
+    }
+
+    public static final FieldParser<ContentTypeField> PARSER = new FieldParser<ContentTypeField>() {
+        
+        public ContentTypeField parse(final Field rawField, final DecodeMonitor monitor) {
+            return new ContentTypeFieldLenientImpl(rawField, monitor);
+        }
+        
+    };
+
+}

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

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

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

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=1127570&r1=1127569&r2=1127570&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 Wed May 25 15:47:57 2011
@@ -29,7 +29,6 @@ import org.apache.james.mime4j.field.dat
 import org.apache.james.mime4j.field.datetime.parser.TokenMgrError;
 import org.apache.james.mime4j.stream.Field;
 import org.apache.james.mime4j.stream.FieldParser;
-import org.apache.james.mime4j.util.ByteSequence;
 
 /**
  * Date-time field such as <code>Date</code> or <code>Resent-Date</code>.
@@ -40,8 +39,8 @@ public class DateTimeFieldImpl extends A
     private Date date;
     private ParseException parseException;
 
-    DateTimeFieldImpl(String name, String body, ByteSequence raw, DecodeMonitor monitor) {
-        super(name, body, raw, monitor);
+    DateTimeFieldImpl(Field rawField, DecodeMonitor monitor) {
+        super(rawField, monitor);
     }
 
     /**
@@ -83,7 +82,7 @@ public class DateTimeFieldImpl extends A
     public static final FieldParser<DateTimeField> PARSER = new FieldParser<DateTimeField>() {
         
         public DateTimeField parse(final Field rawField, final DecodeMonitor monitor) {
-            return new DateTimeFieldImpl(rawField.getName(), rawField.getBody(), rawField.getRaw(), monitor);
+            return new DateTimeFieldImpl(rawField, monitor);
         }
         
     };

Added: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/LenientFieldParser.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/LenientFieldParser.java?rev=1127570&view=auto
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/LenientFieldParser.java (added)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/LenientFieldParser.java Wed May 25 15:47:57 2011
@@ -0,0 +1,134 @@
+/****************************************************************
+ * 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.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;
+import org.apache.james.mime4j.util.ContentUtil;
+
+public class LenientFieldParser extends DelegatingFieldParser {
+
+    private static final LenientFieldParser PARSER = new LenientFieldParser();
+    
+    /**
+     * Gets the default parser used to parse fields.
+     * 
+     * @return the default field parser
+     */
+    public static LenientFieldParser getParser() {
+        return PARSER;
+    }
+
+    /**
+     * Parses the given byte sequence and returns an instance of the
+     * <code>Field</code> class. The type of the class returned depends on the
+     * field name.
+     * 
+     * @param raw the bytes to parse.
+     * @param monitor a DecodeMonitor object used while parsing/decoding.
+     * @return a <code>ParsedField</code> instance.
+     * @throws MimeException if the raw string cannot be split into field name and body.
+     */
+    public static ParsedField parse(
+            final ByteSequence raw, 
+            final DecodeMonitor monitor) throws MimeException {
+        Field rawField = RawFieldParser.DEFAULT.parseField(raw);
+        return PARSER.parse(rawField, monitor);
+    }
+
+    /**
+     * Parses the given string and returns an instance of the <code>Field</code> class. 
+     * The type of the class returned depends on the field name.
+     * 
+     * @param rawStr the string to parse.
+     * @param monitor a DecodeMonitor object used while parsing/decoding.
+     * @return a <code>ParsedField</code> instance.
+     * @throws MimeException if the raw string cannot be split into field name and body.
+     */
+    public static ParsedField parse(
+            final String rawStr,
+            final DecodeMonitor monitor) throws MimeException {
+        ByteSequence raw = ContentUtil.encode(rawStr);
+        RawField rawField = RawFieldParser.DEFAULT.parseField(raw);
+        // Do not retain the original raw representation as the field
+        // may require folding
+        return PARSER.parse(rawField, monitor);
+    }
+
+    public static ParsedField parse(final String rawStr) throws MimeException {
+        return parse(rawStr, DecodeMonitor.SILENT);
+    }
+
+    public LenientFieldParser() {
+        setFieldParser(FieldName.CONTENT_TYPE, 
+                ContentTypeFieldLenientImpl.PARSER);
+        setFieldParser(FieldName.CONTENT_LENGTH,
+                ContentLengthFieldImpl.PARSER);
+        setFieldParser(FieldName.CONTENT_TRANSFER_ENCODING,
+                ContentTransferEncodingFieldImpl.PARSER);
+        setFieldParser(FieldName.CONTENT_DISPOSITION,
+                ContentDispositionFieldImpl.PARSER);
+        setFieldParser(FieldName.CONTENT_ID,
+                ContentDispositionFieldImpl.PARSER);
+        setFieldParser(FieldName.CONTENT_MD5,
+                ContentMD5FieldImpl.PARSER);
+        setFieldParser(FieldName.CONTENT_DESCRIPTION,
+                ContentDescriptionFieldImpl.PARSER);
+        setFieldParser(FieldName.CONTENT_LANGUAGE,
+                ContentLanguageFieldImpl.PARSER);
+        setFieldParser(FieldName.CONTENT_LOCATION,
+                ContentLocationFieldImpl.PARSER);
+        setFieldParser(FieldName.MIME_VERSION,
+                MimeVersionFieldImpl.PARSER);
+
+        final FieldParser<DateTimeField> dateTimeParser = DateTimeFieldImpl.PARSER;
+        setFieldParser(FieldName.DATE, dateTimeParser);
+        setFieldParser(FieldName.RESENT_DATE, dateTimeParser);
+
+        final FieldParser<MailboxListField> mailboxListParser = MailboxListFieldImpl.PARSER;
+        setFieldParser(FieldName.FROM, mailboxListParser);
+        setFieldParser(FieldName.RESENT_FROM, mailboxListParser);
+
+        final FieldParser<MailboxField> mailboxParser = MailboxFieldImpl.PARSER;
+        setFieldParser(FieldName.SENDER, mailboxParser);
+        setFieldParser(FieldName.RESENT_SENDER, mailboxParser);
+
+        final FieldParser<AddressListField> addressListParser = AddressListFieldImpl.PARSER;
+        setFieldParser(FieldName.TO, addressListParser);
+        setFieldParser(FieldName.RESENT_TO, addressListParser);
+        setFieldParser(FieldName.CC, addressListParser);
+        setFieldParser(FieldName.RESENT_CC, addressListParser);
+        setFieldParser(FieldName.BCC, addressListParser);
+        setFieldParser(FieldName.RESENT_BCC, addressListParser);
+        setFieldParser(FieldName.REPLY_TO, addressListParser);
+    }
+
+}

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

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

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

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=1127570&r1=1127569&r2=1127570&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 Wed May 25 15:47:57 2011
@@ -27,7 +27,6 @@ import org.apache.james.mime4j.field.add
 import org.apache.james.mime4j.field.address.ParseException;
 import org.apache.james.mime4j.stream.Field;
 import org.apache.james.mime4j.stream.FieldParser;
-import org.apache.james.mime4j.util.ByteSequence;
 
 /**
  * Mailbox field such as <code>Sender</code> or <code>Resent-Sender</code>.
@@ -38,8 +37,8 @@ public class MailboxFieldImpl extends Ab
     private Mailbox mailbox;
     private ParseException parseException;
 
-    MailboxFieldImpl(final String name, final String body, final ByteSequence raw, DecodeMonitor monitor) {
-        super(name, body, raw, monitor);
+    MailboxFieldImpl(Field rawField, DecodeMonitor monitor) {
+        super(rawField, monitor);
     }
 
     /**
@@ -81,7 +80,7 @@ public class MailboxFieldImpl extends Ab
     public static final FieldParser<MailboxField> PARSER = new FieldParser<MailboxField>() {
         
         public MailboxField parse(final Field rawField, final DecodeMonitor monitor) {
-            return new MailboxFieldImpl(rawField.getName(), rawField.getBody(), rawField.getRaw(), monitor);
+            return new MailboxFieldImpl(rawField, 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=1127570&r1=1127569&r2=1127570&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 Wed May 25 15:47:57 2011
@@ -26,7 +26,6 @@ import org.apache.james.mime4j.field.add
 import org.apache.james.mime4j.field.address.ParseException;
 import org.apache.james.mime4j.stream.Field;
 import org.apache.james.mime4j.stream.FieldParser;
-import org.apache.james.mime4j.util.ByteSequence;
 
 /**
  * Mailbox-list field such as <code>From</code> or <code>Resent-From</code>.
@@ -37,8 +36,8 @@ public class MailboxListFieldImpl extend
     private MailboxList mailboxList;
     private ParseException parseException;
 
-    MailboxListFieldImpl(final String name, final String body, final ByteSequence raw, DecodeMonitor monitor) {
-        super(name, body, raw, monitor);
+    MailboxListFieldImpl(Field rawField, DecodeMonitor monitor) {
+        super(rawField, monitor);
     }
 
     /**
@@ -77,7 +76,7 @@ public class MailboxListFieldImpl extend
     public static final FieldParser<MailboxListField> PARSER = new FieldParser<MailboxListField>() {
         
         public MailboxListField parse(final Field rawField, final DecodeMonitor monitor) {
-            return new MailboxListFieldImpl(rawField.getName(), rawField.getBody(), rawField.getRaw(), monitor);
+            return new MailboxListFieldImpl(rawField, monitor);
         }
         
     };

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/MimeVersionFieldImpl.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/MimeVersionFieldImpl.java?rev=1127570&r1=1127569&r2=1127570&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/MimeVersionFieldImpl.java (original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/MimeVersionFieldImpl.java Wed May 25 15:47:57 2011
@@ -28,7 +28,6 @@ import org.apache.james.mime4j.field.mim
 import org.apache.james.mime4j.field.mimeversion.parser.ParseException;
 import org.apache.james.mime4j.stream.Field;
 import org.apache.james.mime4j.stream.FieldParser;
-import org.apache.james.mime4j.util.ByteSequence;
 
 /**
  * Represents a <code>MIME-Version</code> field.
@@ -43,8 +42,8 @@ public class MimeVersionFieldImpl extend
     private int minor = DEFAULT_MINOR_VERSION;
     private ParseException parsedException;    
 
-    MimeVersionFieldImpl(String name, String body, ByteSequence raw, DecodeMonitor monitor) {
-        super(name, body, raw, monitor);
+    MimeVersionFieldImpl(Field rawField, DecodeMonitor monitor) {
+        super(rawField, monitor);
     }
 
     private void parse() {
@@ -93,7 +92,7 @@ public class MimeVersionFieldImpl extend
     public static final FieldParser<MimeVersionField> PARSER = new FieldParser<MimeVersionField>() {
         
         public MimeVersionField parse(final Field rawField, final DecodeMonitor monitor) {
-            return new MimeVersionFieldImpl(rawField.getName(), rawField.getBody(), rawField.getRaw(), monitor);
+            return new MimeVersionFieldImpl(rawField, 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=1127570&r1=1127569&r2=1127570&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 Wed May 25 15:47:57 2011
@@ -24,18 +24,17 @@ import org.apache.james.mime4j.codec.Dec
 import org.apache.james.mime4j.dom.field.UnstructuredField;
 import org.apache.james.mime4j.stream.Field;
 import org.apache.james.mime4j.stream.FieldParser;
-import org.apache.james.mime4j.util.ByteSequence;
 
 /**
  * Simple unstructured field such as <code>Subject</code>.
  */
-public class UnstructuredFieldImpl extends AbstractField implements org.apache.james.mime4j.dom.field.UnstructuredField {
+public class UnstructuredFieldImpl extends AbstractField implements UnstructuredField {
     private boolean parsed = false;
 
     private String value;
 
-    UnstructuredFieldImpl(String name, String body, ByteSequence raw, DecodeMonitor monitor) {
-        super(name, body, raw, monitor);
+    UnstructuredFieldImpl(Field rawField, DecodeMonitor monitor) {
+        super(rawField, monitor);
     }
 
     /**
@@ -59,7 +58,7 @@ public class UnstructuredFieldImpl exten
     public static final FieldParser<UnstructuredField> PARSER = new FieldParser<UnstructuredField>() {
         
         public UnstructuredField parse(final Field rawField, final DecodeMonitor monitor) {
-            return new UnstructuredFieldImpl(rawField.getName(), rawField.getBody(), rawField.getRaw(), monitor);
+            return new UnstructuredFieldImpl(rawField, monitor);
         }
         
     };

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=1127570&r1=1127569&r2=1127570&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 Wed May 25 15:47:57 2011
@@ -19,83 +19,83 @@
 
 package org.apache.james.mime4j.field;
 
+import org.apache.james.mime4j.MimeException;
 import org.apache.james.mime4j.dom.field.ContentTypeField;
 import org.apache.james.mime4j.field.ContentTypeFieldImpl;
-import org.apache.james.mime4j.field.DefaultFieldParser;
+import org.apache.james.mime4j.stream.RawField;
+import org.apache.james.mime4j.stream.RawFieldParser;
+import org.apache.james.mime4j.util.ByteSequence;
+import org.apache.james.mime4j.util.ContentUtil;
 
 import junit.framework.TestCase;
 
 public class ContentTypeFieldTest extends TestCase {
 
+    static ContentTypeField parse(final String s) throws MimeException {
+        ByteSequence raw = ContentUtil.encode(s);
+        RawField rawField = RawFieldParser.DEFAULT.parseField(raw);
+        return ContentTypeFieldImpl.PARSER.parse(rawField, null);
+    }
+    
     public void testMimeTypeWithSemiColonNoParams() throws Exception  {
-        ContentTypeField f = null;
-        
-        f = (ContentTypeField) DefaultFieldParser.parse("Content-Type: text/html;");
+        ContentTypeField f = parse("Content-Type: text/html;");
         assertEquals("text/html", f.getMimeType());
     }
     
     public void testGetMimeType() throws Exception {
-        ContentTypeField f = null;
-        
-        f = (ContentTypeField) DefaultFieldParser.parse("Content-Type: text/PLAIN");
+        ContentTypeField f = parse("Content-Type: text/PLAIN");
         assertEquals("text/plain", f.getMimeType());
         
-        f = (ContentTypeField) DefaultFieldParser.parse("content-type:   TeXt / html   ");
+        f = parse("content-type:   TeXt / html   ");
         assertEquals("text/html", f.getMimeType());
         
-        f = (ContentTypeField) DefaultFieldParser.parse("CONTENT-TYPE:   x-app/yada ;"
+        f = parse("CONTENT-TYPE:   x-app/yada ;"
                                                     + "  param = yada");
         assertEquals("x-app/yada", f.getMimeType());
         
-        f = (ContentTypeField) DefaultFieldParser.parse("CONTENT-TYPE:   yada");
+        f = parse("CONTENT-TYPE:   yada");
         assertEquals(null, f.getMimeType());
     }
     
     public void testGetMimeTypeStatic() throws Exception {
-        ContentTypeField child = null;
-        ContentTypeField parent = null;
+        ContentTypeField child = parse("Content-Type: child/type");;
+        ContentTypeField parent = parse("Content-Type: parent/type");
         
-        child = (ContentTypeField) DefaultFieldParser.parse("Content-Type: child/type");
-        parent = (ContentTypeField) DefaultFieldParser.parse("Content-Type: parent/type");
         assertEquals("child/type", ContentTypeFieldImpl.getMimeType(child, parent));
         
         child = null;
-        parent = (ContentTypeField) DefaultFieldParser.parse("Content-Type: parent/type");
+        parent = parse("Content-Type: parent/type");
         assertEquals("text/plain", ContentTypeFieldImpl.getMimeType(child, parent));
-        parent = (ContentTypeField) DefaultFieldParser.parse("Content-Type: multipart/digest");
+        parent = parse("Content-Type: multipart/digest");
         assertEquals("message/rfc822", ContentTypeFieldImpl.getMimeType(child, parent));
         
-        child = (ContentTypeField) DefaultFieldParser.parse("Content-Type:");
-        parent = (ContentTypeField) DefaultFieldParser.parse("Content-Type: parent/type");
+        child = parse("Content-Type:");
+        parent = parse("Content-Type: parent/type");
         assertEquals("text/plain", ContentTypeFieldImpl.getMimeType(child, parent));
-        parent = (ContentTypeField) DefaultFieldParser.parse("Content-Type: multipart/digest");
+        parent = parse("Content-Type: multipart/digest");
         assertEquals("message/rfc822", ContentTypeFieldImpl.getMimeType(child, parent));
     }
     
     public void testGetCharsetStatic() throws Exception {
-        ContentTypeField f = null;
-        
-        f = (ContentTypeField) DefaultFieldParser.parse("Content-Type: some/type; charset=iso8859-1");
+        ContentTypeField f = parse("Content-Type: some/type; charset=iso8859-1");
         assertEquals("iso8859-1", ContentTypeFieldImpl.getCharset(f));
         
-        f = (ContentTypeField) DefaultFieldParser.parse("Content-Type: some/type;");
+        f = parse("Content-Type: some/type;");
         assertEquals("us-ascii", ContentTypeFieldImpl.getCharset(f));
     }
     
     public void testGetParameter() throws Exception {
-        ContentTypeField f = null;
-        
-        f = (ContentTypeField) DefaultFieldParser.parse("CONTENT-TYPE:   text / html ;"
+        ContentTypeField f = parse("CONTENT-TYPE:   text / html ;"
                                                 + "  boundary=yada yada");
         assertEquals("yada", f.getParameter("boundary"));
         
-        f = (ContentTypeField) DefaultFieldParser.parse("Content-Type: x-app/yada;"
+        f = parse("Content-Type: x-app/yada;"
                                                 + "  boUNdarY= \"ya:\\\"*da\"; "
                                                 + "\tcharset\t =  us-ascii");
         assertEquals("ya:\"*da", f.getParameter("boundary"));
         assertEquals("us-ascii", f.getParameter("charset"));
         
-        f = (ContentTypeField) DefaultFieldParser.parse("Content-Type: x-app/yada;  "
+        f = parse("Content-Type: x-app/yada;  "
                             + "boUNdarY= \"ya \\\"\\\"\tda \\\"\"; "
                             + "\tcharset\t =  \"\\\"hepp\\\"  =us\t-ascii\"");
         assertEquals("ya \"\"\tda \"", f.getParameter("boundary"));

Added: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/LenientContentTypeFieldTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/LenientContentTypeFieldTest.java?rev=1127570&view=auto
==============================================================================
--- james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/LenientContentTypeFieldTest.java (added)
+++ james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/LenientContentTypeFieldTest.java Wed May 25 15:47:57 2011
@@ -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.field;
+
+import org.apache.james.mime4j.MimeException;
+import org.apache.james.mime4j.dom.field.ContentTypeField;
+import org.apache.james.mime4j.stream.RawField;
+import org.apache.james.mime4j.stream.RawFieldParser;
+import org.apache.james.mime4j.util.ByteSequence;
+import org.apache.james.mime4j.util.ContentUtil;
+
+import junit.framework.TestCase;
+
+public class LenientContentTypeFieldTest extends TestCase {
+
+    static ContentTypeField parse(final String s) throws MimeException {
+        ByteSequence raw = ContentUtil.encode(s);
+        RawField rawField = RawFieldParser.DEFAULT.parseField(raw);
+        return ContentTypeFieldLenientImpl.PARSER.parse(rawField, null);
+    }
+    
+    public void testMimeTypeWithSemiColonNoParams() throws Exception  {
+        ContentTypeField f = parse("Content-Type: text/html;");
+        assertEquals("text/html", f.getMimeType());
+    }
+    
+    public void testMimeTypeWithMultipleSemiColon() throws Exception  {
+        ContentTypeField f = parse("Content-Type: text/html;;;");
+        assertEquals("text/html", f.getMimeType());
+        assertEquals(1, f.getParameters().size());
+    }
+    
+    public void testMimeTypeWithNonameParam() throws Exception  {
+        ContentTypeField f = parse("Content-Type: text/html;=stuff");
+        assertEquals("text/html", f.getMimeType());
+        assertEquals(1, f.getParameters().size());
+        assertEquals("stuff", f.getParameter(""));
+    }
+    
+    public void testGetMimeType() throws Exception {
+        ContentTypeField f = parse("Content-Type: text/PLAIN");
+        assertEquals("text/plain", f.getMimeType());
+        
+        f = parse("content-type:   TeXt / html   ");
+        assertEquals("text/html", f.getMimeType());
+        
+        f = parse("CONTENT-TYPE:   x-app/yada ;"
+                                                    + "  param = yada");
+        assertEquals("x-app/yada", f.getMimeType());
+        
+        f = parse("CONTENT-TYPE:   yada");
+        assertEquals(null, f.getMimeType());
+    }
+    
+    public void testGetParameter() throws Exception {
+        ContentTypeField f = parse("CONTENT-TYPE:   text / html ;"
+                                                + "  boundary=yada yada");
+        assertEquals("yada yada", f.getParameter("boundary"));
+        
+        f = parse("Content-Type: x-app/yada;"
+                                                + "  boUNdarY= \"ya:\\\"*da\"; "
+                                                + "\tcharset\t =  us-ascii");
+        assertEquals("ya:\"*da", f.getParameter("boundary"));
+        assertEquals("us-ascii", f.getParameter("charset"));
+        
+        f = parse("Content-Type: x-app/yada;  "
+                            + "boUNdarY= \"ya \\\"\\\"\tda \\\"\"; "
+                            + "\tcharset\t =  \"\\\"hepp\\\"  =us\t-ascii\"");
+        assertEquals("ya \"\"\tda \"", f.getParameter("boundary"));
+        assertEquals("\"hepp\"  =us\t-ascii", f.getParameter("charset"));
+    }
+
+}

Propchange: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/LenientContentTypeFieldTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/LenientContentTypeFieldTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/LenientContentTypeFieldTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message