Author: mwiederkehr
Date: Tue Jan  6 11:25:25 2009
New Revision: 732068

URL: http://svn.apache.org/viewvc?rev=732068&view=rev
Log:
Deferred parsing of header fields (MIME4J-96).

Modified:
    
james/mime4j/trunk/src/main/java/org/apache/james/mime4j/field/AddressListField.java
    
james/mime4j/trunk/src/main/java/org/apache/james/mime4j/field/ContentTransferEncodingField.java
    
james/mime4j/trunk/src/main/java/org/apache/james/mime4j/field/ContentTypeField.java
    
james/mime4j/trunk/src/main/java/org/apache/james/mime4j/field/DateTimeField.java
    
james/mime4j/trunk/src/main/java/org/apache/james/mime4j/field/MailboxField.java
    
james/mime4j/trunk/src/main/java/org/apache/james/mime4j/field/MailboxListField.java
    
james/mime4j/trunk/src/main/java/org/apache/james/mime4j/field/UnstructuredField.java

Modified: 
james/mime4j/trunk/src/main/java/org/apache/james/mime4j/field/AddressListField.java
URL: 
http://svn.apache.org/viewvc/james/mime4j/trunk/src/main/java/org/apache/james/mime4j/field/AddressListField.java?rev=732068&r1=732067&r2=732068&view=diff
==============================================================================
--- 
james/mime4j/trunk/src/main/java/org/apache/james/mime4j/field/AddressListField.java
 (original)
+++ 
james/mime4j/trunk/src/main/java/org/apache/james/mime4j/field/AddressListField.java
 Tue Jan  6 11:25:25 2009
@@ -24,40 +24,54 @@
 import org.apache.james.mime4j.field.address.AddressList;
 import org.apache.james.mime4j.field.address.parser.ParseException;
 
