james-mime4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject svn commit: r895489 - in /james/mime4j/branches/cycleclean: core/src/main/java/org/apache/james/mime4j/field/address/parser/ core/src/main/java/org/apache/james/mime4j/field/impl/ core/src/main/java/org/apache/james/mime4j/parser/ core/src/test/java/or...
Date Sun, 03 Jan 2010 22:00:31 GMT
Author: bago
Date: Sun Jan  3 22:00:28 2010
New Revision: 895489

URL: http://svn.apache.org/viewvc?rev=895489&view=rev
Log:
Changed AddressBuilder.methods to throw ParseException instead of IllegalStateException.
Moved DecodeMonitor usage up to parser and field.*.parser methods (MIME4J-158)
(Also including some minor change like MessageImpl to Message references).

Added:
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/LoggingMonitor.java   (with props)
Modified:
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/address/parser/AddressBuilder.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/address/parser/Builder.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/AbstractField.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/AddressListFieldImpl.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/ContentDispositionFieldImpl.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/ContentTransferEncodingFieldImpl.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/ContentTypeFieldImpl.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/DateTimeFieldImpl.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/DefaultFieldParser.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/DelegatingFieldParser.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/FieldParser.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/Fields.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/MailboxFieldImpl.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/MailboxListFieldImpl.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/UnstructuredFieldImpl.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/parser/AbstractEntity.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/parser/BasicMimeTokenStream.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/parser/EntityStateMachine.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/parser/MimeEntity.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/parser/RawEntity.java
    james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/field/address/AddressTest.java
    james/mime4j/branches/cycleclean/examples/src/main/java/org/apache/james/mime4j/samples/dom/TextPlainMessage.java
    james/mime4j/branches/cycleclean/examples/src/main/java/org/apache/james/mime4j/samples/transform/TransformMessage.java

