james-mime4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1135968 - in /james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j: field/ message/
Date Wed, 15 Jun 2011 09:18:00 GMT
Author: olegk
Date: Wed Jun 15 09:17:59 2011
New Revision: 1135968

URL: http://svn.apache.org/viewvc?rev=1135968&view=rev
Log:
MIME4J-197: added lenient implementations of MailboxField, MailboxListField, AddressListField
and DateTimeField

Added:
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/AddressListFieldLenientImpl.java
  (with props)
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/DateTimeFieldLenientImpl.java
  (with props)
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/MailboxFieldLenientImpl.java
  (with props)
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/MailboxListFieldLenientImpl.java
  (with props)
Modified:
    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/DateTimeFieldImpl.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/LenientFieldParser.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/message/EntityBuilder.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MimeBuilder.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/SimpleContentHandler.java

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=1135968&r1=1135967&r2=1135968&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 Jun 15 09:17:59 2011
@@ -30,7 +30,7 @@ import org.apache.james.mime4j.stream.Fi
 /**
  * Address list field such as <code>To</code> or <code>Reply-To</code>.
  */
-public class AddressListFieldImpl extends AbstractField implements org.apache.james.mime4j.dom.field.AddressListField
{
+public class AddressListFieldImpl extends AbstractField implements AddressListField {
 
     private boolean parsed = false;
 

Added: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/AddressListFieldLenientImpl.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/AddressListFieldLenientImpl.java?rev=1135968&view=auto
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/AddressListFieldLenientImpl.java
(added)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/AddressListFieldLenientImpl.java
Wed Jun 15 09:17:59 2011
@@ -0,0 +1,82 @@
+/****************************************************************
+ * 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 org.apache.james.mime4j.codec.DecodeMonitor;
+import org.apache.james.mime4j.dom.address.AddressList;
+import org.apache.james.mime4j.dom.address.Mailbox;
+import org.apache.james.mime4j.dom.field.AddressListField;
+import org.apache.james.mime4j.field.address.LenientAddressBuilder;
+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.util.ByteSequence;
+import org.apache.james.mime4j.util.ContentUtil;
+
+/**
+ * Address list field such as <code>To</code> or <code>Reply-To</code>.
+ */
+public class AddressListFieldLenientImpl extends AbstractField implements AddressListField
{
+
+    private boolean parsed = false;
+
+    private AddressList addressList;
+
+    AddressListFieldLenientImpl(final Field rawField, final DecodeMonitor monitor) {
+        super(rawField, monitor);
+    }
+
+    public AddressList getAddressList() {
+        if (!parsed)
+            parse();
+
+        return addressList;
+    }
+
+    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) {
+                addressList = new AddressList(Collections.<Mailbox>emptyList(), true);
+                return;
+            }
+            buf = ContentUtil.encode(body);
+            pos = 0;
+        }
+        ParserCursor cursor = new ParserCursor(pos, buf.length());
+        addressList = LenientAddressBuilder.DEFAULT.parseAddressList(buf, cursor);
+    }
+
+    public static final FieldParser<AddressListField> PARSER = new FieldParser<AddressListField>()
{
+
+        public AddressListField parse(final Field rawField, final DecodeMonitor monitor)
{
+            return new AddressListFieldLenientImpl(rawField, monitor);
+        }
+
+    };
+
+}

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

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

Propchange: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/AddressListFieldLenientImpl.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=1135968&r1=1135967&r2=1135968&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 Jun 15 09:17:59 2011
@@ -33,7 +33,7 @@ import org.apache.james.mime4j.stream.Fi
 /**
  * Date-time field such as <code>Date</code> or <code>Resent-Date</code>.
  */