+/**
+ * Address list field such as <code>To</code> or <code>Reply-To</code>.
+ */
 public class AddressListField extends Field {
+    private static Log log = LogFactory.getLog(AddressListField.class);
+
+    private boolean parsed = false;
+
     private AddressList addressList;
     private ParseException parseException;
 
-    protected AddressListField(String name, String body, String raw, 
AddressList addressList, ParseException parseException) {
+    AddressListField(String name, String body, String raw) {
         super(name, body, raw);
-        this.addressList = addressList;
-        this.parseException = parseException;
     }
 
     public AddressList getAddressList() {
+        if (!parsed)
+            parse();
+
         return addressList;
     }
 
     public ParseException getParseException() {
+        if (!parsed)
+            parse();
+
         return parseException;
     }
 
-    public static class Parser implements FieldParser {
-        private static Log log = LogFactory.getLog(Parser.class);
+    private void parse() {
+        String body = getBody();
 
-        public Field parse(final String name, final String body, final String 
raw) {
-            AddressList addressList = null;
-            ParseException parseException = null;
-            try {
-                addressList = AddressList.parse(body);
-            }
-            catch (ParseException e) {
-                if (log.isDebugEnabled()) {
-                    log.debug("Parsing value '" + body + "': "+ 
e.getMessage());
-                }
-                parseException = e;
+        try {
+            addressList = AddressList.parse(body);
+        } catch (ParseException e) {
+            if (log.isDebugEnabled()) {
+                log.debug("Parsing value '" + body + "': " + e.getMessage());
             }
-            return new AddressListField(name, body, raw, addressList, 
parseException);
+            parseException = e;
+        }
+
+        parsed = true;
+    }
+
+    public static class Parser implements FieldParser {
+        public Field parse(final String name, final String body,
+                final String raw) {
+            return new AddressListField(name, body, raw);
         }
     }
 }

Modified: 
james/mime4j/trunk/src/main/java/org/apache/james/mime4j/field/ContentTransferEncodingField.java
URL: 
http://svn.apache.org/viewvc/james/mime4j/trunk/src/main/java/org/apache/james/mime4j/field/ContentTransferEncodingField.java?rev=732068&r1=732067&r2=732068&view=diff
==============================================================================
--- 
james/mime4j/trunk/src/main/java/org/apache/james/mime4j/field/ContentTransferEncodingField.java
 (original)
+++ 
james/mime4j/trunk/src/main/java/org/apache/james/mime4j/field/ContentTransferEncodingField.java
 Tue Jan  6 11:25:25 2009
@@ -21,20 +21,15 @@
 
 import org.apache.james.mime4j.util.MimeUtil;
 
-
-
 /**
  * Represents a <code>Content-Transfer-Encoding</code> field.
- *
- * 
- * @version $Id: ContentTransferEncodingField.java,v 1.2 2004/10/02 12:41:11 
ntherning Exp $
  */
 public class ContentTransferEncodingField extends Field {
     private String encoding;
-    
-    protected ContentTransferEncodingField(String name, String body, String 
raw, String encoding) {
+
+    ContentTransferEncodingField(String name, String body, String raw) {
         super(name, body, raw);
-        this.encoding = encoding;
+        encoding = body.trim().toLowerCase();
     }
 
     /**
@@ -45,11 +40,11 @@
     public String getEncoding() {
         return encoding;
     }
-    
+
     /**
-     * Gets the encoding of the given field if. Returns the default 
-     * <code>7bit</code> if not set or if
-     * <code>f</code> is <code>null</code>.
+     * Gets the encoding of the given field if. Returns the default
+     * <code>7bit</code> if not set or if <code>f</code> is
+     * <code>null</code>.
      * 
      * @return the encoding.
      */
@@ -59,11 +54,11 @@
         }
         return MimeUtil.ENC_7BIT;
     }
-    
+
     public static class Parser implements FieldParser {
-        public Field parse(final String name, final String body, final String 
raw) {
-            final String encoding = body.trim().toLowerCase();
-            return new ContentTransferEncodingField(name, body, raw, encoding);
+        public Field parse(final String name, final String body,
+                final String raw) {
+            return new ContentTransferEncodingField(name, body, raw);
         }
     }
 }

Modified: 
james/mime4j/trunk/src/main/java/org/apache/james/mime4j/field/ContentTypeField.java
URL: 
http://svn.apache.org/viewvc/james/mime4j/trunk/src/main/java/org/apache/james/mime4j/field/ContentTypeField.java?rev=732068&r1=732067&r2=732068&view=diff
==============================================================================
--- 
james/mime4j/trunk/src/main/java/org/apache/james/mime4j/field/ContentTypeField.java
 (original)
+++ 
james/mime4j/trunk/src/main/java/org/apache/james/mime4j/field/ContentTypeField.java
 Tue Jan  6 11:25:25 2009
@@ -33,52 +33,46 @@
 
 /**
  * Represents a <code>Content-Type</code> field.
- * 
- * @version $Id: ContentTypeField.java,v 1.6 2005/01/27 14:16:31 ntherning Exp 
$
  */
 public class ContentTypeField extends Field {
-    
-    /**
-     * The prefix of all <code>multipart</code> MIME types.
-     */
+    private static Log log = LogFactory.getLog(ContentTypeField.class);
+
+    /** The prefix of all <code>multipart</code> MIME types. */
     public static final String TYPE_MULTIPART_PREFIX = "multipart/";
-    /**
-     * The <code>multipart/digest</code> MIME type.
-     */
+
+    /** The <code>multipart/digest</code> MIME type. */
     public static final String TYPE_MULTIPART_DIGEST = "multipart/digest";
-    /**
-     * The <code>text/plain</code> MIME type.
-     */
+
+    /** The <code>text/plain</code> MIME type. */
     public static final String TYPE_TEXT_PLAIN = "text/plain";
-    /**
-     * The <code>message/rfc822</code> MIME type.
-     */
+
+    /** The <code>message/rfc822</code> MIME type. */
     public static final String TYPE_MESSAGE_RFC822 = "message/rfc822";
-    /**
-     * The name of the <code>boundary</code> parameter.
-     */
+
+    /** The name of the <code>boundary</code> parameter. */
     public static final String PARAM_BOUNDARY = "boundary";
-    /**
-     * The name of the <code>charset</code> parameter.
-     */
+
+    /** The name of the <code>charset</code> parameter. */
     public static final String PARAM_CHARSET = "charset";
-    
+
+    private boolean parsed = false;
+
     private String mimeType = "";
-    private Map<String, String> parameters = null;
+    private Map<String, String> parameters = new HashMap<String, String>();
     private ParseException parseException;
 
-    protected ContentTypeField(String name, String body, String raw, String 
mimeType, Map<String, String> parameters, ParseException parseException) {
+    ContentTypeField(String name, String body, String raw) {
         super(name, body, raw);
-        this.mimeType = mimeType;
-        this.parameters = parameters;
-        this.parseException = parseException;
     }
 
     /**
-     * Gets the exception that was raised during parsing of
-     * the field value, if any; otherwise, null.
+     * Gets the exception that was raised during parsing of the field value, if
+     * any; otherwise, null.
      */
     public ParseException getParseException() {
+        if (!parsed)
+            parse();
+
         return parseException;
     }
 
@@ -88,80 +82,114 @@
      * @return the MIME type or an empty string if not set.
      */
     public String getMimeType() {
+        if (!parsed)
+            parse();
+
         return mimeType;
     }
-    
-    /**
-     * Gets the MIME type defined in the child's 
-     * Content-Type field or derives a MIME type from the parent 
-     * if child is <code>null</code> or hasn't got a MIME type value set. 
-     * If child's MIME type is multipart but no boundary
-     * has been set the MIME type of child will be derived from
-     * the parent.
-     * 
-     * @param child the child.
-     * @param parent the parent.
-     * @return the MIME type.
-     */
-    public static String getMimeType(ContentTypeField child, 
-                                     ContentTypeField parent) {
-        
-        if (child == null || child.getMimeType().length() == 0 
-                || child.isMultipart() && child.getBoundary() == null) {
-            
-            if (parent != null && parent.isMimeType(TYPE_MULTIPART_DIGEST)) {
-                return TYPE_MESSAGE_RFC822;
-            } else {
-                return TYPE_TEXT_PLAIN;
-            }
-        }
-        
-        return child.getMimeType();
-    }
-    
+
     /**
      * Gets the value of a parameter. Parameter names are case-insensitive.
      * 
-     * @param name the name of the parameter to get.
+     * @param name
+     *            the name of the parameter to get.
      * @return the parameter value or <code>null</code> if not set.
      */
     public String getParameter(String name) {
-        return parameters != null 
-                    ? parameters.get(name.toLowerCase())
-                    : null;
+        if (!parsed)
+            parse();
+
+        return parameters.get(name.toLowerCase());
     }
-    
+
     /**
      * Gets all parameters.
      * 
      * @return the parameters.
      */
     public Map<String, String> getParameters() {
-        return parameters != null 
-                    ? Collections.<String, String> unmodifiableMap(parameters)
-                    : Collections.<String, String> emptyMap();
+        if (!parsed)
+            parse();
+
+        return Collections.unmodifiableMap(parameters);
     }
-    
+
+    /**
+     * Determines if the MIME type of this field matches the given one.
+     * 
+     * @param mimeType
+     *            the MIME type to match against.
+     * @return <code>true</code> if the MIME type of this field matches,
+     *         <code>false</code> otherwise.
+     */
+    public boolean isMimeType(String mimeType) {
+        if (!parsed)
+            parse();
+
+        return this.mimeType.equalsIgnoreCase(mimeType);
+    }
+
+    /**
+     * Determines if the MIME type of this field is <code>multipart/*</code>.
+     * 
+     * @return <code>true</code> if this field is has a
+     *         <code>multipart/*</code> MIME type, <code>false</code>
+     *         otherwise.
+     */
+    public boolean isMultipart() {
+        if (!parsed)
+            parse();
+
+        return mimeType.startsWith(TYPE_MULTIPART_PREFIX);
+    }
+
     /**
      * Gets the value of the <code>boundary</code> parameter if set.
      * 
-     * @return the <code>boundary</code> parameter value or <code>null</code> 
-     *             if not set.
+     * @return the <code>boundary</code> parameter value or <code>null</code>
+     *         if not set.
      */
     public String getBoundary() {
         return getParameter(PARAM_BOUNDARY);
     }
-    
+
     /**
      * Gets the value of the <code>charset</code> parameter if set.
      * 
-     * @return the <code>charset</code> parameter value or <code>null</code> 
+     * @return the <code>charset</code> parameter value or <code>null</code>
      *         if not set.
      */
     public String getCharset() {
         return getParameter(PARAM_CHARSET);
     }
-    
+
+    /**
+     * Gets the MIME type defined in the child's Content-Type field or derives 
a
+     * MIME type from the parent if child is <code>null</code> or hasn't got a
+     * MIME type value set. If child's MIME type is multipart but no boundary
+     * has been set the MIME type of child will be derived from the parent.
+     * 
+     * @param child
+     *            the child.
+     * @param parent
+     *            the parent.
+     * @return the MIME type.
+     */
+    public static String getMimeType(ContentTypeField child,
+            ContentTypeField parent) {
+        if (child == null || child.getMimeType().length() == 0
+                || child.isMultipart() && child.getBoundary() == null) {
+
+            if (parent != null && parent.isMimeType(TYPE_MULTIPART_DIGEST)) {
+                return TYPE_MESSAGE_RFC822;
+            } else {
+                return TYPE_TEXT_PLAIN;
+            }
+        }
+
+        return child.getMimeType();
+    }
+
     /**
      * Gets the value of the <code>charset</code> parameter if set for the
      * given field. Returns the default <code>us-ascii</code> if not set or if
@@ -177,79 +205,53 @@
         }
         return "us-ascii";
     }
-    
-    /**
-     * Determines if the MIME type of this field matches the given one. 
-     * 
-     * @param mimeType the MIME type to match against.
-     * @return <code>true</code> if the MIME type of this field matches, 
-     *         <code>false</code> otherwise. 
-     */
-    public boolean isMimeType(String mimeType) {
-        return this.mimeType.equalsIgnoreCase(mimeType);
-    }
-    
-    /**
-     * Determines if the MIME type of this field is <code>multipart/*</code>.
-     * 
-     * @return <code>true</code> if this field is has a 
<code>multipart/*</code>
-     *         MIME type, <code>false</code> otherwise. 
-     */
-    public boolean isMultipart() {
-        return mimeType.startsWith(TYPE_MULTIPART_PREFIX);
-    }
-    
-    public static class Parser implements FieldParser {
-        private static Log log = LogFactory.getLog(Parser.class);
 
-        public Field parse(final String name, final String body, final String 
raw) {
-            ParseException parseException = null;
-            String mimeType = "";
-            Map<String, String> parameters = null;
-
-            ContentTypeParser parser = new ContentTypeParser(new 
StringReader(body));
-            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());
+    private void parse() {
+        String body = getBody();
+
+        ContentTypeParser parser = new ContentTypeParser(new 
StringReader(body));
+        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());
+        }
+
+        final String type = parser.getType();
+        final String subType = parser.getSubType();
+
+        if (type != null && subType != null) {
+            mimeType = (type + "/" + subType).toLowerCase();
 
-            try {
-                final String type = parser.getType();
-                final String subType = parser.getSubType();
-
-                if (type != null && subType != null) {
-                    mimeType = (type + "/" + 
parser.getSubType()).toLowerCase();
-
-                    @SuppressWarnings("unchecked")
-                    List<String> paramNames = parser.getParamNames();
-                    @SuppressWarnings("unchecked")
-                    List<String> paramValues = parser.getParamValues();
-
-                    if (paramNames != null && paramValues != null) {
-                        for (int i = 0; i < paramNames.size() && i < 
paramValues.size(); i++) {
-                            if (parameters == null)
-                                parameters = new HashMap<String, 
String>((int)(paramNames.size() * 1.3 + 1));
-                            String paramName = paramNames.get(i).toLowerCase();
-                            String paramValue = paramValues.get(i);
-                            parameters.put(paramName, paramValue);
-                        }
-                    }
+            @SuppressWarnings("unchecked")
+            List<String> paramNames = parser.getParamNames();
+            @SuppressWarnings("unchecked")
+            List<String> paramValues = parser.getParamValues();
+
+            if (paramNames != null && paramValues != null) {
+                final int len = Math.min(paramNames.size(), 
paramValues.size());
+                for (int i = 0; i < len; i++) {
+                    String paramName = paramNames.get(i).toLowerCase();
+                    String paramValue = paramValues.get(i);
+                    parameters.put(paramName, paramValue);
                 }
             }
-            catch (NullPointerException npe) {
-            }
-            return new ContentTypeField(name, body, raw, mimeType, parameters, 
parseException);
+        }
+
+        parsed = true;
+    }
+
+    public static class Parser implements FieldParser {
+        public Field parse(final String name, final String body,
+                final String raw) {
+            return new ContentTypeField(name, body, raw);
         }
     }
 }

Modified: 
james/mime4j/trunk/src/main/java/org/apache/james/mime4j/field/DateTimeField.java
URL: 
http://svn.apache.org/viewvc/james/mime4j/trunk/src/main/java/org/apache/james/mime4j/field/DateTimeField.java?rev=732068&r1=732067&r2=732068&view=diff
==============================================================================
--- 
james/mime4j/trunk/src/main/java/org/apache/james/mime4j/field/DateTimeField.java
 (original)
+++ 
james/mime4j/trunk/src/main/java/org/apache/james/mime4j/field/DateTimeField.java
 Tue Jan  6 11:25:25 2009
@@ -28,45 +28,60 @@
 import java.io.StringReader;
 import java.util.Date;
 
+/**
+ * Date-time field such as <code>Date</code> or <code>Resent-Date</code>.
+ */
 public class DateTimeField extends Field {
+    private static Log log = LogFactory.getLog(DateTimeField.class);
+
+    private boolean parsed = false;
+
     private Date date;
     private ParseException parseException;
 
-    protected DateTimeField(String name, String body, String raw, Date date, 
ParseException parseException) {
+    DateTimeField(String name, String body, String raw) {
         super(name, body, raw);
-        this.date = date;
-        this.parseException = parseException;
     }
 
     public Date getDate() {
+        if (!parsed)
+            parse();
+
         return date;
     }
 
     public ParseException getParseException() {
+        if (!parsed)
+            parse();
+
         return parseException;
     }
 
-    public static class Parser implements FieldParser {
-        private static Log log = LogFactory.getLog(Parser.class);
+    private void parse() {
+        String body = getBody();
 
-        public Field parse(final String name, final String body, final String 
raw) {
-            Date date = null;
-            ParseException parseException = null;
-            try {
-                try {
-                    date = new DateTimeParser(new 
StringReader(body)).parseAll().getDate();
-                }
-                catch (TokenMgrError err) {
-                    throw new ParseException(err.getMessage());
-                }
+        try {
+            date = new DateTimeParser(new StringReader(body)).parseAll()
+                    .getDate();
+        } catch (ParseException e) {
+            if (log.isDebugEnabled()) {
+                log.debug("Parsing value '" + body + "': " + e.getMessage());
             }
-            catch (ParseException e) {
-                if (log.isDebugEnabled()) {
-                    log.debug("Parsing value '" + body + "': "+ 
e.getMessage());
-                }
-                parseException = e;
+            parseException = e;
+        } catch (TokenMgrError e) {
+            if (log.isDebugEnabled()) {
+                log.debug("Parsing value '" + body + "': " + e.getMessage());
             }
-            return new DateTimeField(name, body, raw, date, parseException);
+            parseException = new ParseException(e.getMessage());
+        }
+
+        parsed = true;
+    }
+
+    public static class Parser implements FieldParser {
+        public Field parse(final String name, final String body,
+                final String raw) {
+            return new DateTimeField(name, body, raw);
         }
     }
 }

Modified: 
james/mime4j/trunk/src/main/java/org/apache/james/mime4j/field/MailboxField.java
URL: 
http://svn.apache.org/viewvc/james/mime4j/trunk/src/main/java/org/apache/james/mime4j/field/MailboxField.java?rev=732068&r1=732067&r2=732068&view=diff
==============================================================================
--- 
james/mime4j/trunk/src/main/java/org/apache/james/mime4j/field/MailboxField.java
 (original)
+++ 
james/mime4j/trunk/src/main/java/org/apache/james/mime4j/field/MailboxField.java
 Tue Jan  6 11:25:25 2009
@@ -26,43 +26,57 @@
 import org.apache.james.mime4j.field.address.MailboxList;
 import org.apache.james.mime4j.field.address.parser.ParseException;
 
+/**
+ * Mailbox field such as <code>Sender</code> or <code>Resent-Sender</code>.
+ */
 public class MailboxField extends Field {
-    private final Mailbox mailbox;
-    private final ParseException parseException;
+    private static Log log = LogFactory.getLog(MailboxField.class);
 
-    protected MailboxField(final String name, final String body, final String 
raw, final Mailbox mailbox, final ParseException parseException) {
+    private boolean parsed = false;
+
+    private Mailbox mailbox;
+    private ParseException parseException;
+
+    MailboxField(final String name, final String body, final String raw) {
         super(name, body, raw);
-        this.mailbox = mailbox;
-        this.parseException = parseException;
     }
 
     public Mailbox getMailbox() {
+        if (!parsed)
+            parse();
+
         return mailbox;
     }
 
     public ParseException getParseException() {
+        if (!parsed)
+            parse();
+
         return parseException;
     }
-    
-    public static class Parser implements FieldParser {
-        private static Log log = LogFactory.getLog(Parser.class);
 
-        public Field parse(final String name, final String body, final String 
raw) {
-            Mailbox mailbox = null;
-            ParseException parseException = null;
-            try {
-                MailboxList mailboxList = AddressList.parse(body).flatten();
-                if (mailboxList.size() > 0) {
-                    mailbox = mailboxList.get(0);
-                }
+    private void parse() {
+        String body = getBody();
+
+        try {
+            MailboxList mailboxList = AddressList.parse(body).flatten();
+            if (mailboxList.size() > 0) {
+                mailbox = mailboxList.get(0);
             }
-            catch (ParseException e) {
-                if (log.isDebugEnabled()) {
-                    log.debug("Parsing value '" + body + "': "+ 
e.getMessage());
-                }
-                parseException = e;
+        } catch (ParseException e) {
+            if (log.isDebugEnabled()) {
+                log.debug("Parsing value '" + body + "': " + e.getMessage());
             }
-            return new MailboxField(name, body, raw, mailbox, parseException);
+            parseException = e;
+        }
+
+        parsed = true;
+    }
+
+    public static class Parser implements FieldParser {
+        public Field parse(final String name, final String body,
+                final String raw) {
+            return new MailboxField(name, body, raw);
         }
     }
 }

Modified: 
james/mime4j/trunk/src/main/java/org/apache/james/mime4j/field/MailboxListField.java
URL: 
http://svn.apache.org/viewvc/james/mime4j/trunk/src/main/java/org/apache/james/mime4j/field/MailboxListField.java?rev=732068&r1=732067&r2=732068&view=diff
==============================================================================
--- 
james/mime4j/trunk/src/main/java/org/apache/james/mime4j/field/MailboxListField.java
 (original)
+++ 
james/mime4j/trunk/src/main/java/org/apache/james/mime4j/field/MailboxListField.java
 Tue Jan  6 11:25:25 2009
@@ -25,41 +25,54 @@
 import org.apache.james.mime4j.field.address.MailboxList;
 import org.apache.james.mime4j.field.address.parser.ParseException;
 
+/**
+ * Mailbox-list field such as <code>From</code> or <code>Resent-From</code>.
+ */
 public class MailboxListField extends Field {
-    
+    private static Log log = LogFactory.getLog(MailboxListField.class);
+
+    private boolean parsed = false;
+
     private MailboxList mailboxList;
     private ParseException parseException;
 
-    protected MailboxListField(final String name, final String body, final 
String raw, final MailboxList mailboxList, final ParseException parseException) 
{
+    MailboxListField(final String name, final String body, final String raw) {
         super(name, body, raw);
-        this.mailboxList = mailboxList;
-        this.parseException = parseException;
     }
 
     public MailboxList getMailboxList() {
+        if (!parsed)
+            parse();
+
         return mailboxList;
     }
 
     public ParseException getParseException() {
+        if (!parsed)
+            parse();
+
         return parseException;
     }
-    
-    public static class Parser implements FieldParser {
-        private static Log log = LogFactory.getLog(Parser.class);
 
-        public Field parse(final String name, final String body, final String 
raw) {
-            MailboxList mailboxList = null;
-            ParseException parseException = null;
-            try {
-                mailboxList = AddressList.parse(body).flatten();
-            }
-            catch (ParseException e) {
-                if (log.isDebugEnabled()) {
-                    log.debug("Parsing value '" + body + "': "+ 
e.getMessage());
-                }
-                parseException = e;
+    private void parse() {
+        String body = getBody();
+
+        try {
+            mailboxList = AddressList.parse(body).flatten();
+        } catch (ParseException e) {
+            if (log.isDebugEnabled()) {
+                log.debug("Parsing value '" + body + "': " + e.getMessage());
             }
-            return new MailboxListField(name, body, raw, mailboxList, 
parseException);
+            parseException = e;
+        }
+
+        parsed = true;
+    }
+
+    public static class Parser implements FieldParser {
+        public Field parse(final String name, final String body,
+                final String raw) {
+            return new MailboxListField(name, body, raw);
         }
     }
 }

Modified: 
james/mime4j/trunk/src/main/java/org/apache/james/mime4j/field/UnstructuredField.java
URL: 
http://svn.apache.org/viewvc/james/mime4j/trunk/src/main/java/org/apache/james/mime4j/field/UnstructuredField.java?rev=732068&r1=732067&r2=732068&view=diff
==============================================================================
--- 
james/mime4j/trunk/src/main/java/org/apache/james/mime4j/field/UnstructuredField.java
 (original)
+++ 
james/mime4j/trunk/src/main/java/org/apache/james/mime4j/field/UnstructuredField.java
 Tue Jan  6 11:25:25 2009
@@ -21,19 +21,15 @@
 
 import org.apache.james.mime4j.decoder.DecoderUtil;
 
-
 /**
  * Simple unstructured field such as <code>Subject</code>.
- *
- * 
- * @version $Id: UnstructuredField.java,v 1.3 2004/10/25 07:26:46 ntherning 
Exp $
  */
 public class UnstructuredField extends Field {
     private String value;
-    
-    protected UnstructuredField(String name, String body, String raw, String 
value) {
+
+    UnstructuredField(String name, String body, String raw) {
         super(name, body, raw);
-        this.value = value;
+        value = DecoderUtil.decodeEncodedWords(body);
     }
 
     public String getValue() {
@@ -41,9 +37,9 @@
     }
 
     public static class Parser implements FieldParser {
-        public Field parse(final String name, final String body, final String 
raw) {
-            final String value = DecoderUtil.decodeEncodedWords(body);
-            return new UnstructuredField(name, body, raw, value);
+        public Field parse(final String name, final String body,
+                final String raw) {
+            return new UnstructuredField(name, body, raw);
         }
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to