james-mime4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1130114 - in /james/mime4j/trunk: core/src/main/java/org/apache/james/mime4j/codec/ core/src/main/java/org/apache/james/mime4j/stream/ dom/src/main/java/org/apache/james/mime4j/field/ dom/src/test/java/org/apache/james/mime4j/field/
Date Wed, 01 Jun 2011 11:58:12 GMT
Author: olegk
Date: Wed Jun  1 11:58:11 2011
New Revision: 1130114

URL: http://svn.apache.org/viewvc?rev=1130114&view=rev
Log:
MIME4J-197: added lenient implementations of ContentDispositionField and ContentLanguageField

Added:
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentDispositionFieldLenientImpl.java   (with props)
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentLanguageFieldLenientImpl.java   (with props)
    james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/ContentLanguageFieldTest.java   (with props)
    james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/LenientContentDispositionFieldTest.java   (with props)
    james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/LenientContentLanguageFieldTest.java   (with props)
Modified:
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/codec/DecodeMonitor.java
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/ParserCursor.java
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/RawField.java
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/RawFieldParser.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/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/ContentTypeFieldLenientImpl.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/LenientFieldParser.java
    james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/ContentDispositionFieldTest.java
    james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/ContentTransferEncodingFieldTest.java

Modified: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/codec/DecodeMonitor.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/codec/DecodeMonitor.java?rev=1130114&r1=1130113&r2=1130114&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/codec/DecodeMonitor.java (original)
+++ james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/codec/DecodeMonitor.java Wed Jun  1 11:58:11 2011
@@ -25,7 +25,7 @@ package org.apache.james.mime4j.codec;
  * and unexpected data.
  * 
  * 2 basic implementations are provided:
- * STRICT return "true" on any occourence.
+ * STRICT return "true" on any occurrence.
  * SILENT ignores any problem.
  * 
  * @see org.apache.james.mime4j.field.LoggingMonitor for an example

Modified: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/ParserCursor.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/ParserCursor.java?rev=1130114&r1=1130113&r2=1130114&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/ParserCursor.java (original)
+++ james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/ParserCursor.java Wed Jun  1 11:58:11 2011
@@ -28,7 +28,7 @@ package org.apache.james.mime4j.stream;
  * <p/>
  * Copied from Apache HttpCore project
  */