-public class DateTimeFieldImpl extends AbstractField implements org.apache.james.mime4j.dom.field.DateTimeField
{
+public class DateTimeFieldImpl extends AbstractField implements DateTimeField {
     private boolean parsed = false;
 
     private Date date;

Added: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/DateTimeFieldLenientImpl.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/DateTimeFieldLenientImpl.java?rev=1135968&view=auto
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/DateTimeFieldLenientImpl.java
(added)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/DateTimeFieldLenientImpl.java
Wed Jun 15 09:17:59 2011
@@ -0,0 +1,89 @@
+/****************************************************************
+ * 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.Date;
+import java.util.List;
+import java.util.Locale;
+import java.util.TimeZone;
+
+import org.apache.james.mime4j.codec.DecodeMonitor;
+import org.apache.james.mime4j.dom.field.DateTimeField;
+import org.apache.james.mime4j.stream.Field;
+import org.apache.james.mime4j.stream.FieldParser;
+
+/**
+ * Date-time field such as <code>Date</code> or <code>Resent-Date</code>.
+ */
+public class DateTimeFieldLenientImpl extends AbstractField implements DateTimeField {
+
+    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 Date date;
+
+    DateTimeFieldLenientImpl(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 Date getDate() {
+        if (!parsed) {
+            parse();
+        }
+        return date;
+    }
+
+    private void parse() {
+        parsed = true;
+        date = null;
+        String body = getBody();
+        for (String datePattern: datePatterns) {
+            try {
+                SimpleDateFormat parser = new SimpleDateFormat(datePattern, Locale.US);
+                parser.setTimeZone(TimeZone.getTimeZone("GMT"));
+                parser.setLenient(true);
+                date = parser.parse(body);
+                break;
+            } catch (ParseException ignore) {
+            }
+        }
+    }
+
+    public static final FieldParser<DateTimeField> PARSER = new FieldParser<DateTimeField>()
{
+
+        public DateTimeField parse(final Field rawField, final DecodeMonitor monitor) {
+            return new DateTimeFieldLenientImpl(rawField, null, monitor);
+        }
+
+    };
+}

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

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

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

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=1135968&r1=1135967&r2=1135968&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 15 09:17:59 2011
@@ -110,19 +110,19 @@ public class LenientFieldParser extends 
         setFieldParser(FieldName.MIME_VERSION,
                 MimeVersionFieldImpl.PARSER);               // lenient
 
-        final FieldParser<DateTimeField> dateTimeParser = DateTimeFieldImpl.PARSER;
+        FieldParser<DateTimeField> dateTimeParser = DateTimeFieldLenientImpl.PARSER;
         setFieldParser(FieldName.DATE, dateTimeParser);
         setFieldParser(FieldName.RESENT_DATE, dateTimeParser);
 
-        final FieldParser<MailboxListField> mailboxListParser = MailboxListFieldImpl.PARSER;
+        FieldParser<MailboxListField> mailboxListParser = MailboxListFieldLenientImpl.PARSER;
         setFieldParser(FieldName.FROM, mailboxListParser);
         setFieldParser(FieldName.RESENT_FROM, mailboxListParser);
 
-        final FieldParser<MailboxField> mailboxParser = MailboxFieldImpl.PARSER;
+        FieldParser<MailboxField> mailboxParser = MailboxFieldLenientImpl.PARSER;
         setFieldParser(FieldName.SENDER, mailboxParser);
         setFieldParser(FieldName.RESENT_SENDER, mailboxParser);
 
-        final FieldParser<AddressListField> addressListParser = AddressListFieldImpl.PARSER;
+        FieldParser<AddressListField> addressListParser = AddressListFieldLenientImpl.PARSER;
         setFieldParser(FieldName.TO, addressListParser);
         setFieldParser(FieldName.RESENT_TO, addressListParser);
         setFieldParser(FieldName.CC, addressListParser);

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/MailboxFieldImpl.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/MailboxFieldImpl.java?rev=1135968&r1=1135967&r2=1135968&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 Jun 15 09:17:59 2011
@@ -21,7 +21,6 @@ package org.apache.james.mime4j.field;
 
 import org.apache.james.mime4j.codec.DecodeMonitor;
 import org.apache.james.mime4j.dom.address.Mailbox;
-import org.apache.james.mime4j.dom.address.MailboxList;
 import org.apache.james.mime4j.dom.field.MailboxField;
 import org.apache.james.mime4j.field.address.AddressBuilder;
 import org.apache.james.mime4j.field.address.ParseException;
@@ -31,7 +30,7 @@ import org.apache.james.mime4j.stream.Fi
 /**
  * Mailbox field such as <code>Sender</code> or <code>Resent-Sender</code>.
  */
-public class MailboxFieldImpl extends AbstractField implements org.apache.james.mime4j.dom.field.MailboxField
{
+public class MailboxFieldImpl extends AbstractField implements MailboxField {
     private boolean parsed = false;
 
     private Mailbox mailbox;
@@ -66,10 +65,7 @@ public class MailboxFieldImpl extends Ab
         String body = getBody();
 
         try {
-            MailboxList mailboxList = AddressBuilder.DEFAULT.parseAddressList(body, monitor).flatten();
-            if (mailboxList.size() > 0) {
-                mailbox = mailboxList.get(0);
-            }
+            mailbox = AddressBuilder.DEFAULT.parseMailbox(body, monitor);
         } catch (ParseException e) {
             parseException = e;
         }

Added: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/MailboxFieldLenientImpl.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/MailboxFieldLenientImpl.java?rev=1135968&view=auto
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/MailboxFieldLenientImpl.java
(added)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/MailboxFieldLenientImpl.java
Wed Jun 15 09:17:59 2011
@@ -0,0 +1,77 @@
+/****************************************************************
+ * 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.codec.DecodeMonitor;
+import org.apache.james.mime4j.dom.address.Mailbox;
+import org.apache.james.mime4j.dom.field.MailboxField;
+import org.apache.james.mime4j.field.address.LenientAddressBuilder;
+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.util.ByteSequence;
+import org.apache.james.mime4j.util.ContentUtil;
+
+/**
+ * Mailbox field such as <code>Sender</code> or <code>Resent-Sender</code>.
+ */
+public class MailboxFieldLenientImpl extends AbstractField implements MailboxField {
+
+    private boolean parsed = false;
+
+    private Mailbox mailbox;
+
+    MailboxFieldLenientImpl(final Field rawField, final DecodeMonitor monitor) {
+        super(rawField, monitor);
+    }
+
+    public Mailbox getMailbox() {
+        if (!parsed) {
+            parse();
+        }
+        return mailbox;
+    }
+
+    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;
+        }
+        ParserCursor cursor = new ParserCursor(pos, buf.length());
+        mailbox = LenientAddressBuilder.DEFAULT.parseMailbox(buf, cursor, null);
+    }
+
+    public static final FieldParser<MailboxField> PARSER = new FieldParser<MailboxField>()
{
+
+        public MailboxField parse(final Field rawField, final DecodeMonitor monitor) {
+            return new MailboxFieldLenientImpl(rawField, monitor);
+        }
+
+    };
+}

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

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

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

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=1135968&r1=1135967&r2=1135968&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 Jun 15 09:17:59 2011
@@ -30,7 +30,7 @@ import org.apache.james.mime4j.stream.Fi
 /**
  * Mailbox-list field such as <code>From</code> or <code>Resent-From</code>.
  */
-public class MailboxListFieldImpl extends AbstractField implements org.apache.james.mime4j.dom.field.MailboxListField
{
+public class MailboxListFieldImpl extends AbstractField implements MailboxListField {
     private boolean parsed = false;
 
     private MailboxList mailboxList;

Added: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/MailboxListFieldLenientImpl.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/MailboxListFieldLenientImpl.java?rev=1135968&view=auto
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/MailboxListFieldLenientImpl.java
(added)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/MailboxListFieldLenientImpl.java
Wed Jun 15 09:17:59 2011
@@ -0,0 +1,82 @@
+/****************************************************************
+ * 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 org.apache.james.mime4j.codec.DecodeMonitor;
+import org.apache.james.mime4j.dom.address.Mailbox;
+import org.apache.james.mime4j.dom.address.MailboxList;
+import org.apache.james.mime4j.dom.field.MailboxListField;
+import org.apache.james.mime4j.field.address.LenientAddressBuilder;
+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.util.ByteSequence;
+import org.apache.james.mime4j.util.ContentUtil;
+
+/**
+ * Mailbox-list field such as <code>From</code> or <code>Resent-From</code>.
+ */
+public class MailboxListFieldLenientImpl extends AbstractField implements MailboxListField
{
+
+    private boolean parsed = false;
+
+    private MailboxList mailboxList;
+
+    MailboxListFieldLenientImpl(final Field rawField, final DecodeMonitor monitor) {
+        super(rawField, monitor);
+    }
+
+    public MailboxList getMailboxList() {
+        if (!parsed) {
+            parse();
+        }
+        return mailboxList;
+    }
+
+    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) {
+                mailboxList = new MailboxList(Collections.<Mailbox>emptyList(), true);
           
+                return;
+            }
+            buf = ContentUtil.encode(body);
+            pos = 0;
+        }
+        ParserCursor cursor = new ParserCursor(pos, buf.length());
+        mailboxList = LenientAddressBuilder.DEFAULT.parseAddressList(buf, cursor).flatten();
+    }
+
+    public static final FieldParser<MailboxListField> PARSER = new FieldParser<MailboxListField>()
{
+
+        public MailboxListField parse(final Field rawField, final DecodeMonitor monitor)
{
+            return new MailboxListFieldLenientImpl(rawField, monitor);
+        }
+
+    };
+
+}

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

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

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

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/EntityBuilder.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/EntityBuilder.java?rev=1135968&r1=1135967&r2=1135968&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/EntityBuilder.java
(original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/EntityBuilder.java
Wed Jun 15 09:17:59 2011
@@ -31,7 +31,6 @@ import org.apache.james.mime4j.dom.Heade
 import org.apache.james.mime4j.dom.Message;
 import org.apache.james.mime4j.dom.Multipart;
 import org.apache.james.mime4j.dom.field.ParsedField;
-import org.apache.james.mime4j.field.DefaultFieldParser;
 import org.apache.james.mime4j.parser.ContentHandler;
 import org.apache.james.mime4j.stream.BodyDescriptor;
 import org.apache.james.mime4j.stream.Field;
@@ -47,25 +46,21 @@ import org.apache.james.mime4j.util.Byte
 class EntityBuilder implements ContentHandler {
 
     private final Entity entity;
-    private final Stack<Object> stack;
+    private final DecodeMonitor monitor;
     private final FieldParser<? extends ParsedField> fieldParser; 
     private final BodyFactory bodyFactory;
-    private final DecodeMonitor monitor;
-    
-    public EntityBuilder(Entity entity) {
-        this(entity, null, null, null);
-    }
+    private final Stack<Object> stack;
     
-    public EntityBuilder(
-            final Entity entity, 
+    EntityBuilder(
+            final Entity entity,
+            final DecodeMonitor monitor,
             final FieldParser<? extends ParsedField> fieldParser, 
-            final BodyFactory bodyFactory, 
-            final DecodeMonitor monitor) {
+            final BodyFactory bodyFactory) {
         this.entity = entity;
+        this.monitor = monitor;
+        this.fieldParser = fieldParser;
+        this.bodyFactory = bodyFactory;
         this.stack = new Stack<Object>();
-        this.fieldParser = fieldParser != null ? fieldParser : DefaultFieldParser.getParser();
-        this.bodyFactory = bodyFactory != null ? bodyFactory : new BasicBodyFactory();
-        this.monitor = monitor != null ? monitor : DecodeMonitor.SILENT;
     }
     
     private void expect(Class<?> c) {

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MimeBuilder.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MimeBuilder.java?rev=1135968&r1=1135967&r2=1135968&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MimeBuilder.java
(original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MimeBuilder.java
Wed Jun 15 09:17:59 2011
@@ -34,6 +34,7 @@ import org.apache.james.mime4j.dom.Multi
 import org.apache.james.mime4j.dom.SingleBody;
 import org.apache.james.mime4j.dom.field.ParsedField;
 import org.apache.james.mime4j.field.DefaultFieldParser;
+import org.apache.james.mime4j.field.LenientFieldParser;
 import org.apache.james.mime4j.parser.AbstractContentHandler;
 import org.apache.james.mime4j.parser.MimeStreamParser;
 import org.apache.james.mime4j.stream.Field;
@@ -261,13 +262,17 @@ public class MimeBuilder {
             final boolean flatMode) throws IOException, MimeIOException {
         try {
             MessageImpl message = new MessageImpl();
-            DecodeMonitor mon = monitor != null ? monitor : DecodeMonitor.SILENT;
+            MimeEntityConfig cfg = config != null ? config : new MimeEntityConfig();
+            boolean strict = cfg.isStrictParsing();
+            DecodeMonitor mon = monitor != null ? monitor : 
+                strict ? DecodeMonitor.STRICT : DecodeMonitor.SILENT;
             FieldParser<? extends ParsedField> fp = fieldParser != null ? fieldParser
: 
-                DefaultFieldParser.getParser();
+                strict ? DefaultFieldParser.getParser() : LenientFieldParser.getParser();
             MutableBodyDescriptorFactory bdf = bodyDescFactory != null ? bodyDescFactory
:
                 new MinimalBodyDescriptorFactory();
-            MimeStreamParser parser = new MimeStreamParser(config, mon, fp, bdf);
-            parser.setContentHandler(new EntityBuilder(message, fp, bodyFactory, mon));
+            BodyFactory bf = bodyFactory != null ? bodyFactory : new BasicBodyFactory();

+            MimeStreamParser parser = new MimeStreamParser(cfg, mon, fp, bdf);
+            parser.setContentHandler(new EntityBuilder(message, mon, fp, bf));
             parser.setContentDecoding(contentDecoding);
             if (flatMode) {
                 parser.setFlat();

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/SimpleContentHandler.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/SimpleContentHandler.java?rev=1135968&r1=1135967&r2=1135968&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/SimpleContentHandler.java
(original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/SimpleContentHandler.java
Wed Jun 15 09:17:59 2011
@@ -23,7 +23,7 @@ import org.apache.james.mime4j.MimeExcep
 import org.apache.james.mime4j.codec.DecodeMonitor;
 import org.apache.james.mime4j.dom.Header;
 import org.apache.james.mime4j.dom.field.ParsedField;
-import org.apache.james.mime4j.field.DefaultFieldParser;
+import org.apache.james.mime4j.field.LenientFieldParser;
 import org.apache.james.mime4j.parser.AbstractContentHandler;
 import org.apache.james.mime4j.stream.Field;
 import org.apache.james.mime4j.stream.FieldParser;
@@ -45,7 +45,7 @@ public abstract class SimpleContentHandl
             final FieldParser<? extends ParsedField> fieldParser, 
             final DecodeMonitor monitor) {
         super();
-        this.fieldParser = fieldParser != null ? fieldParser : DefaultFieldParser.getParser();
+        this.fieldParser = fieldParser != null ? fieldParser : LenientFieldParser.getParser();
         this.monitor = monitor != null ? monitor : DecodeMonitor.SILENT;
     }
     



Mime
View raw message