Modified: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/address/parser/AddressBuilder.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/address/parser/AddressBuilder.java?rev=895489&r1=895488&r2=895489&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/address/parser/AddressBuilder.java (original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/address/parser/AddressBuilder.java Sun Jan  3 22:00:28 2010
@@ -21,6 +21,7 @@
 
 import java.io.StringReader;
 
+import org.apache.james.mime4j.codec.DecodeMonitor;
 import org.apache.james.mime4j.field.address.Address;
 import org.apache.james.mime4j.field.address.AddressList;
 import org.apache.james.mime4j.field.address.Group;
@@ -33,18 +34,18 @@
      * 
      * @param rawAddressString
      *            string to parse.
+     * @param monitor the DecodeMonitor to be used while parsing/decoding
      * @return an <code>Address</code> object for the specified string.
-     * @throws IllegalArgumentException
-     *             if the raw string does not represent a single address.
+     * @throws ParseException if the raw string does not represent a single address.
      */
-    public static Address parseAddress(String rawAddressString) {
+    public static Address parseAddress(String rawAddressString, DecodeMonitor monitor) throws ParseException {
         AddressListParser parser = new AddressListParser(new StringReader(
                 rawAddressString));
-        try {
-            return Builder.getInstance().buildAddress(parser.parseAddress());
-        } catch (ParseException e) {
-            throw new IllegalArgumentException(e);
-        }
+        return Builder.getInstance().buildAddress(parser.parseAddress(), monitor);
+    }
+
+    public static Address parseAddress(String rawAddressString) throws ParseException {
+        return parseAddress(rawAddressString, DecodeMonitor.STRICT);
     }
 
     /**
@@ -52,14 +53,22 @@
      * Sender, or Reply-To header.
      * 
      * The string MUST be unfolded already.
+     * @param monitor the DecodeMonitor to be used while parsing/decoding
      */
-    public static AddressList parseAddressList(String rawAddressList)
+    public static AddressList parseAddressList(String rawAddressList, DecodeMonitor monitor)
             throws ParseException {
         AddressListParser parser = new AddressListParser(new StringReader(
                 rawAddressList));
-        return Builder.getInstance().buildAddressList(parser.parseAddressList());
+        try {
+            return Builder.getInstance().buildAddressList(parser.parseAddressList(), monitor);
+        } catch (RuntimeException e) {
+            throw new ParseException(e.getMessage());
+        }
     }
 
+    public static AddressList parseAddressList(String rawAddressList) throws ParseException {
+        return parseAddressList(rawAddressList, DecodeMonitor.STRICT);
+    }
 
     /**
      * Test console for AddressList
@@ -76,7 +85,7 @@
                     System.out.println("Goodbye.");
                     return;
                 }
-                AddressList list = AddressBuilder.parseAddressList(line);
+                AddressList list = AddressBuilder.parseAddressList(line, DecodeMonitor.STRICT);
                 list.print();
             } catch (Exception e) {
                 e.printStackTrace();
@@ -90,19 +99,20 @@
      * 
      * @param rawMailboxString
      *            string to parse.
+     * @param monitor the DecodeMonitor to be used while parsing/decoding.
      * @return a <code>Mailbox</code> object for the specified string.
-     * @throws IllegalArgumentException
+     * @throws ParseException
      *             if the raw string does not represent a single mailbox
      *             address.
      */
-    public static Mailbox parseMailbox(String rawMailboxString) {
+    public static Mailbox parseMailbox(String rawMailboxString, DecodeMonitor monitor) throws ParseException {
         AddressListParser parser = new AddressListParser(new StringReader(
                 rawMailboxString));
-        try {
-            return Builder.getInstance().buildMailbox(parser.parseMailbox());
-        } catch (ParseException e) {
-            throw new IllegalArgumentException(e);
-        }
+        return Builder.getInstance().buildMailbox(parser.parseMailbox(), monitor);
+    }
+
+    public static Mailbox parseMailbox(String rawMailboxString) throws ParseException {
+        return parseMailbox(rawMailboxString, DecodeMonitor.STRICT);
     }
 
     /**
@@ -111,15 +121,19 @@
      * @param rawGroupString
      *            string to parse.
      * @return a <code>Group</code> object for the specified string.
-     * @throws IllegalArgumentException
+     * @throws ParseException
      *             if the raw string does not represent a single group address.
      */
-    public static Group parseGroup(String rawGroupString) {
-        Address address = parseAddress(rawGroupString);
+    public static Group parseGroup(String rawGroupString, DecodeMonitor monitor) throws ParseException {
+        Address address = parseAddress(rawGroupString, monitor);
         if (!(address instanceof Group))
-            throw new IllegalArgumentException("Not a group address");
+            throw new ParseException("Not a group address");
     
         return (Group) address;
     }
 
+    public static Group parseGroup(String rawGroupString) throws ParseException {
+        return parseGroup(rawGroupString, DecodeMonitor.STRICT);
+    }
+
 }

Modified: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/address/parser/Builder.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/address/parser/Builder.java?rev=895489&r1=895488&r2=895489&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/address/parser/Builder.java (original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/address/parser/Builder.java Sun Jan  3 22:00:28 2010
@@ -19,30 +19,17 @@
 
 package org.apache.james.mime4j.field.address.parser;
 
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.james.mime4j.codec.DecodeMonitor;
 import org.apache.james.mime4j.codec.DecoderUtil;
 import org.apache.james.mime4j.field.address.Address;
 import org.apache.james.mime4j.field.address.AddressList;
 import org.apache.james.mime4j.field.address.DomainList;
 import org.apache.james.mime4j.field.address.Mailbox;
 import org.apache.james.mime4j.field.address.MailboxList;
-import org.apache.james.mime4j.field.address.parser.ASTaddr_spec;
-import org.apache.james.mime4j.field.address.parser.ASTaddress;
-import org.apache.james.mime4j.field.address.parser.ASTaddress_list;
-import org.apache.james.mime4j.field.address.parser.ASTangle_addr;
-import org.apache.james.mime4j.field.address.parser.ASTdomain;
-import org.apache.james.mime4j.field.address.parser.ASTgroup_body;
-import org.apache.james.mime4j.field.address.parser.ASTlocal_part;
-import org.apache.james.mime4j.field.address.parser.ASTmailbox;
-import org.apache.james.mime4j.field.address.parser.ASTname_addr;
-import org.apache.james.mime4j.field.address.parser.ASTphrase;
-import org.apache.james.mime4j.field.address.parser.ASTroute;
-import org.apache.james.mime4j.field.address.parser.Node;
-import org.apache.james.mime4j.field.address.parser.SimpleNode;
-import org.apache.james.mime4j.field.address.parser.Token;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
 
 /**
  * Transforms the JJTree-generated abstract syntax tree into a graph of
@@ -56,17 +43,17 @@
         return singleton;
     }
 
-    public AddressList buildAddressList(ASTaddress_list node) {
+    public AddressList buildAddressList(ASTaddress_list node, DecodeMonitor monitor) throws ParseException {
         List<Address> list = new ArrayList<Address>();
         for (int i = 0; i < node.jjtGetNumChildren(); i++) {
             ASTaddress childNode = (ASTaddress) node.jjtGetChild(i);
-            Address address = buildAddress(childNode);
+            Address address = buildAddress(childNode, monitor);
             list.add(address);
         }
         return new AddressList(list, true);
     }
 
-    public Address buildAddress(ASTaddress node) {
+    public Address buildAddress(ASTaddress node, DecodeMonitor monitor) throws ParseException {
         ChildNodeIterator it = new ChildNodeIterator(node);
         Node n = it.next();
         if (n instanceof ASTaddr_spec) {
@@ -77,34 +64,38 @@
             String name = buildString((ASTphrase) n, false);
             Node n2 = it.next();
             if (n2 instanceof ASTgroup_body) {
-                return new GroupImpl(name, buildGroupBody((ASTgroup_body) n2));
+                return new GroupImpl(name, buildGroupBody((ASTgroup_body) n2, monitor));
             } else if (n2 instanceof ASTangle_addr) {
-                name = DecoderUtil.decodeEncodedWords(name);
+                try {
+                    name = DecoderUtil.decodeEncodedWords(name, monitor);
+                } catch (IllegalArgumentException e) {
+                    throw new ParseException(e.getMessage());
+                }
                 Mailbox mb = buildAngleAddr((ASTangle_addr) n2);
                 return new MailboxImpl(name, mb.getRoute(), mb.getLocalPart(),
                         mb.getDomain());
             } else {
-                throw new IllegalStateException();
+                throw new ParseException();
             }
         } else {
-            throw new IllegalStateException();
+            throw new ParseException();
         }
     }
 
-    private MailboxList buildGroupBody(ASTgroup_body node) {
+    private MailboxList buildGroupBody(ASTgroup_body node, DecodeMonitor monitor) throws ParseException {
         List<Mailbox> results = new ArrayList<Mailbox>();
         ChildNodeIterator it = new ChildNodeIterator(node);
         while (it.hasNext()) {
             Node n = it.next();
             if (n instanceof ASTmailbox)
-                results.add(buildMailbox((ASTmailbox) n));
+                results.add(buildMailbox((ASTmailbox) n, monitor));
             else
-                throw new IllegalStateException();
+                throw new ParseException();
         }
         return new MailboxList(results, true);
     }
 
-    public Mailbox buildMailbox(ASTmailbox node) {
+    public Mailbox buildMailbox(ASTmailbox node, DecodeMonitor monitor) throws ParseException {
         ChildNodeIterator it = new ChildNodeIterator(node);
         Node n = it.next();
         if (n instanceof ASTaddr_spec) {
@@ -112,34 +103,38 @@
         } else if (n instanceof ASTangle_addr) {
             return buildAngleAddr((ASTangle_addr) n);
         } else if (n instanceof ASTname_addr) {
-            return buildNameAddr((ASTname_addr) n);
+            return buildNameAddr((ASTname_addr) n, monitor);
         } else {
-            throw new IllegalStateException();
+            throw new ParseException();
         }
     }
 
-    private Mailbox buildNameAddr(ASTname_addr node) {
+    private Mailbox buildNameAddr(ASTname_addr node, DecodeMonitor monitor) throws ParseException {
         ChildNodeIterator it = new ChildNodeIterator(node);
         Node n = it.next();
         String name;
         if (n instanceof ASTphrase) {
             name = buildString((ASTphrase) n, false);
         } else {
-            throw new IllegalStateException();
+            throw new ParseException();
         }
 
         n = it.next();
         if (n instanceof ASTangle_addr) {
-            name = DecoderUtil.decodeEncodedWords(name);
+            try {
+                name = DecoderUtil.decodeEncodedWords(name, monitor);
+            } catch (IllegalArgumentException e) {
+                throw new ParseException(e.getMessage());
+            }
             Mailbox mb = buildAngleAddr((ASTangle_addr) n);
             return new MailboxImpl(name, mb.getRoute(), mb.getLocalPart(),
                     mb.getDomain());
         } else {
-            throw new IllegalStateException();
+            throw new ParseException();
         }
     }
 
-    private Mailbox buildAngleAddr(ASTangle_addr node) {
+    private Mailbox buildAngleAddr(ASTangle_addr node) throws ParseException {
         ChildNodeIterator it = new ChildNodeIterator(node);
         DomainList route = null;
         Node n = it.next();
@@ -150,15 +145,15 @@
             // do nothing
         }
         else
-            throw new IllegalStateException();
+            throw new ParseException();
 
         if (n instanceof ASTaddr_spec)
             return buildAddrSpec(route, (ASTaddr_spec) n);
         else
-            throw new IllegalStateException();
+            throw new ParseException();
     }
 
-    private DomainList buildRoute(ASTroute node) {
+    private DomainList buildRoute(ASTroute node) throws ParseException {
         List<String> results = new ArrayList<String>(node.jjtGetNumChildren());
         ChildNodeIterator it = new ChildNodeIterator(node);
         while (it.hasNext()) {
@@ -166,7 +161,7 @@
             if (n instanceof ASTdomain)
                 results.add(buildString((ASTdomain) n, true));
             else
-                throw new IllegalStateException();
+                throw new ParseException();
         }
         return new DomainList(results, true);
     }

Modified: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/AbstractField.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/AbstractField.java?rev=895489&r1=895488&r2=895489&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/AbstractField.java (original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/AbstractField.java Sun Jan  3 22:00:28 2010
@@ -22,6 +22,7 @@
 import java.io.IOException;
 import java.io.OutputStream;
 
+import org.apache.james.mime4j.codec.DecodeMonitor;
 import org.apache.james.mime4j.field.ParseException;
 import org.apache.james.mime4j.field.ParsedField;
 import org.apache.james.mime4j.util.ByteSequence;
@@ -34,11 +35,13 @@
     private final String name;
     private final String body;
     private final ByteSequence raw;
+    protected DecodeMonitor monitor;
     
-    protected AbstractField(final String name, final String body, final ByteSequence raw) {
+    protected AbstractField(final String name, final String body, final ByteSequence raw, DecodeMonitor monitor) {
         this.name = name;
         this.body = body;
         this.raw = raw;
+        this.monitor = monitor;
     }
     
     /**

Modified: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/AddressListFieldImpl.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/AddressListFieldImpl.java?rev=895489&r1=895488&r2=895489&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/AddressListFieldImpl.java (original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/AddressListFieldImpl.java Sun Jan  3 22:00:28 2010
@@ -19,8 +19,7 @@
 
 package org.apache.james.mime4j.field.impl;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.apache.james.mime4j.codec.DecodeMonitor;
 import org.apache.james.mime4j.field.address.AddressList;
 import org.apache.james.mime4j.field.address.parser.AddressBuilder;
 import org.apache.james.mime4j.field.address.parser.ParseException;
@@ -30,15 +29,14 @@
  * Address list field such as <code>To</code> or <code>Reply-To</code>.
  */
 public class AddressListFieldImpl extends AbstractField implements org.apache.james.mime4j.field.AddressListField {
-    private static Log log = LogFactory.getLog(AddressListFieldImpl.class);
 
     private boolean parsed = false;
 
     private AddressList addressList;
     private ParseException parseException;
 
-    AddressListFieldImpl(String name, String body, ByteSequence raw) {
-        super(name, body, raw);
+    AddressListFieldImpl(String name, String body, ByteSequence raw, DecodeMonitor monitor) {
+        super(name, body, raw, monitor);
     }
 
     /**
@@ -66,11 +64,8 @@
         String body = getBody();
 
         try {
-            addressList = AddressBuilder.parseAddressList(body);
+            addressList = AddressBuilder.parseAddressList(body, monitor);
         } catch (ParseException e) {
-            if (log.isDebugEnabled()) {
-                log.debug("Parsing value '" + body + "': " + e.getMessage());
-            }
             parseException = e;
         }
 
@@ -79,8 +74,8 @@
 
     static final FieldParser<AddressListFieldImpl> PARSER = new FieldParser<AddressListFieldImpl>() {
         public AddressListFieldImpl parse(final String name, final String body,
-                final ByteSequence raw) {
-            return new AddressListFieldImpl(name, body, raw);
+                final ByteSequence raw, DecodeMonitor monitor) {
+            return new AddressListFieldImpl(name, body, raw, monitor);
         }
     };
 }

Modified: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/ContentDispositionFieldImpl.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/ContentDispositionFieldImpl.java?rev=895489&r1=895488&r2=895489&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/ContentDispositionFieldImpl.java (original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/ContentDispositionFieldImpl.java Sun Jan  3 22:00:28 2010
@@ -27,8 +27,7 @@
 import java.util.Locale;
 import java.util.Map;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.apache.james.mime4j.codec.DecodeMonitor;
 import org.apache.james.mime4j.field.contentdisposition.parser.ContentDispositionParser;
 import org.apache.james.mime4j.field.contentdisposition.parser.ParseException;
 import org.apache.james.mime4j.field.contentdisposition.parser.TokenMgrError;
@@ -39,7 +38,6 @@
  * Represents a <code>Content-Disposition</code> field.
  */
 public class ContentDispositionFieldImpl extends AbstractField implements org.apache.james.mime4j.field.ContentDispositionField {
-    private static Log log = LogFactory.getLog(ContentDispositionFieldImpl.class);
 
     private boolean parsed = false;
 
@@ -56,8 +54,8 @@
     private boolean readDateParsed;
     private Date readDate;
 
-    ContentDispositionFieldImpl(String name, String body, ByteSequence raw) {
-        super(name, body, raw);
+    ContentDispositionFieldImpl(String name, String body, ByteSequence raw, DecodeMonitor monitor) {
+        super(name, body, raw, monitor);
     }
 
     /**
@@ -194,9 +192,7 @@
     private Date parseDate(String paramName) {
         String value = getParameter(paramName);
         if (value == null) {
-            if (log.isDebugEnabled()) {
-                log.debug("Parsing " + paramName + " null");
-            }
+            monitor.warn("Parsing " + paramName + " null", "returning null");
             return null;
         }
 
@@ -204,16 +200,12 @@
             return new DateTimeParser(new StringReader(value)).parseAll()
                     .getDate();
         } catch (org.apache.james.mime4j.field.datetime.parser.ParseException e) {
-            if (log.isDebugEnabled()) {
-                log.debug("Parsing " + paramName + " '" + value + "': "
-                        + e.getMessage());
-            }
+            monitor.warn("Parsing " + paramName + " '" + value + "': "
+                    + e.getMessage(), "returning null");
             return null;
         } catch (org.apache.james.mime4j.field.datetime.parser.TokenMgrError e) {
-            if (log.isDebugEnabled()) {
-                log.debug("Parsing " + paramName + " '" + value + "': "
-                        + e.getMessage());
-            }
+            monitor.warn("Parsing " + paramName + " '" + value + "': "
+                    + e.getMessage(), "returning null");
             return null;
         }
     }
@@ -226,14 +218,8 @@
         try {
             parser.parseAll();
         } catch (ParseException e) {
-            if (log.isDebugEnabled()) {
-                log.debug("Parsing value '" + body + "': " + e.getMessage());
-            }
             parseException = e;
         } catch (TokenMgrError e) {
-            if (log.isDebugEnabled()) {
-                log.debug("Parsing value '" + body + "': " + e.getMessage());
-            }
             parseException = new ParseException(e.getMessage());
         }
 
@@ -260,8 +246,8 @@
 
     static final FieldParser<ContentDispositionFieldImpl> PARSER = new FieldParser<ContentDispositionFieldImpl>() {
         public ContentDispositionFieldImpl parse(final String name, final String body,
-                final ByteSequence raw) {
-            return new ContentDispositionFieldImpl(name, body, raw);
+                final ByteSequence raw, DecodeMonitor monitor) {
+            return new ContentDispositionFieldImpl(name, body, raw, monitor);
         }
     };
 }

Modified: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/ContentTransferEncodingFieldImpl.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/ContentTransferEncodingFieldImpl.java?rev=895489&r1=895488&r2=895489&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/ContentTransferEncodingFieldImpl.java (original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/ContentTransferEncodingFieldImpl.java Sun Jan  3 22:00:28 2010
@@ -19,6 +19,7 @@
 
 package org.apache.james.mime4j.field.impl;
 
+import org.apache.james.mime4j.codec.DecodeMonitor;
 import org.apache.james.mime4j.field.ContentTransferEncodingField;
 import org.apache.james.mime4j.util.ByteSequence;
 import org.apache.james.mime4j.util.MimeUtil;
@@ -29,8 +30,8 @@
 public class ContentTransferEncodingFieldImpl extends AbstractField implements ContentTransferEncodingField {
     private String encoding;
 
-    ContentTransferEncodingFieldImpl(String name, String body, ByteSequence raw) {
-        super(name, body, raw);
+    ContentTransferEncodingFieldImpl(String name, String body, ByteSequence raw, DecodeMonitor monitor) {
+        super(name, body, raw, monitor);
         encoding = body.trim().toLowerCase();
     }
 
@@ -57,8 +58,8 @@
 
     static final FieldParser<ContentTransferEncodingFieldImpl> PARSER = new FieldParser<ContentTransferEncodingFieldImpl>() {
         public ContentTransferEncodingFieldImpl parse(final String name, final String body,
-                final ByteSequence raw) {
-            return new ContentTransferEncodingFieldImpl(name, body, raw);
+                final ByteSequence raw, DecodeMonitor monitor) {
+            return new ContentTransferEncodingFieldImpl(name, body, raw, monitor);
         }
     };
 }

Modified: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/ContentTypeFieldImpl.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/ContentTypeFieldImpl.java?rev=895489&r1=895488&r2=895489&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/ContentTypeFieldImpl.java (original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/ContentTypeFieldImpl.java Sun Jan  3 22:00:28 2010
@@ -25,8 +25,7 @@
 import java.util.List;
 import java.util.Map;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.apache.james.mime4j.codec.DecodeMonitor;
 import org.apache.james.mime4j.field.ContentTypeField;
 import org.apache.james.mime4j.field.contenttype.parser.ContentTypeParser;
 import org.apache.james.mime4j.field.contenttype.parser.ParseException;
@@ -37,16 +36,14 @@
  * Represents a <code>Content-Type</code> field.
  */
 public class ContentTypeFieldImpl extends AbstractField implements ContentTypeField {
-    private static Log log = LogFactory.getLog(ContentTypeFieldImpl.class);
-
     private boolean parsed = false;
 
     private String mimeType = "";
     private Map<String, String> parameters = new HashMap<String, String>();
     private ParseException parseException;
 
-    ContentTypeFieldImpl(String name, String body, ByteSequence raw) {
-        super(name, body, raw);
+    ContentTypeFieldImpl(String name, String body, ByteSequence raw, DecodeMonitor monitor) {
+        super(name, body, raw, monitor);
     }
 
     /**
@@ -175,14 +172,8 @@
         try {
             parser.parseAll();
         } catch (ParseException e) {
-            if (log.isDebugEnabled()) {
-                log.debug("Parsing value '" + body + "': " + e.getMessage());
-            }
             parseException = e;
         } catch (TokenMgrError e) {
-            if (log.isDebugEnabled()) {
-                log.debug("Parsing value '" + body + "': " + e.getMessage());
-            }
             parseException = new ParseException(e.getMessage());
         }
 
@@ -210,8 +201,8 @@
 
     static final FieldParser<ContentTypeFieldImpl> PARSER = new FieldParser<ContentTypeFieldImpl>() {
         public ContentTypeFieldImpl parse(final String name, final String body,
-                final ByteSequence raw) {
-            return new ContentTypeFieldImpl(name, body, raw);
+                final ByteSequence raw, DecodeMonitor monitor) {
+            return new ContentTypeFieldImpl(name, body, raw, monitor);
         }
     };
 }

Modified: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/DateTimeFieldImpl.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/DateTimeFieldImpl.java?rev=895489&r1=895488&r2=895489&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/DateTimeFieldImpl.java (original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/DateTimeFieldImpl.java Sun Jan  3 22:00:28 2010
@@ -22,8 +22,7 @@
 import java.io.StringReader;
 import java.util.Date;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.apache.james.mime4j.codec.DecodeMonitor;
 import org.apache.james.mime4j.field.datetime.parser.DateTimeParser;
 import org.apache.james.mime4j.field.datetime.parser.ParseException;
 import org.apache.james.mime4j.field.datetime.parser.TokenMgrError;
@@ -33,15 +32,13 @@
  * Date-time field such as <code>Date</code> or <code>Resent-Date</code>.
  */
 public class DateTimeFieldImpl extends AbstractField implements org.apache.james.mime4j.field.DateTimeField {
-    private static Log log = LogFactory.getLog(DateTimeFieldImpl.class);
-
     private boolean parsed = false;
 
     private Date date;
     private ParseException parseException;
 
-    DateTimeFieldImpl(String name, String body, ByteSequence raw) {
-        super(name, body, raw);
+    DateTimeFieldImpl(String name, String body, ByteSequence raw, DecodeMonitor monitor) {
+        super(name, body, raw, monitor);
     }
 
     /**
@@ -72,14 +69,8 @@
             date = new DateTimeParser(new StringReader(body)).parseAll()
                     .getDate();
         } catch (ParseException e) {
-            if (log.isDebugEnabled()) {
-                log.debug("Parsing value '" + body + "': " + e.getMessage());
-            }
             parseException = e;
         } catch (TokenMgrError e) {
-            if (log.isDebugEnabled()) {
-                log.debug("Parsing value '" + body + "': " + e.getMessage());
-            }
             parseException = new ParseException(e.getMessage());
         }
 
@@ -88,8 +79,8 @@
 
     static final FieldParser<DateTimeFieldImpl> PARSER = new FieldParser<DateTimeFieldImpl>() {
         public DateTimeFieldImpl parse(final String name, final String body,
-                final ByteSequence raw) {
-            return new DateTimeFieldImpl(name, body, raw);
+                final ByteSequence raw, DecodeMonitor monitor) {
+            return new DateTimeFieldImpl(name, body, raw, monitor);
         }
     };
 }

Modified: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/DefaultFieldParser.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/DefaultFieldParser.java?rev=895489&r1=895488&r2=895489&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/DefaultFieldParser.java (original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/DefaultFieldParser.java Sun Jan  3 22:00:28 2010
@@ -61,7 +61,7 @@
      */
     public static ParsedField parse(final ByteSequence raw) throws MimeException {
     	RawField rawField = new RawField(raw);
-        return PARSER.parse(rawField.getName(), rawField.getBody(), raw);
+        return PARSER.parse(rawField.getName(), rawField.getBody(), raw, LoggingMonitor.MONITOR);
     }
 
 

Modified: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/DelegatingFieldParser.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/DelegatingFieldParser.java?rev=895489&r1=895488&r2=895489&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/DelegatingFieldParser.java (original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/DelegatingFieldParser.java Sun Jan  3 22:00:28 2010
@@ -22,6 +22,7 @@
 import java.util.HashMap;
 import java.util.Map;
 
+import org.apache.james.mime4j.codec.DecodeMonitor;
 import org.apache.james.mime4j.field.ParsedField;
 import org.apache.james.mime4j.field.impl.UnstructuredFieldImpl;
 import org.apache.james.mime4j.util.ByteSequence;
@@ -48,8 +49,8 @@
         return field;
     }
     
-    public ParsedField parse(final String name, final String body, final ByteSequence raw) {
+    public ParsedField parse(final String name, final String body, final ByteSequence raw, DecodeMonitor monitor) {
         final FieldParser<? extends ParsedField> parser = getParser(name);
-        return parser.parse(name, body, raw);
+        return parser.parse(name, body, raw, monitor);
     }
 }

Modified: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/FieldParser.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/FieldParser.java?rev=895489&r1=895488&r2=895489&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/FieldParser.java (original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/FieldParser.java Sun Jan  3 22:00:28 2010
@@ -19,11 +19,12 @@
 
 package org.apache.james.mime4j.field.impl;
 
+import org.apache.james.mime4j.codec.DecodeMonitor;
 import org.apache.james.mime4j.field.ParsedField;
 import org.apache.james.mime4j.util.ByteSequence;
 
 public interface FieldParser<T extends ParsedField> {
     
-    T parse(final String name, final String body, final ByteSequence raw);
+    T parse(final String name, final String body, final ByteSequence raw, DecodeMonitor monitor);
     
 }

Modified: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/Fields.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/Fields.java?rev=895489&r1=895488&r2=895489&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/Fields.java (original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/Fields.java Sun Jan  3 22:00:28 2010
@@ -614,7 +614,7 @@
     private static <F extends ParsedField> F parse(FieldParser<F> parser,
             String fieldName, String fieldBody) {
     	RawField rawField = new RawField(fieldName, fieldBody);
-        return parser.parse(rawField.getName(), rawField.getBody(), rawField.getRaw());
+        return parser.parse(rawField.getName(), rawField.getBody(), rawField.getRaw(), LoggingMonitor.MONITOR);
     }
 
     private static String encodeAddresses(Iterable<? extends Address> addresses) {

Added: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/LoggingMonitor.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/LoggingMonitor.java?rev=895489&view=auto
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/LoggingMonitor.java (added)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/LoggingMonitor.java Sun Jan  3 22:00:28 2010
@@ -0,0 +1,28 @@
+/**
+ * 
+ */
+package org.apache.james.mime4j.field.impl;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.james.mime4j.codec.DecodeMonitor;
+
+public final class LoggingMonitor extends DecodeMonitor {
+    private static Log log = LogFactory.getLog(LoggingMonitor.class);
+    
+    public static DecodeMonitor MONITOR = new LoggingMonitor();
+
+    @Override
+    public boolean warn(String error, String dropDesc) {
+        if (dropDesc != null) {
+            log.warn(error+"; "+dropDesc);
+        } else {
+            log.warn(error);
+        }
+        return false;
+    }
+    
+    public boolean isListening() {
+        return true;
+    }
+}
\ No newline at end of file

Propchange: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/LoggingMonitor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/LoggingMonitor.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/MailboxFieldImpl.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/MailboxFieldImpl.java?rev=895489&r1=895488&r2=895489&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/MailboxFieldImpl.java (original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/MailboxFieldImpl.java Sun Jan  3 22:00:28 2010
@@ -19,8 +19,7 @@
 
 package org.apache.james.mime4j.field.impl;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.apache.james.mime4j.codec.DecodeMonitor;
 import org.apache.james.mime4j.field.address.Mailbox;
 import org.apache.james.mime4j.field.address.MailboxList;
 import org.apache.james.mime4j.field.address.parser.AddressBuilder;
@@ -31,15 +30,13 @@
  * Mailbox field such as <code>Sender</code> or <code>Resent-Sender</code>.
  */
 public class MailboxFieldImpl extends AbstractField implements org.apache.james.mime4j.field.MailboxField {
-    private static Log log = LogFactory.getLog(MailboxFieldImpl.class);
-
     private boolean parsed = false;
 
     private Mailbox mailbox;
     private ParseException parseException;
 
-    MailboxFieldImpl(final String name, final String body, final ByteSequence raw) {
-        super(name, body, raw);
+    MailboxFieldImpl(final String name, final String body, final ByteSequence raw, DecodeMonitor monitor) {
+        super(name, body, raw, monitor);
     }
 
     /**
@@ -67,14 +64,11 @@
         String body = getBody();
 
         try {
-            MailboxList mailboxList = AddressBuilder.parseAddressList(body).flatten();
+            MailboxList mailboxList = AddressBuilder.parseAddressList(body, monitor).flatten();
             if (mailboxList.size() > 0) {
                 mailbox = mailboxList.get(0);
             }
         } catch (ParseException e) {
-            if (log.isDebugEnabled()) {
-                log.debug("Parsing value '" + body + "': " + e.getMessage());
-            }
             parseException = e;
         }
 
@@ -83,8 +77,8 @@
 
     static final FieldParser<MailboxFieldImpl> PARSER = new FieldParser<MailboxFieldImpl>() {
         public MailboxFieldImpl parse(final String name, final String body,
-                final ByteSequence raw) {
-            return new MailboxFieldImpl(name, body, raw);
+                final ByteSequence raw, DecodeMonitor monitor) {
+            return new MailboxFieldImpl(name, body, raw, monitor);
         }
     };
 }

Modified: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/MailboxListFieldImpl.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/MailboxListFieldImpl.java?rev=895489&r1=895488&r2=895489&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/MailboxListFieldImpl.java (original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/MailboxListFieldImpl.java Sun Jan  3 22:00:28 2010
@@ -19,8 +19,7 @@
 
 package org.apache.james.mime4j.field.impl;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.apache.james.mime4j.codec.DecodeMonitor;
 import org.apache.james.mime4j.field.address.MailboxList;
 import org.apache.james.mime4j.field.address.parser.AddressBuilder;
 import org.apache.james.mime4j.field.address.parser.ParseException;
@@ -30,15 +29,13 @@
  * Mailbox-list field such as <code>From</code> or <code>Resent-From</code>.
  */
 public class MailboxListFieldImpl extends AbstractField implements org.apache.james.mime4j.field.MailboxListField {
-    private static Log log = LogFactory.getLog(MailboxListFieldImpl.class);
-
     private boolean parsed = false;
 
     private MailboxList mailboxList;
     private ParseException parseException;
 
-    MailboxListFieldImpl(final String name, final String body, final ByteSequence raw) {
-        super(name, body, raw);
+    MailboxListFieldImpl(final String name, final String body, final ByteSequence raw, DecodeMonitor monitor) {
+        super(name, body, raw, monitor);
     }
 
     /**
@@ -66,11 +63,8 @@
         String body = getBody();
 
         try {
-            mailboxList = AddressBuilder.parseAddressList(body).flatten();
+            mailboxList = AddressBuilder.parseAddressList(body, monitor).flatten();
         } catch (ParseException e) {
-            if (log.isDebugEnabled()) {
-                log.debug("Parsing value '" + body + "': " + e.getMessage());
-            }
             parseException = e;
         }
 
@@ -79,8 +73,8 @@
 
     static final FieldParser<MailboxListFieldImpl> PARSER = new FieldParser<MailboxListFieldImpl>() {
         public MailboxListFieldImpl parse(final String name, final String body,
-                final ByteSequence raw) {
-            return new MailboxListFieldImpl(name, body, raw);
+                final ByteSequence raw, DecodeMonitor monitor) {
+            return new MailboxListFieldImpl(name, body, raw, monitor);
         }
     };
 }

Modified: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/UnstructuredFieldImpl.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/UnstructuredFieldImpl.java?rev=895489&r1=895488&r2=895489&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/UnstructuredFieldImpl.java (original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/UnstructuredFieldImpl.java Sun Jan  3 22:00:28 2010
@@ -19,6 +19,7 @@
 
 package org.apache.james.mime4j.field.impl;
 
+import org.apache.james.mime4j.codec.DecodeMonitor;
 import org.apache.james.mime4j.codec.DecoderUtil;
 import org.apache.james.mime4j.util.ByteSequence;
 
@@ -30,8 +31,8 @@
 
     private String value;
 
-    UnstructuredFieldImpl(String name, String body, ByteSequence raw) {
-        super(name, body, raw);
+    UnstructuredFieldImpl(String name, String body, ByteSequence raw, DecodeMonitor monitor) {
+        super(name, body, raw, monitor);
     }
 
     /**
@@ -47,15 +48,15 @@
     private void parse() {
         String body = getBody();
 
-        value = DecoderUtil.decodeEncodedWords(body);
+        value = DecoderUtil.decodeEncodedWords(body, monitor);
 
         parsed = true;
     }
 
     static final FieldParser<UnstructuredFieldImpl> PARSER = new FieldParser<UnstructuredFieldImpl>() {
         public UnstructuredFieldImpl parse(final String name, final String body,
-                final ByteSequence raw) {
-            return new UnstructuredFieldImpl(name, body, raw);
+                final ByteSequence raw, DecodeMonitor monitor) {
+            return new UnstructuredFieldImpl(name, body, raw, monitor);
         }
     };
 }

Modified: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/parser/AbstractEntity.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/parser/AbstractEntity.java?rev=895489&r1=895488&r2=895489&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/parser/AbstractEntity.java (original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/parser/AbstractEntity.java Sun Jan  3 22:00:28 2010
@@ -21,9 +21,8 @@
 
 import java.io.IOException;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.james.mime4j.MimeException;
+import org.apache.james.mime4j.codec.DecodeMonitor;
 import org.apache.james.mime4j.io.LineReaderInputStream;
 import org.apache.james.mime4j.io.MaxHeaderLengthLimitException;
 import org.apache.james.mime4j.io.MaxHeaderLimitException;
@@ -36,8 +35,6 @@
  */
 public abstract class AbstractEntity implements EntityStateMachine {
 
-    protected final Log log;
-    
     protected final int startState;
     protected final int endState;
     protected final MimeEntityConfig config;
@@ -51,6 +48,7 @@
     private RawField field;
     private boolean endOfHeader;
     private int headerCount;
+    protected final DecodeMonitor monitor;
 
     /**
      * Internal state, not exposed.
@@ -65,8 +63,8 @@
             MutableBodyDescriptor body,
             int startState, 
             int endState,
-            MimeEntityConfig config) {
-        this.log = LogFactory.getLog(getClass());        
+            MimeEntityConfig config,
+            DecodeMonitor monitor) {
         this.state = startState;
         this.startState = startState;
         this.endState = endState;
@@ -76,6 +74,7 @@
         this.lineCount = 0;
         this.endOfHeader = false;
         this.headerCount = 0;
+        this.monitor = monitor;
     }
 
     public int getState() {
@@ -171,7 +170,7 @@
             try {
             	field = new RawField(fieldbuf);
             	if (field.isObsoleteSyntax()) {
-            		warn(Event.OBSOLETE_HEADER);
+            		monitor(Event.OBSOLETE_HEADER);
             	}
                 body.addField(field);
                 return true;
@@ -236,10 +235,11 @@
      * @throws IOException subclasses may elect to throw this exception
      */
     protected void monitor(Event event) throws MimeException, IOException {
-        if (config.isStrictParsing()) {
-            throw new MimeParseEventException(event);
-        } else {
-            warn(event);
+        if (monitor.isListening()) {
+            String message = message(event);
+            if (monitor.warn(message, "ignoring")) {
+                throw new MimeParseEventException(event);
+            }
         }
     }
     
@@ -264,28 +264,6 @@
         else
             return "Line " + lineNumber + ": " + message;
     }
-    
-    /**
-     * Logs (at warn) an indicative message based on the given event 
-     * and the current state of the system.
-     * @param event <code>Event</code>, not null
-     */
-    protected void warn(Event event) {
-        if (log.isWarnEnabled()) {
-            log.warn(message(event));
-        }
-    }
-    
-    /**
-     * Logs (at debug) an indicative message based on the given event
-     * and the current state of the system.
-     * @param event <code>Event</code>, not null
-     */
-    protected void debug(Event event) {
-        if (log.isDebugEnabled()) {
-            log.debug(message(event));
-        }
-    }
 
     @Override
     public String toString() {

Modified: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/parser/BasicMimeTokenStream.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/parser/BasicMimeTokenStream.java?rev=895489&r1=895488&r2=895489&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/parser/BasicMimeTokenStream.java (original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/parser/BasicMimeTokenStream.java Sun Jan  3 22:00:28 2010
@@ -29,12 +29,10 @@
 import java.util.LinkedList;
 
 import org.apache.james.mime4j.MimeException;
-import org.apache.james.mime4j.codec.Base64InputStream;
-import org.apache.james.mime4j.codec.QuotedPrintableInputStream;
+import org.apache.james.mime4j.codec.DecodeMonitor;
 import org.apache.james.mime4j.io.LineNumberInputStream;
 import org.apache.james.mime4j.io.LineNumberSource;
 import org.apache.james.mime4j.util.CharsetUtil;
-import org.apache.james.mime4j.util.MimeUtil;
 
 /**
  * <p>
@@ -101,6 +99,11 @@
 
     public void doParse(InputStream stream,
             MutableBodyDescriptor newBodyDescriptor, int start) {
+        doParse(stream, newBodyDescriptor, start, config.isStrictParsing() ? DecodeMonitor.STRICT : DecodeMonitor.SILENT);
+    }
+    
+    public void doParse(InputStream stream,
+            MutableBodyDescriptor newBodyDescriptor, int start, DecodeMonitor monitor) {
         LineNumberSource lineSource = null;
         if (config.isCountLineNumbers()) {
             LineNumberInputStream lineInput = new LineNumberInputStream(stream);
@@ -114,7 +117,8 @@
                 newBodyDescriptor, 
                 start, 
                 T_END_MESSAGE,
-                config);
+                config,
+                monitor);
 
 		rootentity.setRecursionMode(recursionMode);
         currentStateMachine = rootentity;
@@ -212,15 +216,7 @@
      *   invalid value.
      */
     public InputStream getDecodedInputStream() {
-        BodyDescriptor bodyDescriptor = getBodyDescriptor();
-        String transferEncoding = bodyDescriptor.getTransferEncoding();
-        InputStream dataStream = currentStateMachine.getContentStream();
-        if (MimeUtil.isBase64Encoding(transferEncoding)) {
-            dataStream = new Base64InputStream(dataStream);
-        } else if (MimeUtil.isQuotedPrintableEncoded(transferEncoding)) {
-            dataStream = new QuotedPrintableInputStream(dataStream);
-        }
-        return dataStream;
+        return currentStateMachine.getDecodedContentStream();
     }
 
     /**

Modified: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/parser/EntityStateMachine.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/parser/EntityStateMachine.java?rev=895489&r1=895488&r2=895489&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/parser/EntityStateMachine.java (original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/parser/EntityStateMachine.java Sun Jan  3 22:00:28 2010
@@ -88,6 +88,16 @@
      *  obtained at the current stage of the parsing process. 
      */
     InputStream getContentStream() throws IllegalStateException;
+    
+    /**
+     * Returns the decoded content stream of the entity body.
+     * 
+     * @return input stream
+     * 
+     * @throws IllegalStateException if the content stream cannot be
+     *  obtained at the current stage of the parsing process. 
+     */
+    InputStream getDecodedContentStream() throws IllegalStateException;
  
     /**
      * Returns current header field.

Modified: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/parser/MimeEntity.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/parser/MimeEntity.java?rev=895489&r1=895488&r2=895489&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/parser/MimeEntity.java (original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/parser/MimeEntity.java Sun Jan  3 22:00:28 2010
@@ -24,6 +24,7 @@
 
 import org.apache.james.mime4j.MimeException;
 import org.apache.james.mime4j.codec.Base64InputStream;
+import org.apache.james.mime4j.codec.DecodeMonitor;
 import org.apache.james.mime4j.codec.QuotedPrintableInputStream;
 import org.apache.james.mime4j.io.BufferedLineReaderInputStream;
 import org.apache.james.mime4j.io.LimitedInputStream;
@@ -50,8 +51,9 @@
             MutableBodyDescriptor body, 
             int startState, 
             int endState,
-            MimeEntityConfig config) {
-        super(body, startState, endState, config);
+            MimeEntityConfig config, 
+            DecodeMonitor monitor) {
+        super(body, startState, endState, config, monitor);
         this.lineSource = lineSource;
         this.inbuffer = new BufferedLineReaderInputStream(
                 instream,
@@ -65,9 +67,19 @@
     public MimeEntity(
             LineNumberSource lineSource,
             InputStream instream,
+            MutableBodyDescriptor body, 
+            int startState, 
+            int endState,
+            MimeEntityConfig config) {
+        this(lineSource, instream, body, startState, endState, config, config.isStrictParsing() ? DecodeMonitor.STRICT : DecodeMonitor.SILENT);
+    }
+
+    public MimeEntity(
+            LineNumberSource lineSource,
+            InputStream instream,
             MutableBodyDescriptor body) {
         this(lineSource, instream, body, EntityStates.T_START_MESSAGE, EntityStates.T_END_MESSAGE, 
-                new MimeEntityConfig());
+                new MimeEntityConfig(), DecodeMonitor.SILENT);
     }
 
     public int getRecursionMode() {
@@ -203,19 +215,21 @@
     }
     
     private EntityStateMachine nextMessage() {
-        String transferEncoding = body.getTransferEncoding();
         // optimize nesting of streams returning the "lower" stream instead of
         // always return dataStream (that would add a LineReaderInputStreamAdaptor in the chain)
         InputStream instream = currentMimePartStream != null ? currentMimePartStream : inbuffer;
+        instream = decodedStream(instream);
+        return nextMimeEntity(EntityStates.T_START_MESSAGE, EntityStates.T_END_MESSAGE, instream);
+    }
+
+    private InputStream decodedStream(InputStream instream) {
+        String transferEncoding = body.getTransferEncoding();
         if (MimeUtil.isBase64Encoding(transferEncoding)) {
-            log.debug("base64 encoded message/rfc822 detected");
             instream = new Base64InputStream(instream);                    
         } else if (MimeUtil.isQuotedPrintableEncoded(transferEncoding)) {
-            log.debug("quoted-printable encoded message/rfc822 detected");
             instream = new QuotedPrintableInputStream(instream);
         }
-
-        return nextMimeEntity(EntityStates.T_START_MESSAGE, EntityStates.T_END_MESSAGE, instream);
+        return instream;
     }
     
     private EntityStateMachine nextMimeEntity() {
@@ -233,7 +247,8 @@
                     body.newChild(), 
                     startState, 
                     endState,
-                    config);
+                    config,
+                    monitor);
             mimeentity.setRecursionMode(recursionMode);
             return mimeentity;
         }
@@ -248,6 +263,9 @@
         }
     }
     
+    /**
+     * @see org.apache.james.mime4j.parser.EntityStateMachine#getContentStream()
+     */
     public InputStream getContentStream() {
         switch (state) {
         case EntityStates.T_START_MULTIPART:
@@ -260,4 +278,11 @@
         }
     }
 
+    /**
+     * @see org.apache.james.mime4j.parser.EntityStateMachine#getDecodedContentStream()
+     */
+    public InputStream getDecodedContentStream() throws IllegalStateException {
+        return decodedStream(getContentStream());
+    }
+
 }

Modified: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/parser/RawEntity.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/parser/RawEntity.java?rev=895489&r1=895488&r2=895489&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/parser/RawEntity.java (original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/parser/RawEntity.java Sun Jan  3 22:00:28 2010
@@ -87,5 +87,12 @@
     public String getFieldValue() {
         return null;
     }
+
+    /**
+     * @see org.apache.james.mime4j.parser.EntityStateMachine#getDecodedContentStream()
+     */
+    public InputStream getDecodedContentStream() throws IllegalStateException {
+        throw new IllegalStateException("Raw entity does not support stream decoding");
+    }
     
 }

Modified: james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/field/address/AddressTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/field/address/AddressTest.java?rev=895489&r1=895488&r2=895489&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/field/address/AddressTest.java (original)
+++ james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/field/address/AddressTest.java Sun Jan  3 22:00:28 2010
@@ -424,7 +424,7 @@
         try {
             AddressBuilder.parseGroup("john.doe@acme.org, jane.doe@acme.org");
             fail();
-        } catch (IllegalArgumentException expected) {
+        } catch (ParseException expected) {
         }
     }
     
@@ -447,13 +447,13 @@
         try {
             AddressBuilder.parseGroup("john.doe@acme.org");
             fail();
-        } catch (IllegalArgumentException expected) {
+        } catch (ParseException expected) {
         }
 
         try {
             AddressBuilder.parseGroup("g1: john.doe@acme.org;, g2: mary@example.net;");
             fail();
-        } catch (IllegalArgumentException expected) {
+        } catch (ParseException expected) {
         }
     }
 
@@ -475,13 +475,13 @@
         try {
             AddressBuilder.parseMailbox("g: Mary Smith <mary@example.net>;");
             fail();
-        } catch (IllegalArgumentException expected) {
+        } catch (ParseException expected) {
         }
 
         try {
             AddressBuilder.parseMailbox("Mary Smith <mary@example.net>, hans.mueller@acme.org");
             fail();
-        } catch (IllegalArgumentException expected) {
+        } catch (ParseException expected) {
         }
     }
     

Modified: james/mime4j/branches/cycleclean/examples/src/main/java/org/apache/james/mime4j/samples/dom/TextPlainMessage.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/examples/src/main/java/org/apache/james/mime4j/samples/dom/TextPlainMessage.java?rev=895489&r1=895488&r2=895489&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/examples/src/main/java/org/apache/james/mime4j/samples/dom/TextPlainMessage.java (original)
+++ james/mime4j/branches/cycleclean/examples/src/main/java/org/apache/james/mime4j/samples/dom/TextPlainMessage.java Sun Jan  3 22:00:28 2010
@@ -23,6 +23,7 @@
 import java.util.Date;
 
 import org.apache.james.mime4j.field.address.parser.AddressBuilder;
+import org.apache.james.mime4j.field.address.parser.ParseException;
 import org.apache.james.mime4j.message.TextBody;
 import org.apache.james.mime4j.message.impl.BodyFactory;
 import org.apache.james.mime4j.message.impl.MessageImpl;
@@ -32,7 +33,7 @@
  * Appendix A.1.1.
  */
 public class TextPlainMessage {
-    public static void main(String[] args) throws IOException {
+    public static void main(String[] args) throws IOException, ParseException {
         // 1) start with an empty message
 
         MessageImpl message = new MessageImpl();

Modified: james/mime4j/branches/cycleclean/examples/src/main/java/org/apache/james/mime4j/samples/transform/TransformMessage.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/examples/src/main/java/org/apache/james/mime4j/samples/transform/TransformMessage.java?rev=895489&r1=895488&r2=895489&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/examples/src/main/java/org/apache/james/mime4j/samples/transform/TransformMessage.java (original)
+++ james/mime4j/branches/cycleclean/examples/src/main/java/org/apache/james/mime4j/samples/transform/TransformMessage.java Sun Jan  3 22:00:28 2010
@@ -25,8 +25,10 @@
 import java.util.Random;
 
 import org.apache.james.mime4j.field.address.parser.AddressBuilder;
+import org.apache.james.mime4j.field.ParseException;
 import org.apache.james.mime4j.message.Body;
 import org.apache.james.mime4j.message.Entity;
+import org.apache.james.mime4j.message.Message;
 import org.apache.james.mime4j.message.Multipart;
 import org.apache.james.mime4j.message.TextBody;
 import org.apache.james.mime4j.message.impl.BodyFactory;
@@ -55,10 +57,10 @@
         // Create a template message. It would be possible to load a message
         // from an input stream but for this example a message object is created
         // from scratch for demonstration purposes.
-        MessageImpl template = createTemplate();
+        Message template = createTemplate();
 
         // Create a new message by transforming the template.
-        MessageImpl transformed = transform(template);
+        Message transformed = transform(template);
 
         // Print transformed message.
         System.out.println("\n\nTransformed message:\n--------------------\n");
@@ -83,8 +85,9 @@
 
     /**
      * Copies the given message and makes some arbitrary changes to the copy.
+     * @throws ParseException on bad arguments
      */
-    private static MessageImpl transform(MessageImpl original) throws IOException {
+    private static Message transform(Message original) throws IOException, ParseException {
         // Create a copy of the template. The copy can be modified without
         // affecting the original.
         MessageImpl message = new MessageImpl(original);
@@ -123,7 +126,7 @@
      * Creates a multipart/mixed message that consists of three parts (one text,
      * two binary).
      */
-    private static MessageImpl createTemplate() throws IOException {
+    private static Message createTemplate() throws IOException {
         Multipart multipart = new MultipartImpl("mixed");
 
         BodyPart part1 = createTextPart("This is the first part of the template..");
@@ -135,7 +138,7 @@
         BodyPart part3 = createRandomBinaryPart(300);
         multipart.addBodyPart(part3);
 
-        MessageImpl message = new MessageImpl();
+        Message message = new MessageImpl();
         message.setMultipart(multipart);
 
         message.setSubject("Template message");



Mime
View raw message