-class ParserCursor {
+public class ParserCursor {
 
     private final int lowerBound;
     private final int upperBound;

Modified: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/RawField.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/RawField.java?rev=1130114&r1=1130113&r2=1130114&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/RawField.java (original)
+++ james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/RawField.java Wed Jun  1 11:58:11 2011
@@ -68,7 +68,7 @@ public final class RawField implements F
         return null;
     }
 
-    int getDelimiterIdx() {
+    public int getDelimiterIdx() {
         return delimiterIdx;
     }
 

Modified: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/RawFieldParser.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/RawFieldParser.java?rev=1130114&r1=1130113&r2=1130114&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/RawFieldParser.java (original)
+++ james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/RawFieldParser.java Wed Jun  1 11:58:11 2011
@@ -66,7 +66,7 @@ public class RawFieldParser {
         return parseRawBody(buf, cursor);
     }
 
-    RawBody parseRawBody(final ByteSequence buf, final ParserCursor cursor) {
+    public RawBody parseRawBody(final ByteSequence buf, final ParserCursor cursor) {
         String value = parseToken(buf, cursor, SEMICOLON);
         if (cursor.atEnd()) {
             return new RawBody(value, new ArrayList<NameValuePair>());
@@ -76,7 +76,7 @@ public class RawFieldParser {
         return new RawBody(value, params);
     }
 
-    List<NameValuePair> parseParameters(final ByteSequence buf, final ParserCursor cursor) {
+    public List<NameValuePair> parseParameters(final ByteSequence buf, final ParserCursor cursor) {
         List<NameValuePair> params = new ArrayList<NameValuePair>();
         skipWhiteSpace(buf, cursor);
         while (!cursor.atEnd()) {
@@ -86,7 +86,7 @@ public class RawFieldParser {
         return params;
     }
 
-    NameValuePair parseParameter(final ByteSequence buf, final ParserCursor cursor) {
+    public NameValuePair parseParameter(final ByteSequence buf, final ParserCursor cursor) {
         String name = parseToken(buf, cursor, EQUAL_OR_SEMICOLON);
         if (cursor.atEnd()) {
             return new NameValuePair(name, null);
@@ -114,7 +114,7 @@ public class RawFieldParser {
         return false;
     }
 
-    static String parseToken(final ByteSequence buf, final ParserCursor cursor, final int[] delimiters) {
+    public static String parseToken(final ByteSequence buf, final ParserCursor cursor, final int[] delimiters) {
         StringBuilder dst = new StringBuilder();
         boolean whitespace = false;
         while (!cursor.atEnd()) {
@@ -137,7 +137,7 @@ public class RawFieldParser {
         return dst.toString();
     }
 
-    static String parseValue(final ByteSequence buf, final ParserCursor cursor, final int[] delimiters) {
+    public static String parseValue(final ByteSequence buf, final ParserCursor cursor, final int[] delimiters) {
         StringBuilder dst = new StringBuilder();
         boolean whitespace = false;
         while (!cursor.atEnd()) {
@@ -166,7 +166,7 @@ public class RawFieldParser {
         return dst.toString();
     }
 
-    static void skipWhiteSpace(final ByteSequence buf, final ParserCursor cursor) {
+    public static void skipWhiteSpace(final ByteSequence buf, final ParserCursor cursor) {
         int pos = cursor.getPos();
         int indexFrom = cursor.getPos();
         int indexTo = cursor.getUpperBound();
@@ -181,7 +181,7 @@ public class RawFieldParser {
         cursor.updatePos(pos);
     }
 
-    static void skipComment(final ByteSequence buf, final ParserCursor cursor) {
+    public static void skipComment(final ByteSequence buf, final ParserCursor cursor) {
         if (cursor.atEnd()) {
             return;
         }
@@ -218,7 +218,7 @@ public class RawFieldParser {
         cursor.updatePos(pos);
     }
 
-    static void copyContent(final ByteSequence buf, final ParserCursor cursor, final int[] delimiters,
+    public static void copyContent(final ByteSequence buf, final ParserCursor cursor, final int[] delimiters,
             final StringBuilder dst) {
         int pos = cursor.getPos();
         int indexFrom = cursor.getPos();
@@ -235,7 +235,7 @@ public class RawFieldParser {
         cursor.updatePos(pos);
     }
 
-    static void copyQuotedContent(final ByteSequence buf, final ParserCursor cursor,
+    public static void copyQuotedContent(final ByteSequence buf, final ParserCursor cursor,
             final StringBuilder dst) {
         if (cursor.atEnd()) {
             return;

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=1130114&r1=1130113&r2=1130114&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 Jun  1 11:58:11 2011
@@ -202,12 +202,14 @@ public class ContentDispositionFieldImpl
             return new DateTimeParser(new StringReader(value)).parseAll()
                     .getDate();
         } catch (org.apache.james.mime4j.field.datetime.parser.ParseException e) {
-            monitor.warn("Parsing " + paramName + " '" + value + "': "
-                    + e.getMessage(), "returning null");
+            if (monitor.isListening()) {
+                monitor.warn(paramName + " parameter is invalid: " + value, 
+                        paramName + " parameter is ignored");
+            }
             return null;
-        } catch (org.apache.james.mime4j.field.datetime.parser.TokenMgrError e) {
-            monitor.warn("Parsing " + paramName + " '" + value + "': "
-                    + e.getMessage(), "returning null");
+        } catch (TokenMgrError e) {
+            monitor.warn(paramName + " parameter is invalid: " + value, 
+                    paramName + "parameter is ignored");
             return null;
         }
     }

Added: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentDispositionFieldLenientImpl.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentDispositionFieldLenientImpl.java?rev=1130114&view=auto
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentDispositionFieldLenientImpl.java (added)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentDispositionFieldLenientImpl.java Wed Jun  1 11:58:11 2011
@@ -0,0 +1,205 @@
+/****************************************************************
+ * 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.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.TimeZone;
+
+import org.apache.james.mime4j.codec.DecodeMonitor;
+import org.apache.james.mime4j.dom.field.ContentDispositionField;
+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-Disposition</code> field.
+ */
+public class ContentDispositionFieldLenientImpl extends AbstractField implements ContentDispositionField {
+
+    private static final String DEFAULT_DATE_FORMAT = "EEE, dd MMM yyyy hh:mm:ss ZZZZ";
+    
+    private final List<String> datePatterns;
+    
+    private boolean parsed = false;
+
+    private String dispositionType = "";
+    private Map<String, String> parameters = new HashMap<String, String>();
+
+    private boolean creationDateParsed;
+    private Date creationDate;
+
+    private boolean modificationDateParsed;
+    private Date modificationDate;
+
+    private boolean readDateParsed;
+    private Date readDate;
+
+    ContentDispositionFieldLenientImpl(final Field rawField, 
+            final Collection<String> dateParsers, final DecodeMonitor monitor) {
+        super(rawField, monitor);
+        this.datePatterns = new ArrayList<String>();
+        if (dateParsers != null) {
+            this.datePatterns.addAll(dateParsers);
+        } else {
+            this.datePatterns.add(DEFAULT_DATE_FORMAT);
+        }
+    }
+
+    public String getDispositionType() {
+        if (!parsed) {
+            parse();
+        }
+        return dispositionType;
+    }
+
+    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 isDispositionType(String dispositionType) {
+        if (!parsed) {
+            parse();
+        }
+        return this.dispositionType.equalsIgnoreCase(dispositionType);
+    }
+
+    public boolean isInline() {
+        if (!parsed) {
+            parse();
+        }
+        return dispositionType.equals(DISPOSITION_TYPE_INLINE);
+    }
+
+    public boolean isAttachment() {
+        if (!parsed) {
+            parse();
+        }
+        return dispositionType.equals(DISPOSITION_TYPE_ATTACHMENT);
+    }
+
+    public String getFilename() {
+        return getParameter(PARAM_FILENAME);
+    }
+
+    public Date getCreationDate() {
+        if (!creationDateParsed) {
+            creationDate = parseDate(PARAM_CREATION_DATE);
+            creationDateParsed = true;
+        }
+        return creationDate;
+    }
+
+    public Date getModificationDate() {
+        if (!modificationDateParsed) {
+            modificationDate = parseDate(PARAM_MODIFICATION_DATE);
+            modificationDateParsed = true;
+        }
+        return modificationDate;
+    }
+
+    public Date getReadDate() {
+        if (!readDateParsed) {
+            readDate = parseDate(PARAM_READ_DATE);
+            readDateParsed = true;
+        }
+        return readDate;
+    }
+
+    public long getSize() {
+        String value = getParameter(PARAM_SIZE);
+        if (value == null)
+            return -1;
+
+        try {
+            long size = Long.parseLong(value);
+            return size < 0 ? -1 : size;
+        } catch (NumberFormatException e) {
+            return -1;
+        }
+    }
+
+    private void parse() {
+        parsed = true;
+        RawField f = getRawField();
+        RawBody body = RawFieldParser.DEFAULT.parseRawBody(f);
+        String main = body.getValue();
+        if (main != null) {
+            dispositionType = main.toLowerCase(Locale.US);
+        } else {
+            dispositionType = null;
+        }
+        parameters.clear();
+        for (NameValuePair nmp: body.getParams()) {
+            String name = nmp.getName().toLowerCase(Locale.US);
+            parameters.put(name, nmp.getValue());
+        }
+    }
+
+    private Date parseDate(final String paramName) {
+        String value = getParameter(paramName);
+        if (value == null) {
+            return null;
+        }
+        for (String datePattern: datePatterns) {
+            try {
+                SimpleDateFormat parser = new SimpleDateFormat(datePattern, Locale.US);
+                parser.setTimeZone(TimeZone.getTimeZone("GMT"));
+                parser.setLenient(true);
+                return parser.parse(value);
+            } catch (ParseException ignore) {
+            }
+        }
+        if (monitor.isListening()) {
+            monitor.warn(paramName + " parameter is invalid: " + value, 
+                    paramName + " parameter is ignored");
+        }
+        return null;
+    }
+
+    public static final FieldParser<ContentDispositionField> PARSER = new FieldParser<ContentDispositionField>() {
+        
+        public ContentDispositionField parse(final Field rawField, final DecodeMonitor monitor) {
+            return new ContentDispositionFieldLenientImpl(rawField, null, monitor);
+        }
+        
+    };
+}

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

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

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

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=1130114&r1=1130113&r2=1130114&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 Jun  1 11:58:11 2011
@@ -20,6 +20,7 @@
 package org.apache.james.mime4j.field;
 
 import java.io.StringReader;
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 
@@ -45,6 +46,7 @@ public class ContentLanguageFieldImpl ex
 
     private void parse() {
         parsed = true;
+        languages = Collections.<String>emptyList();
         String body = getBody();
         if (body != null) {
             ContentLanguageParser parser = new ContentLanguageParser(new StringReader(body));
@@ -52,10 +54,7 @@ public class ContentLanguageFieldImpl ex
                 languages = parser.parse();
             } catch (ParseException ex) {
                 parseException = ex;
-                languages = Collections.<String>emptyList();
             }
-        } else {
-            languages = Collections.<String>emptyList();
         }
     }
 
@@ -68,7 +67,7 @@ public class ContentLanguageFieldImpl ex
         if (!parsed) {
             parse();
         }
-        return languages;
+        return new ArrayList<String>(languages);
     }
 
     public static final FieldParser<ContentLanguageField> PARSER = new FieldParser<ContentLanguageField>() {

Added: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentLanguageFieldLenientImpl.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentLanguageFieldLenientImpl.java?rev=1130114&view=auto
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentLanguageFieldLenientImpl.java (added)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentLanguageFieldLenientImpl.java Wed Jun  1 11:58:11 2011
@@ -0,0 +1,97 @@
+/****************************************************************
+ * 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.ArrayList;
+import java.util.List;
+
+import org.apache.james.mime4j.codec.DecodeMonitor;
+import org.apache.james.mime4j.dom.field.ContentLanguageField;
+import org.apache.james.mime4j.stream.Field;
+import org.apache.james.mime4j.stream.FieldParser;
+import org.apache.james.mime4j.stream.ParserCursor;
+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;
+
+/**
+ * Represents a <code>Content-Transfer-Encoding</code> field.
+ */
+public class ContentLanguageFieldLenientImpl extends AbstractField implements ContentLanguageField {
+
+    private final static int   COMMA = ',';
+    private final static int[] DELIM = new int[] { COMMA };
+    
+    private boolean parsed = false;
+    private List<String> languages;
+
+    ContentLanguageFieldLenientImpl(final Field rawField, final DecodeMonitor monitor) {
+        super(rawField, monitor);
+    }
+
+    private void parse() {
+        parsed = true;
+        RawField f = getRawField();
+        ByteSequence buf = f.getRaw();
+        int pos = f.getDelimiterIdx() + 1;
+        if (buf == null) {
+            String body = f.getBody();
+            if (body == null) {
+                return;
+            }
+            buf = ContentUtil.encode(body);
+            pos = 0;
+        }
+        languages = new ArrayList<String>();
+        ParserCursor cursor = new ParserCursor(pos, buf.length());
+        for (;;) {
+            String token = RawFieldParser.parseToken(buf, cursor, DELIM);
+            if (token.length() > 0) {
+                languages.add(token);
+            }
+            if (cursor.atEnd()) {
+                break;
+            } else {
+                pos = cursor.getPos();
+                if (buf.byteAt(pos) == COMMA) {
+                    cursor.updatePos(pos + 1);
+                }
+            }
+        }
+    }
+
+    public List<String> getLanguages() {
+        if (!parsed) {
+            parse();
+        }
+        return new ArrayList<String>(languages);
+    }
+
+    public static final FieldParser<ContentLanguageField> PARSER = new FieldParser<ContentLanguageField>() {
+        
+        public ContentLanguageField parse(final Field rawField, final DecodeMonitor monitor) {
+            return new ContentLanguageFieldLenientImpl(rawField, monitor);
+        }
+        
+    };
+
+}
+

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

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

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

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=1130114&r1=1130113&r2=1130114&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 Jun  1 11:58:11 2011
@@ -38,26 +38,24 @@ public class ContentLengthFieldImpl exte
 
     private void parse() {
         parsed = true;
+        contentLength = -1;
         String body = getBody();
         if (body != null) {
             try {
-                long v = Long.parseLong(body);
-                if (v < 0) {
-                    if (monitor.warn("Negative content length: " + body, 
-                            "ignoring Content-Length header")) {
-                        contentLength = -1;
+                contentLength = Long.parseLong(body);
+                if (contentLength < 0) {
+                    contentLength = -1;
+                    if (monitor.isListening()) {
+                        monitor.warn("Negative content length: " + body, 
+                                "ignoring Content-Length header");
                     }
-                } else {
-                    contentLength = v;
                 }
             } catch (NumberFormatException e) {
-                if (monitor.warn("Invalid content length: " + body, 
-                        "ignoring Content-Length header")) {
-                    contentLength = -1;
+                if (monitor.isListening()) {
+                    monitor.warn("Invalid content length: " + body, 
+                            "ignoring Content-Length header");
                 }
             }
-        } else {
-            contentLength = -1;
         }
     }
     

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=1130114&r1=1130113&r2=1130114&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 Jun  1 11:58:11 2011
@@ -44,6 +44,7 @@ public class ContentLocationFieldImpl ex
     private void parse() {
         parsed = true;
         String body = getBody();
+        location = null;
         if (body != null) {
             StringReader stringReader = new StringReader(body);
             StructuredFieldParser parser = new StructuredFieldParser(stringReader);
@@ -58,10 +59,7 @@ public class ContentLocationFieldImpl ex
                 location = parser.parse().replaceAll("\\s", "");
             } catch (ParseException ex) { 
                 parseException = ex;
-                location = null;
             }
-        } else {
-            location = null;
         }
     }
     

Modified: 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=1130114&r1=1130113&r2=1130114&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentTypeFieldLenientImpl.java (original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentTypeFieldLenientImpl.java Wed Jun  1 11:58:11 2011
@@ -45,7 +45,7 @@ public class ContentTypeFieldLenientImpl
     private String subType = null;
     private Map<String, String> parameters = new HashMap<String, String>();
 
-    ContentTypeFieldLenientImpl(Field rawField, DecodeMonitor monitor) {
+    ContentTypeFieldLenientImpl(final Field rawField, final DecodeMonitor monitor) {
         super(rawField, monitor);
     }
 
@@ -126,6 +126,9 @@ public class ContentTypeFieldLenientImpl
                 }
             }
             if (!valid) {
+                if (monitor.isListening()) {
+                    monitor.warn("Invalid Content-Type: " + body, "Content-Type value ignored");
+                }
                 main = null;
                 type = null;
                 subtype = null;

Modified: 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=1130114&r1=1130113&r2=1130114&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/LenientFieldParser.java (original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/LenientFieldParser.java Wed Jun  1 11:58:11 2011
@@ -89,21 +89,21 @@ public class LenientFieldParser extends 
 
     public LenientFieldParser() {
         setFieldParser(FieldName.CONTENT_TYPE, 
-                ContentTypeFieldLenientImpl.PARSER);
+                ContentTypeFieldLenientImpl.PARSER);        // lenient 
         setFieldParser(FieldName.CONTENT_LENGTH,
-                ContentLengthFieldImpl.PARSER);
+                ContentLengthFieldImpl.PARSER);             // default
         setFieldParser(FieldName.CONTENT_TRANSFER_ENCODING,
-                ContentTransferEncodingFieldImpl.PARSER);
+                ContentTransferEncodingFieldImpl.PARSER);   // default
         setFieldParser(FieldName.CONTENT_DISPOSITION,
-                ContentDispositionFieldImpl.PARSER);
+                ContentDispositionFieldLenientImpl.PARSER); // lenient
         setFieldParser(FieldName.CONTENT_ID,
-                ContentDispositionFieldImpl.PARSER);
+                ContentIdFieldImpl.PARSER);                 // default
         setFieldParser(FieldName.CONTENT_MD5,
-                ContentMD5FieldImpl.PARSER);
+                ContentMD5FieldImpl.PARSER);                // default
         setFieldParser(FieldName.CONTENT_DESCRIPTION,
-                ContentDescriptionFieldImpl.PARSER);
+                ContentDescriptionFieldImpl.PARSER);        // default
         setFieldParser(FieldName.CONTENT_LANGUAGE,
-                ContentLanguageFieldImpl.PARSER);
+                ContentLanguageFieldLenientImpl.PARSER);    // lenient
         setFieldParser(FieldName.CONTENT_LOCATION,
                 ContentLocationFieldImpl.PARSER);
         setFieldParser(FieldName.MIME_VERSION,

Modified: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/ContentDispositionFieldTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/ContentDispositionFieldTest.java?rev=1130114&r1=1130113&r2=1130114&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/ContentDispositionFieldTest.java (original)
+++ james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/ContentDispositionFieldTest.java Wed Jun  1 11:58:11 2011
@@ -23,54 +23,51 @@ import java.util.Date;
 
 import junit.framework.TestCase;
 
+import org.apache.james.mime4j.MimeException;
 import org.apache.james.mime4j.dom.field.ContentDispositionField;
-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;
 
 public class ContentDispositionFieldTest extends TestCase {
 
+    static ContentDispositionField parse(final String s) throws MimeException {
+        ByteSequence raw = ContentUtil.encode(s);
+        RawField rawField = RawFieldParser.DEFAULT.parseField(raw);
+        return ContentDispositionFieldImpl.PARSER.parse(rawField, null);
+    }
+    
     public void testDispositionTypeWithSemiColonNoParams() throws Exception {
-        ContentDispositionField f = null;
-
-        f = (ContentDispositionField) DefaultFieldParser
-                .parse("Content-Disposition: inline;");
+        ContentDispositionField f = parse("Content-Disposition: inline;");
         assertEquals("inline", f.getDispositionType());
     }
 
     public void testGetDispositionType() throws Exception {
-        ContentDispositionField f = null;
-
-        f = (ContentDispositionField) DefaultFieldParser
-                .parse("Content-Disposition: attachment");
+        ContentDispositionField f = parse("Content-Disposition: attachment");
         assertEquals("attachment", f.getDispositionType());
 
-        f = (ContentDispositionField) DefaultFieldParser
-                .parse("content-disposition:   InLiNe   ");
+        f = parse("content-disposition:   InLiNe   ");
         assertEquals("inline", f.getDispositionType());
 
-        f = (ContentDispositionField) DefaultFieldParser
-                .parse("CONTENT-DISPOSITION:   x-yada ;" + "  param = yada");
+        f = parse("CONTENT-DISPOSITION:   x-yada ;" + "  param = yada");
         assertEquals("x-yada", f.getDispositionType());
 
-        f = (ContentDispositionField) DefaultFieldParser.parse("CONTENT-DISPOSITION:   ");
+        f = parse("CONTENT-DISPOSITION:   ");
         assertEquals("", f.getDispositionType());
     }
 
     public void testGetParameter() throws Exception {
-        ContentDispositionField f = null;
-
-        f = (ContentDispositionField) DefaultFieldParser
-                .parse("CONTENT-DISPOSITION:   inline ;"
+        ContentDispositionField f = parse("CONTENT-DISPOSITION:   inline ;"
                         + "  filename=yada yada");
         assertEquals("yada", f.getParameter("filename"));
 
-        f = (ContentDispositionField) DefaultFieldParser
-                .parse("Content-Disposition: x-yada;"
+        f = parse("Content-Disposition: x-yada;"
                         + "  fileNAme= \"ya:\\\"*da\"; " + "\tSIZE\t =  1234");
         assertEquals("ya:\"*da", f.getParameter("filename"));
         assertEquals("1234", f.getParameter("size"));
 
-        f = (ContentDispositionField) DefaultFieldParser
-                .parse("Content-Disposition: x-yada;  "
+        f = parse("Content-Disposition: x-yada;  "
                         + "fileNAme= \"ya \\\"\\\"\tda \\\"\"; "
                         + "\tx-Yada\t =  \"\\\"hepp\\\"  =us\t-ascii\"");
         assertEquals("ya \"\"\tda \"", f.getParameter("filename"));
@@ -78,126 +75,93 @@ public class ContentDispositionFieldTest
     }
 
     public void testIsDispositionType() throws Exception {
-        ContentDispositionField f = null;
-
-        f = (ContentDispositionField) DefaultFieldParser.parse("Content-Disposition:INline");
+        ContentDispositionField f = parse("Content-Disposition:INline");
         assertTrue(f.isDispositionType("InLiNe"));
         assertFalse(f.isDispositionType("NiLiNe"));
         assertTrue(f.isInline());
         assertFalse(f.isAttachment());
 
-        f = (ContentDispositionField) DefaultFieldParser
-                .parse("Content-Disposition: attachment");
+        f = parse("Content-Disposition: attachment");
         assertTrue(f.isDispositionType("ATTACHMENT"));
         assertFalse(f.isInline());
         assertTrue(f.isAttachment());
 
-        f = (ContentDispositionField) DefaultFieldParser
-                .parse("Content-Disposition: x-something");
+        f = parse("Content-Disposition: x-something");
         assertTrue(f.isDispositionType("x-SomeThing"));
         assertFalse(f.isInline());
         assertFalse(f.isAttachment());
     }
 
     public void testGetFilename() throws Exception {
-        ContentDispositionField f = null;
-
-        f = (ContentDispositionField) DefaultFieldParser
-                .parse("Content-Disposition: inline; filename=yada.txt");
+        ContentDispositionField f = parse("Content-Disposition: inline; filename=yada.txt");
         assertEquals("yada.txt", f.getFilename());
 
-        f = (ContentDispositionField) DefaultFieldParser
-                .parse("Content-Disposition: inline; filename=yada yada.txt");
+        f = parse("Content-Disposition: inline; filename=yada yada.txt");
         assertEquals("yada", f.getFilename());
 
-        f = (ContentDispositionField) DefaultFieldParser
-                .parse("Content-Disposition: inline; filename=\"yada yada.txt\"");
+        f = parse("Content-Disposition: inline; filename=\"yada yada.txt\"");
         assertEquals("yada yada.txt", f.getFilename());
 
-        f = (ContentDispositionField) DefaultFieldParser
-                .parse("Content-Disposition: inline");
+        f = parse("Content-Disposition: inline");
         assertNull(f.getFilename());
     }
 
     public void testGetCreationDate() throws Exception {
-        ContentDispositionField f = null;
-
-        f = (ContentDispositionField) DefaultFieldParser
-                .parse("Content-Disposition: inline; "
+        ContentDispositionField f = parse("Content-Disposition: inline; "
                         + "creation-date=\"Tue, 01 Jan 1970 00:00:00 +0000\"");
         assertEquals(new Date(0), f.getCreationDate());
 
-        f = (ContentDispositionField) DefaultFieldParser
-                .parse("Content-Disposition: inline; "
+        f = parse("Content-Disposition: inline; "
                         + "creation-date=Tue, 01 Jan 1970 00:00:00 +0000");
         assertNull(f.getCreationDate());
 
-        f = (ContentDispositionField) DefaultFieldParser
-                .parse("Content-Disposition: attachment");
+        f = parse("Content-Disposition: attachment");
         assertNull(f.getCreationDate());
     }
 
     public void testGetModificationDate() throws Exception {
-        ContentDispositionField f = null;
-
-        f = (ContentDispositionField) DefaultFieldParser
-                .parse("Content-Disposition: inline; "
+        ContentDispositionField f = parse("Content-Disposition: inline; "
                         + "modification-date=\"Tue, 01 Jan 1970 00:00:00 +0000\"");
         assertEquals(new Date(0), f.getModificationDate());
 
-        f = (ContentDispositionField) DefaultFieldParser
-                .parse("Content-Disposition: inline; "
+        f = parse("Content-Disposition: inline; "
                         + "modification-date=\"Wed, 12 Feb 1997 16:29:51 -0500\"");
         assertEquals(new Date(855782991000l), f.getModificationDate());
 
-        f = (ContentDispositionField) DefaultFieldParser
-                .parse("Content-Disposition: inline; "
+        f = parse("Content-Disposition: inline; "
                         + "modification-date=yesterday");
         assertNull(f.getModificationDate());
 
-        f = (ContentDispositionField) DefaultFieldParser
-                .parse("Content-Disposition: attachment");
+        f = parse("Content-Disposition: attachment");
         assertNull(f.getModificationDate());
     }
 
     public void testGetReadDate() throws Exception {
-        ContentDispositionField f = null;
-
-        f = (ContentDispositionField) DefaultFieldParser
-                .parse("Content-Disposition: inline; "
+        ContentDispositionField f = parse("Content-Disposition: inline; "
                         + "read-date=\"Tue, 01 Jan 1970 00:00:00 +0000\"");
         assertEquals(new Date(0), f.getReadDate());
 
-        f = (ContentDispositionField) DefaultFieldParser
-                .parse("Content-Disposition: inline; read-date=");
+        f = parse("Content-Disposition: inline; read-date=");
         assertNull(f.getReadDate());
 
-        f = (ContentDispositionField) DefaultFieldParser
-                .parse("Content-Disposition: attachment");
+        f = parse("Content-Disposition: attachment");
         assertNull(f.getReadDate());
     }
 
     public void testGetSize() throws Exception {
-        ContentDispositionField f = null;
-
-        f = (ContentDispositionField) DefaultFieldParser
-                .parse("Content-Disposition: attachment; size=0");
+        ContentDispositionField f = parse("Content-Disposition: attachment; size=0");
         assertEquals(0, f.getSize());
 
-        f = (ContentDispositionField) DefaultFieldParser
-                .parse("Content-Disposition: attachment; size=matters");
+        f = parse("Content-Disposition: attachment; size=matters");
         assertEquals(-1, f.getSize());
 
-        f = (ContentDispositionField) DefaultFieldParser
-                .parse("Content-Disposition: attachment");
+        f = parse("Content-Disposition: attachment");
         assertEquals(-1, f.getSize());
 
-        f = (ContentDispositionField) DefaultFieldParser
-                .parse("Content-Disposition: attachment; size=-12");
+        f = parse("Content-Disposition: attachment; size=-12");
         assertEquals(-1, f.getSize());
 
-        f = (ContentDispositionField) DefaultFieldParser
-                .parse("Content-Disposition: attachment; size=12");
+        f = parse("Content-Disposition: attachment; size=12");
         assertEquals(12, f.getSize());
     }
 

Added: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/ContentLanguageFieldTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/ContentLanguageFieldTest.java?rev=1130114&view=auto
==============================================================================
--- james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/ContentLanguageFieldTest.java (added)
+++ james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/ContentLanguageFieldTest.java Wed Jun  1 11:58:11 2011
@@ -0,0 +1,75 @@
+/****************************************************************
+ * 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.List;
+
+import org.apache.james.mime4j.MimeException;
+import org.apache.james.mime4j.dom.field.ContentLanguageField;
+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 ContentLanguageFieldTest extends TestCase {
+
+    static ContentLanguageField parse(final String s) throws MimeException {
+        ByteSequence raw = ContentUtil.encode(s);
+        RawField rawField = RawFieldParser.DEFAULT.parseField(raw);
+        return ContentLanguageFieldImpl.PARSER.parse(rawField, null);
+    }
+    
+    public void testGetLanguage() throws Exception {
+        ContentLanguageField f = parse("Content-Language: en, de");
+        List<String> langs = f.getLanguages();
+        assertNotNull(langs);
+        assertEquals(2, langs.size());
+        assertEquals("en", langs.get(0));
+        assertEquals("de", langs.get(1));
+    }
+    
+    public void testGetLanguageWithComments() throws Exception {
+        ContentLanguageField f = parse("Content-Language: en (yada yada), (blah blah)de");
+        List<String> langs = f.getLanguages();
+        assertNotNull(langs);
+        assertEquals(2, langs.size());
+        assertEquals("en", langs.get(0));
+        assertEquals("de", langs.get(1));
+    }
+    
+    public void testGetLanguageWithUnderscore() throws Exception {
+        ContentLanguageField f = parse("Content-Language: en, en_GB (Great Britain)");
+        List<String> langs = f.getLanguages();
+        assertNotNull(langs);
+        assertEquals(0, langs.size());
+        assertNotNull(f.getParseException());
+    }
+    
+    public void testGetLanguageWithEmptyElement() throws Exception {
+        ContentLanguageField f = parse("Content-Language: en,, de");
+        List<String> langs = f.getLanguages();
+        assertNotNull(langs);
+        assertEquals(0, langs.size());
+        assertNotNull(f.getParseException());
+    }
+    
+}

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

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

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

Modified: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/ContentTransferEncodingFieldTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/ContentTransferEncodingFieldTest.java?rev=1130114&r1=1130113&r2=1130114&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/ContentTransferEncodingFieldTest.java (original)
+++ james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/ContentTransferEncodingFieldTest.java Wed Jun  1 11:58:11 2011
@@ -19,50 +19,49 @@
 
 package org.apache.james.mime4j.field;
 
+import org.apache.james.mime4j.MimeException;
 import org.apache.james.mime4j.dom.field.ContentTransferEncodingField;
 import org.apache.james.mime4j.field.ContentTransferEncodingFieldImpl;
-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 ContentTransferEncodingFieldTest extends TestCase {
 
+    static ContentTransferEncodingField parse(final String s) throws MimeException {
+        ByteSequence raw = ContentUtil.encode(s);
+        RawField rawField = RawFieldParser.DEFAULT.parseField(raw);
+        return ContentTransferEncodingFieldImpl.PARSER.parse(rawField, null);
+    }
+    
     public void testGetEncoding() throws Exception {
-        ContentTransferEncodingField f = null;
-        
-        f = (ContentTransferEncodingField) 
-                    DefaultFieldParser.parse("Content-Transfer-Encoding: 8bit");
+        ContentTransferEncodingField f = parse("Content-Transfer-Encoding: 8bit");
         assertEquals("8bit", f.getEncoding());
         
-        f = (ContentTransferEncodingField) 
-                    DefaultFieldParser.parse("Content-Transfer-Encoding:    BaSE64   ");
+        f = parse("Content-Transfer-Encoding:    BaSE64   ");
         assertEquals("base64", f.getEncoding());
         
-        f = (ContentTransferEncodingField) 
-                    DefaultFieldParser.parse("Content-Transfer-Encoding:       ");
+        f = parse("Content-Transfer-Encoding:       ");
         assertEquals("", f.getEncoding());
         
-        f = (ContentTransferEncodingField) 
-                    DefaultFieldParser.parse("Content-Transfer-Encoding:");
+        f = parse("Content-Transfer-Encoding:");
         assertEquals("", f.getEncoding());
     }
     
     public void testGetEncodingStatic() throws Exception {
-        ContentTransferEncodingField f = null;
-        
-        f = (ContentTransferEncodingField) 
-                    DefaultFieldParser.parse("Content-Transfer-Encoding: 8bit");
+        ContentTransferEncodingField f = parse("Content-Transfer-Encoding: 8bit");
         assertEquals("8bit", ContentTransferEncodingFieldImpl.getEncoding(f));
         
         f = null;
         assertEquals("7bit", ContentTransferEncodingFieldImpl.getEncoding(f));
         
-        f = (ContentTransferEncodingField) 
-                    DefaultFieldParser.parse("Content-Transfer-Encoding:       ");
+        f = parse("Content-Transfer-Encoding:       ");
         assertEquals("7bit", ContentTransferEncodingFieldImpl.getEncoding(f));
         
-        f = (ContentTransferEncodingField) 
-                    DefaultFieldParser.parse("Content-Transfer-Encoding:");
+        f = parse("Content-Transfer-Encoding:");
         assertEquals("7bit", ContentTransferEncodingFieldImpl.getEncoding(f));
     }
 

Added: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/LenientContentDispositionFieldTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/LenientContentDispositionFieldTest.java?rev=1130114&view=auto
==============================================================================
--- james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/LenientContentDispositionFieldTest.java (added)
+++ james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/LenientContentDispositionFieldTest.java Wed Jun  1 11:58:11 2011
@@ -0,0 +1,168 @@
+/****************************************************************
+ * 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.Date;
+
+import junit.framework.TestCase;
+
+import org.apache.james.mime4j.MimeException;
+import org.apache.james.mime4j.dom.field.ContentDispositionField;
+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 LenientContentDispositionFieldTest extends TestCase {
+
+    static ContentDispositionField parse(final String s) throws MimeException {
+        ByteSequence raw = ContentUtil.encode(s);
+        RawField rawField = RawFieldParser.DEFAULT.parseField(raw);
+        return ContentDispositionFieldLenientImpl.PARSER.parse(rawField, null);
+    }
+    
+    public void testDispositionTypeWithSemiColonNoParams() throws Exception {
+        ContentDispositionField f = parse("Content-Disposition: inline;");
+        assertEquals("inline", f.getDispositionType());
+    }
+
+    public void testGetDispositionType() throws Exception {
+        ContentDispositionField f = parse("Content-Disposition: attachment");
+        assertEquals("attachment", f.getDispositionType());
+
+        f = parse("content-disposition:   InLiNe   ");
+        assertEquals("inline", f.getDispositionType());
+
+        f = parse("CONTENT-DISPOSITION:   x-yada ;" + "  param = yada");
+        assertEquals("x-yada", f.getDispositionType());
+
+        f = parse("CONTENT-DISPOSITION:   ");
+        assertEquals("", f.getDispositionType());
+    }
+
+    public void testGetParameter() throws Exception {
+        ContentDispositionField f = parse("CONTENT-DISPOSITION:   inline ;"
+                        + "  filename=yada yada");
+        assertEquals("yada yada", f.getParameter("filename"));
+
+        f = parse("Content-Disposition: x-yada;"
+                        + "  fileNAme= \"ya:\\\"*da\"; " + "\tSIZE\t =  1234");
+        assertEquals("ya:\"*da", f.getParameter("filename"));
+        assertEquals("1234", f.getParameter("size"));
+
+        f = parse("Content-Disposition: x-yada;  "
+                        + "fileNAme= \"ya \\\"\\\"\tda \\\"\"; "
+                        + "\tx-Yada\t =  \"\\\"hepp\\\"  =us\t-ascii\"");
+        assertEquals("ya \"\"\tda \"", f.getParameter("filename"));
+        assertEquals("\"hepp\"  =us\t-ascii", f.getParameter("x-yada"));
+    }
+
+    public void testIsDispositionType() throws Exception {
+        ContentDispositionField f = parse("Content-Disposition:INline");
+        assertTrue(f.isDispositionType("InLiNe"));
+        assertFalse(f.isDispositionType("NiLiNe"));
+        assertTrue(f.isInline());
+        assertFalse(f.isAttachment());
+
+        f = parse("Content-Disposition: attachment");
+        assertTrue(f.isDispositionType("ATTACHMENT"));
+        assertFalse(f.isInline());
+        assertTrue(f.isAttachment());
+
+        f = parse("Content-Disposition: x-something");
+        assertTrue(f.isDispositionType("x-SomeThing"));
+        assertFalse(f.isInline());
+        assertFalse(f.isAttachment());
+    }
+
+    public void testGetFilename() throws Exception {
+        ContentDispositionField f = parse("Content-Disposition: inline; filename=yada.txt");
+        assertEquals("yada.txt", f.getFilename());
+
+        f = parse("Content-Disposition: inline; filename=yada yada.txt");
+        assertEquals("yada yada.txt", f.getFilename());
+
+        f = parse("Content-Disposition: inline; filename=\"yada yada.txt\"");
+        assertEquals("yada yada.txt", f.getFilename());
+
+        f = parse("Content-Disposition: inline");
+        assertNull(f.getFilename());
+    }
+
+    public void testGetCreationDate() throws Exception {
+        ContentDispositionField f = parse("Content-Disposition: inline; "
+                        + "creation-date=\"Tue, 01 Jan 1970 00:00:00 +0000\"");
+        assertEquals(new Date(0), f.getCreationDate());
+
+        f = parse("Content-Disposition: inline; "
+                        + "creation-date=Tue, 01 Jan 1970 00:00:00 +0000");
+        assertEquals(new Date(0), f.getCreationDate());
+
+        f = parse("Content-Disposition: attachment");
+        assertNull(f.getCreationDate());
+    }
+
+    public void testGetModificationDate() throws Exception {
+        ContentDispositionField f = parse("Content-Disposition: inline; "
+                        + "modification-date=\"Tue, 01 Jan 1970 00:00:00 +0000\"");
+        assertEquals(new Date(0), f.getModificationDate());
+
+        f = parse("Content-Disposition: inline; "
+                        + "modification-date=\"Wed, 12 Feb 1997 16:29:51 -0500\"");
+        assertEquals(new Date(855782991000l), f.getModificationDate());
+
+        f = parse("Content-Disposition: inline; "
+                        + "modification-date=yesterday");
+        assertNull(f.getModificationDate());
+
+        f = parse("Content-Disposition: attachment");
+        assertNull(f.getModificationDate());
+    }
+
+    public void testGetReadDate() throws Exception {
+        ContentDispositionField f = parse("Content-Disposition: inline; "
+                        + "read-date=\"Tue, 01 Jan 1970 00:00:00 +0000\"");
+        assertEquals(new Date(0), f.getReadDate());
+
+        f = parse("Content-Disposition: inline; read-date=");
+        assertNull(f.getReadDate());
+
+        f = parse("Content-Disposition: attachment");
+        assertNull(f.getReadDate());
+    }
+
+    public void testGetSize() throws Exception {
+        ContentDispositionField f = parse("Content-Disposition: attachment; size=0");
+        assertEquals(0, f.getSize());
+
+        f = parse("Content-Disposition: attachment; size=matters");
+        assertEquals(-1, f.getSize());
+
+        f = parse("Content-Disposition: attachment");
+        assertEquals(-1, f.getSize());
+
+        f = parse("Content-Disposition: attachment; size=-12");
+        assertEquals(-1, f.getSize());
+
+        f = parse("Content-Disposition: attachment; size=12");
+        assertEquals(12, f.getSize());
+    }
+
+}

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

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

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

Added: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/LenientContentLanguageFieldTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/LenientContentLanguageFieldTest.java?rev=1130114&view=auto
==============================================================================
--- james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/LenientContentLanguageFieldTest.java (added)
+++ james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/LenientContentLanguageFieldTest.java Wed Jun  1 11:58:11 2011
@@ -0,0 +1,84 @@
+/****************************************************************
+ * 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.List;
+
+import org.apache.james.mime4j.MimeException;
+import org.apache.james.mime4j.dom.field.ContentLanguageField;
+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 LenientContentLanguageFieldTest extends TestCase {
+
+    static ContentLanguageField parse(final String s) throws MimeException {
+        ByteSequence raw = ContentUtil.encode(s);
+        RawField rawField = RawFieldParser.DEFAULT.parseField(raw);
+        return ContentLanguageFieldLenientImpl.PARSER.parse(rawField, null);
+    }
+    
+    public void testGetLanguage() throws Exception {
+        ContentLanguageField f = parse("Content-Language: en, de");
+        List<String> langs = f.getLanguages();
+        assertNotNull(langs);
+        assertEquals(2, langs.size());
+        assertEquals("en", langs.get(0));
+        assertEquals("de", langs.get(1));
+    }
+    
+    public void testGetLanguageEmpty() throws Exception {
+        ContentLanguageField f = parse("Content-Language: ");
+        List<String> langs = f.getLanguages();
+        assertNotNull(langs);
+        assertEquals(0, langs.size());
+    }
+    
+    public void testGetLanguageWithComments() throws Exception {
+        ContentLanguageField f = parse("Content-Language: en (yada yada), (blah blah)de");
+        List<String> langs = f.getLanguages();
+        assertNotNull(langs);
+        assertEquals(2, langs.size());
+        assertEquals("en", langs.get(0));
+        assertEquals("de", langs.get(1));
+    }
+    
+    public void testGetLanguageWithUnderscore() throws Exception {
+        ContentLanguageField f = parse("Content-Language: en, en_GB (Great Britain)");
+        List<String> langs = f.getLanguages();
+        assertNotNull(langs);
+        assertEquals(2, langs.size());
+        assertEquals("en", langs.get(0));
+        assertEquals("en_GB", langs.get(1));
+    }
+    
+    public void testGetLanguageWithEmptyElement() throws Exception {
+        ContentLanguageField f = parse("Content-Language: en,, de,");
+        List<String> langs = f.getLanguages();
+        assertNotNull(langs);
+        assertEquals(2, langs.size());
+        assertEquals("en", langs.get(0));
+        assertEquals("de", langs.get(1));
+    }
+    
+}

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

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

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



Mime
View raw message