james-mime4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1063904 [1/2] - in /james/mime4j/trunk: ./ benchmark/src/main/java/org/apache/james/mime4j/ core/src/main/java/org/apache/james/mime4j/parser/ dom/src/main/java/org/apache/james/mime4j/dom/ dom/src/main/java/org/apache/james/mime4j/field/ ...
Date Wed, 26 Jan 2011 22:38:39 GMT
Author: olegk
Date: Wed Jan 26 22:38:38 2011
New Revision: 1063904

URL: http://svn.apache.org/viewvc?rev=1063904&view=rev
Log:
Message builder / formatter API refactoring (merged from refactoring branch)

Added:
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/dom/MessageFormatter.java
      - copied unchanged from r1063861, james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/MessageFormatter.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/dom/MessageServiceFactory.java
      - copied unchanged from r1063861, james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/MessageServiceFactory.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/dom/ParseParams.java
      - copied unchanged from r1063861, james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/ParseParams.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/dom/ServiceLoaderException.java
      - copied unchanged from r1063861, james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/ServiceLoaderException.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MessageFormatterImpl.java
      - copied unchanged from r1063861, james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/message/MessageFormatterImpl.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MessageServiceFactoryImpl.java
      - copied unchanged from r1063861, james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/message/MessageServiceFactoryImpl.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MimeWriter.java
      - copied unchanged from r1063861, james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/message/MimeWriter.java
    james/mime4j/trunk/dom/src/main/resources/META-INF/services/org.apache.james.mime4j.dom.MessageServiceFactory
      - copied unchanged from r1063861, james/mime4j/branches/dom-api-refactoring/dom/src/main/resources/META-INF/services/org.apache.james.mime4j.dom.MessageServiceFactory
    james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MessageServiceFactoryTest.java
      - copied unchanged from r1063861, james/mime4j/branches/dom-api-refactoring/dom/src/test/java/org/apache/james/mime4j/dom/MessageServiceFactoryTest.java
Removed:
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/dom/MessageBuilderFactory.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MessageBuilderFactoryImpl.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MessageWriter.java
    james/mime4j/trunk/dom/src/main/resources/META-INF/services/org.apache.james.mime4j.dom.MessageBuilderFactory
    james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MessageBuilderFactoryTest.java
Modified:
    james/mime4j/trunk/   (props changed)
    james/mime4j/trunk/benchmark/src/main/java/org/apache/james/mime4j/LongMultipartReadBench.java
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/parser/MimeStreamParser.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/dom/Message.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/dom/MessageBuilder.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/dom/ServiceLoader.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/AddressListFieldImpl.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/Fields.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/MailboxFieldImpl.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/MailboxListFieldImpl.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/address/AddressBuilder.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/address/AddressFormatter.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MessageBuilderImpl.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MessageImpl.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MimeBuilder.java
    james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/ExampleMessagesRoundtripTest.java
    james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/HeaderTest.java
    james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MessageCompleteMailTest.java
    james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MessageHeadlessParserTest.java
    james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MessageParserTest.java
    james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MessageTest.java
    james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MessageWriteToTest.java
    james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MimeBuilderCopyTest.java
    james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MultipartFormTest.java
    james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/FieldsTest.java
    james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/address/AddressTest.java
    james/mime4j/trunk/examples/src/main/java/org/apache/james/mime4j/samples/dom/MultipartMessage.java
    james/mime4j/trunk/examples/src/main/java/org/apache/james/mime4j/samples/dom/TextPlainMessage.java
    james/mime4j/trunk/examples/src/main/java/org/apache/james/mime4j/samples/transform/TransformMessage.java
    james/mime4j/trunk/examples/src/main/java/org/apache/james/mime4j/samples/tree/MessageTree.java

Propchange: james/mime4j/trunk/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jan 26 22:38:38 2011
@@ -1 +1 @@
-/james/mime4j/branches/dom-api-refactoring:1058069-1060896
+/james/mime4j/branches/dom-api-refactoring:1058069-1063861

Modified: james/mime4j/trunk/benchmark/src/main/java/org/apache/james/mime4j/LongMultipartReadBench.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/benchmark/src/main/java/org/apache/james/mime4j/LongMultipartReadBench.java?rev=1063904&r1=1063903&r2=1063904&view=diff
==============================================================================
--- james/mime4j/trunk/benchmark/src/main/java/org/apache/james/mime4j/LongMultipartReadBench.java (original)
+++ james/mime4j/trunk/benchmark/src/main/java/org/apache/james/mime4j/LongMultipartReadBench.java Wed Jan 26 22:38:38 2011
@@ -171,7 +171,7 @@ public class LongMultipartReadBench {
             DefaultStorageProvider.setInstance(new MemoryStorageProvider());
 
             for (int i = 0; i < repetitions; i++) {
-                MimeBuilder.parse(new ByteArrayInputStream(content));
+                MimeBuilder.DEFAULT.parse(new ByteArrayInputStream(content));
             }
         }
     }

Modified: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/parser/MimeStreamParser.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/parser/MimeStreamParser.java?rev=1063904&r1=1063903&r2=1063904&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/parser/MimeStreamParser.java (original)
+++ james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/parser/MimeStreamParser.java Wed Jan 26 22:38:38 2011
@@ -192,32 +192,33 @@ public class MimeStreamParser {
     }
     
     /**
-     * Enables or disables raw mode. In raw mode all future entities 
-     * (messages or body parts) in the stream will be reported to the
+     * Enables raw mode. In raw mode all future entities (messages 
+     * or body parts) in the stream will be reported to the
      * {@link ContentHandler#raw(InputStream)} handler method only.
      * The stream will contain the entire unparsed entity contents 
      * including header fields and whatever is in the body.
-     * 
-     * @param raw <code>true</code> enables raw mode, <code>false</code>
-     *        disables it.
      */
-    public void setRaw(boolean raw) {
+    public void setRaw() {
         mimeTokenStream.setRecursionMode(MimeTokenStream.M_RAW);
     }
     
     /**
-     * Enables or disables flat mode. In flat mode rfc822 parts are not
-     * recursively parsed and multipart content is handled as a single
-     * "simple" stream.
-     * 
-     * @param raw <code>true</code> enables raw mode, <code>false</code>
-     *        disables it.
+     * Enables flat mode. In flat mode rfc822 parts are not recursively 
+     * parsed and multipart content is handled as a single "simple" stream.
      */
-    public void setFlat(boolean flat) {
+    public void setFlat() {
         mimeTokenStream.setRecursionMode(MimeTokenStream.M_FLAT);
     }
     
     /**
+     * Enables recursive mode. In tihs mode rfc822 parts are recursively 
+     * parsed.
+     */
+    public void setRecurse() {
+        mimeTokenStream.setRecursionMode(MimeTokenStream.M_RECURSE);
+    }
+
+    /**
      * Finishes the parsing and stops reading lines.
      * NOTE: No more lines will be parsed but the parser
      * will still call 

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/dom/Message.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/dom/Message.java?rev=1063904&r1=1063903&r2=1063904&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/dom/Message.java (original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/dom/Message.java Wed Jan 26 22:38:38 2011
@@ -19,8 +19,6 @@
 
 package org.apache.james.mime4j.dom;
 
-import java.io.IOException;
-import java.io.OutputStream;
 import java.util.Collection;
 import java.util.Date;
 import java.util.TimeZone;
@@ -33,16 +31,6 @@ import org.apache.james.mime4j.dom.addre
 public interface Message extends Entity, Body {
 
     /**
-     * Write the content to the given output stream.
-     * 
-     * @param out
-     *            the output stream to write to.
-     * @throws IOException
-     *             in case of an I/O error
-     */
-    void writeTo(OutputStream out) throws IOException;
-
-    /**
      * Returns the value of the <i>Message-ID</i> header field of this message
      * or <code>null</code> if it is not present.
      * 

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/dom/MessageBuilder.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/dom/MessageBuilder.java?rev=1063904&r1=1063903&r2=1063904&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/dom/MessageBuilder.java (original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/dom/MessageBuilder.java Wed Jan 26 22:38:38 2011
@@ -28,19 +28,15 @@ import org.apache.james.mime4j.codec.Dec
 /**
  * Defines the API to obtain Message instances from a mime stream.
  */
-public abstract class MessageBuilder {
+public interface MessageBuilder {
     
-    public abstract Message newMessage();
+    Message newMessage();
+          
+    Message newMessage(Message source);
+          
+    Message parse(InputStream source) throws MimeException, IOException;
+          
+    Message parse(InputStream source, 
+            ParseParams params, DecodeMonitor decodeMonitor) throws MimeException, IOException;
 
-    public abstract Message newMessage(Message source);
-
-    public abstract Message parse(InputStream source) throws MimeException, IOException;
-
-    public abstract void setDecodeMonitor(
-            DecodeMonitor decodeMonitor);
-
-    public abstract void setContentDecoding(boolean contentDecoding);
-    
-    public abstract void setFlatMode();
-
-}
+}
\ No newline at end of file

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/dom/ServiceLoader.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/dom/ServiceLoader.java?rev=1063904&r1=1063903&r2=1063904&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/dom/ServiceLoader.java (original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/dom/ServiceLoader.java Wed Jan 26 22:38:38 2011
@@ -20,6 +20,7 @@ package org.apache.james.mime4j.dom;
 
 import java.io.BufferedReader;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.net.URL;
 import java.util.Enumeration;
@@ -40,56 +41,50 @@ class ServiceLoader {
     static <T> T load(Class<T> spiClass) {
         String spiResURI = "META-INF/services/" + spiClass.getName();
         ClassLoader classLoader = spiClass.getClassLoader();
-        Enumeration<URL> resources;
         try {
-            resources = classLoader.getResources(spiResURI);
-        } catch (IOException e) {
-            return null;
-        }
-
-        while (resources.hasMoreElements()) {
-            URL resource = resources.nextElement();
-            BufferedReader reader = null;
-            try {
-                reader = new BufferedReader(new InputStreamReader(resource
-                        .openStream()));
-                String line;
-                while ((line = reader.readLine()) != null) {
-                    line = line.trim();
-                    int cmtIdx = line.indexOf('#');
-                    if (cmtIdx != -1) {
-                        line = line.substring(0, cmtIdx);
+             Enumeration<URL> resources = classLoader.getResources(spiResURI);
+             while (resources.hasMoreElements()) {
+                 URL resource = resources.nextElement();
+                 InputStream instream = resource.openStream();
+                 try {
+                     BufferedReader reader = new BufferedReader(new InputStreamReader(instream));
+                     String line;
+                     while ((line = reader.readLine()) != null) {
                         line = line.trim();
-                    }
-
-                    if (line.length() == 0) {
-                        continue;
-                    }
+                         int cmtIdx = line.indexOf('#');
+                         if (cmtIdx != -1) {
+                             line = line.substring(0, cmtIdx);
+                             line = line.trim();
+                         }
+
+                         if (line.length() == 0) {
+                             continue;
+                         }
 
-                    Class<?> implClass;
-                    try {
-                        implClass = classLoader.loadClass(line);
-                        
+                         Class<?> implClass = classLoader.loadClass(line);
                         if (spiClass.isAssignableFrom(implClass)) {
                             Object impl = implClass.newInstance();
                             return spiClass.cast(impl);
                         }
-                    } catch (Exception e) {
-                        e.printStackTrace();
-                    }
-                }
-            } catch (IOException e) {
-                e.printStackTrace();
-            } finally {
-                if (reader != null) {
-                    try {
-                        reader.close();
-                    } catch (IOException e) {
                     }
+                     reader.close();
+                 } finally {
+                     instream.close();
                 }
             }
+             return null;
+         } catch (IOException ex) {
+             throw new ServiceLoaderException(ex);
+         } catch (ClassNotFoundException ex) {
+             throw new ServiceLoaderException("Unknown SPI class '" 
+                     + spiClass.getName() + "'", ex);
+         } catch (IllegalAccessException ex) {
+             // Not visible
+             return null;
+         } catch (InstantiationException ex) {
+             throw new ServiceLoaderException("SPI class '" 
+                     + spiClass.getName() + "' cannot be instantiated", ex);
         }
-
-        return null;
     }
+
 }
\ No newline at end of file

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/AddressListFieldImpl.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/AddressListFieldImpl.java?rev=1063904&r1=1063903&r2=1063904&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/AddressListFieldImpl.java (original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/AddressListFieldImpl.java Wed Jan 26 22:38:38 2011
@@ -64,7 +64,7 @@ public class AddressListFieldImpl extend
         String body = getBody();
 
         try {
-            addressList = AddressBuilder.parseAddressList(body, monitor);
+            addressList = AddressBuilder.DEFAULT.parseAddressList(body, monitor);
         } catch (ParseException e) {
             parseException = e;
         }

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/Fields.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/Fields.java?rev=1063904&r1=1063903&r2=1063904&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/Fields.java (original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/Fields.java Wed Jan 26 22:38:38 2011
@@ -635,7 +635,7 @@ public class Fields {
             if (sb.length() > 0) {
                 sb.append(", ");
             }
-            AddressFormatter.encode(sb, address);
+            AddressFormatter.DEFAULT.encode(sb, address);
         }
         return sb.toString();
     }

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/MailboxFieldImpl.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/MailboxFieldImpl.java?rev=1063904&r1=1063903&r2=1063904&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/MailboxFieldImpl.java (original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/MailboxFieldImpl.java Wed Jan 26 22:38:38 2011
@@ -64,7 +64,7 @@ public class MailboxFieldImpl extends Ab
         String body = getBody();
 
         try {
-            MailboxList mailboxList = AddressBuilder.parseAddressList(body, monitor).flatten();
+            MailboxList mailboxList = AddressBuilder.DEFAULT.parseAddressList(body, monitor).flatten();
             if (mailboxList.size() > 0) {
                 mailbox = mailboxList.get(0);
             }

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/MailboxListFieldImpl.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/MailboxListFieldImpl.java?rev=1063904&r1=1063903&r2=1063904&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/MailboxListFieldImpl.java (original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/MailboxListFieldImpl.java Wed Jan 26 22:38:38 2011
@@ -63,7 +63,7 @@ public class MailboxListFieldImpl extend
         String body = getBody();
 
         try {
-            mailboxList = AddressBuilder.parseAddressList(body, monitor).flatten();
+            mailboxList = AddressBuilder.DEFAULT.parseAddressList(body, monitor).flatten();
         } catch (ParseException e) {
             parseException = e;
         }

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/address/AddressBuilder.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/address/AddressBuilder.java?rev=1063904&r1=1063903&r2=1063904&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/address/AddressBuilder.java (original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/address/AddressBuilder.java Wed Jan 26 22:38:38 2011
@@ -31,6 +31,12 @@ import org.apache.james.mime4j.field.add
 
 public class AddressBuilder {
 
+    public static final AddressBuilder DEFAULT = new AddressBuilder();
+    
+    protected AddressBuilder() {
+        super();
+    }
+    
     /**
      * Parses the specified raw string into an address.
      * 
@@ -40,13 +46,13 @@ public class AddressBuilder {
      * @return an <code>Address</code> object for the specified string.
      * @throws ParseException if the raw string does not represent a single address.
      */
-    public static Address parseAddress(String rawAddressString, DecodeMonitor monitor) throws ParseException {
+    public Address parseAddress(String rawAddressString, DecodeMonitor monitor) throws ParseException {
         AddressListParser parser = new AddressListParser(new StringReader(
                 rawAddressString));
         return Builder.getInstance().buildAddress(parser.parseAddress(), monitor);
     }
 
-    public static Address parseAddress(String rawAddressString) throws ParseException {
+    public Address parseAddress(String rawAddressString) throws ParseException {
         return parseAddress(rawAddressString, DecodeMonitor.STRICT);
     }
 
@@ -57,14 +63,14 @@ public class AddressBuilder {
      * The string MUST be unfolded already.
      * @param monitor the DecodeMonitor to be used while parsing/decoding
      */
-    public static AddressList parseAddressList(String rawAddressList, DecodeMonitor monitor)
+    public AddressList parseAddressList(String rawAddressList, DecodeMonitor monitor)
             throws ParseException {
         AddressListParser parser = new AddressListParser(new StringReader(
                 rawAddressList));
         return Builder.getInstance().buildAddressList(parser.parseAddressList(), monitor);
     }
 
-    public static AddressList parseAddressList(String rawAddressList) throws ParseException {
+    public AddressList parseAddressList(String rawAddressList) throws ParseException {
         return parseAddressList(rawAddressList, DecodeMonitor.STRICT);
     }
 
@@ -79,13 +85,13 @@ public class AddressBuilder {
      *             if the raw string does not represent a single mailbox
      *             address.
      */
-    public static Mailbox parseMailbox(String rawMailboxString, DecodeMonitor monitor) throws ParseException {
+    public Mailbox parseMailbox(String rawMailboxString, DecodeMonitor monitor) throws ParseException {
         AddressListParser parser = new AddressListParser(new StringReader(
                 rawMailboxString));
         return Builder.getInstance().buildMailbox(parser.parseMailbox(), monitor);
     }
 
-    public static Mailbox parseMailbox(String rawMailboxString) throws ParseException {
+    public Mailbox parseMailbox(String rawMailboxString) throws ParseException {
         return parseMailbox(rawMailboxString, DecodeMonitor.STRICT);
     }
 
@@ -98,7 +104,7 @@ public class AddressBuilder {
      * @throws ParseException
      *             if the raw string does not represent a single group address.
      */
-    public static Group parseGroup(String rawGroupString, DecodeMonitor monitor) throws ParseException {
+    public Group parseGroup(String rawGroupString, DecodeMonitor monitor) throws ParseException {
         Address address = parseAddress(rawGroupString, monitor);
         if (!(address instanceof Group))
             throw new ParseException("Not a group address");
@@ -106,7 +112,7 @@ public class AddressBuilder {
         return (Group) address;
     }
 
-    public static Group parseGroup(String rawGroupString) throws ParseException {
+    public Group parseGroup(String rawGroupString) throws ParseException {
         return parseGroup(rawGroupString, DecodeMonitor.STRICT);
     }
 

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/address/AddressFormatter.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/address/AddressFormatter.java?rev=1063904&r1=1063903&r2=1063904&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/address/AddressFormatter.java (original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/address/AddressFormatter.java Wed Jan 26 22:38:38 2011
@@ -26,6 +26,12 @@ import org.apache.james.mime4j.dom.addre
 
 public class AddressFormatter {
 
+    public static final AddressFormatter DEFAULT = new AddressFormatter();
+    
+    protected AddressFormatter() {
+        super();
+    }
+    
     /**
      * Formats the address as a human readable string, not including the route.
      * The resulting string is intended for display purposes only and cannot be
@@ -47,7 +53,7 @@ public class AddressFormatter {
      *            exists, <code>false</code> otherwise.
      * @return a string representation of this address intended to be displayed.
      */
-    public static void format(final StringBuilder sb, final Address address, boolean includeRoute) {
+    public void format(final StringBuilder sb, final Address address, boolean includeRoute) {
         if (address == null) {
             return;
         }
@@ -69,7 +75,7 @@ public class AddressFormatter {
      * @return a string representation of this address intended for transport
      *         purposes.
      */
-    public static void encode(final StringBuilder sb, final Address address) {
+    public void encode(final StringBuilder sb, final Address address) {
         if (address == null) {
             return;
         }
@@ -82,7 +88,7 @@ public class AddressFormatter {
         }
     }
     
-    public static void format(final StringBuilder sb, final Mailbox mailbox, boolean includeRoute) {
+    public void format(final StringBuilder sb, final Mailbox mailbox, boolean includeRoute) {
         if (sb == null) {
             throw new IllegalArgumentException("StringBuilder may not be null");
         }
@@ -112,13 +118,13 @@ public class AddressFormatter {
         }
     }
     
-    public static String format(final Mailbox mailbox, boolean includeRoute) {
+    public String format(final Mailbox mailbox, boolean includeRoute) {
         StringBuilder sb = new StringBuilder();
         format(sb, mailbox, includeRoute);
         return sb.toString();
     }
     
-    public static void encode(final StringBuilder sb, final Mailbox mailbox) {
+    public void encode(final StringBuilder sb, final Mailbox mailbox) {
         if (sb == null) {
             throw new IllegalArgumentException("StringBuilder may not be null");
         }
@@ -142,13 +148,13 @@ public class AddressFormatter {
         }
     }
     
-    public static String encode(final Mailbox mailbox) {
+    public String encode(final Mailbox mailbox) {
         StringBuilder sb = new StringBuilder();
         encode(sb, mailbox);
         return sb.toString();
     }
 
-    public static void format(final StringBuilder sb, final Group group, boolean includeRoute) {
+    public void format(final StringBuilder sb, final Group group, boolean includeRoute) {
         if (sb == null) {
             throw new IllegalArgumentException("StringBuilder may not be null");
         }
@@ -171,13 +177,13 @@ public class AddressFormatter {
         sb.append(";");
     }
     
-    public static String format(final Group group, boolean includeRoute) {
+    public String format(final Group group, boolean includeRoute) {
         StringBuilder sb = new StringBuilder();
         format(sb, group, includeRoute);
         return sb.toString();
     }
     
-    public static void encode(final StringBuilder sb, final Group group) {
+    public void encode(final StringBuilder sb, final Group group) {
         if (sb == null) {
             throw new IllegalArgumentException("StringBuilder may not be null");
         }
@@ -200,7 +206,7 @@ public class AddressFormatter {
         sb.append(';');
     }
 
-    public static String encode(final Group group) {
+    public String encode(final Group group) {
         StringBuilder sb = new StringBuilder();
         encode(sb, group);
         return sb.toString();

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MessageBuilderImpl.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MessageBuilderImpl.java?rev=1063904&r1=1063903&r2=1063904&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MessageBuilderImpl.java (original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MessageBuilderImpl.java Wed Jan 26 22:38:38 2011
@@ -1,3 +1,22 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
 package org.apache.james.mime4j.message;
 
 import java.io.IOException;
@@ -7,6 +26,7 @@ import org.apache.james.mime4j.MimeExcep
 import org.apache.james.mime4j.codec.DecodeMonitor;
 import org.apache.james.mime4j.dom.Message;
 import org.apache.james.mime4j.dom.MessageBuilder;
+import org.apache.james.mime4j.dom.ParseParams;
 import org.apache.james.mime4j.storage.StorageProvider;
 import org.apache.james.mime4j.stream.MimeEntityConfig;
 import org.apache.james.mime4j.stream.MutableBodyDescriptorFactory;
@@ -15,44 +35,53 @@ import org.apache.james.mime4j.stream.Mu
  * Default MessageBuilder implementation delegating Message parsing to the "legacy"
  * MessageImpl object.
  */
-public class MessageBuilderImpl extends MessageBuilder {
+public class MessageBuilderImpl implements MessageBuilder {
 
+    private MimeBuilder mimeBuilder = null;
     private StorageProvider storageProvider = null;
-    private DecodeMonitor decodeMonitor = null;
     private MimeEntityConfig mimeEntityConfig = null;
     private MutableBodyDescriptorFactory mutableBodyDescriptorFactory = null;
-    private boolean flatMode = false;
-    private boolean contentDecoding = true;
 
     public MessageBuilderImpl() {
     }
 
-    @Override
     public Message newMessage() {
         return new MessageImpl();
     }
 
-    @Override
+    private MimeBuilder getMimeBuilder() {
+        if (this.mimeBuilder != null) {
+            return this.mimeBuilder;
+        } else {
+            return MimeBuilder.DEFAULT;
+        }
+        
+    }
+    
     public Message newMessage(Message source) {
-        return MimeBuilder.copy(source);
+        return getMimeBuilder().copy(source);
     }
 
-    @Override
     public Message parse(InputStream source) throws MimeException, IOException {
-        return MimeBuilder.parse(source, 
+        return getMimeBuilder().parse(source, 
                 mimeEntityConfig, 
                 storageProvider, 
                 mutableBodyDescriptorFactory, 
-                decodeMonitor, 
-                contentDecoding, 
-                flatMode);
+                null,
+                null);
     }
-
-    @Override
-    public void setDecodeMonitor(DecodeMonitor decodeMonitor) {
-        this.decodeMonitor = decodeMonitor;
+    
+    public Message parse(
+            InputStream source, 
+            ParseParams params, DecodeMonitor decodeMonitor) throws MimeException, IOException {
+        return getMimeBuilder().parse(source, 
+                mimeEntityConfig, 
+                storageProvider, 
+                mutableBodyDescriptorFactory, 
+                params,
+                decodeMonitor);
     }
-
+    
     public void setStorageProvider(StorageProvider storageProvider) {
         this.storageProvider = storageProvider;
     }
@@ -66,14 +95,8 @@ public class MessageBuilderImpl extends 
         this.mutableBodyDescriptorFactory  = mutableBodyDescriptorFactory;
     }
 
-    @Override
-    public void setContentDecoding(boolean contentDecoding) {
-        this.contentDecoding  = contentDecoding;
-    }
-
-    @Override
-    public void setFlatMode() {
-        this.flatMode = true;
+    public void setMimeBuilder(MimeBuilder mimeBuilder) {
+        this.mimeBuilder = mimeBuilder;
     }
 
 }

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MessageImpl.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MessageImpl.java?rev=1063904&r1=1063903&r2=1063904&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MessageImpl.java (original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MessageImpl.java Wed Jan 26 22:38:38 2011
@@ -19,8 +19,6 @@
 
 package org.apache.james.mime4j.message;
 
-import java.io.IOException;
-import java.io.OutputStream;
 import java.util.Collection;
 import java.util.Date;
 import java.util.Map;
@@ -53,13 +51,6 @@ public class MessageImpl extends Abstrac
     public MessageImpl() {
     }
 
-    /**
-     * @see org.apache.james.mime4j.dom.Message#writeTo(java.io.OutputStream)
-     */
-    public void writeTo(OutputStream out) throws IOException {
-        MessageWriter.DEFAULT.writeEntity(this, out);
-    }
-
     @Override
     protected String newUniqueBoundary() {
         return MimeUtil.createUniqueBoundary();

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MimeBuilder.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MimeBuilder.java?rev=1063904&r1=1063903&r2=1063904&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MimeBuilder.java (original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MimeBuilder.java Wed Jan 26 22:38:38 2011
@@ -31,6 +31,7 @@ import org.apache.james.mime4j.dom.Entit
 import org.apache.james.mime4j.dom.Header;
 import org.apache.james.mime4j.dom.Message;
 import org.apache.james.mime4j.dom.Multipart;
+import org.apache.james.mime4j.dom.ParseParams;
 import org.apache.james.mime4j.dom.SingleBody;
 import org.apache.james.mime4j.dom.field.Field;
 import org.apache.james.mime4j.field.DefaultFieldParser;
@@ -45,9 +46,12 @@ import org.apache.james.mime4j.stream.Ra
 /**
  * Utility class for copying message and parsing message elements.
  */
-public final class MimeBuilder {
+public class MimeBuilder {
 
-    private MimeBuilder() {
+    public static final MimeBuilder DEFAULT = new MimeBuilder();
+    
+    protected MimeBuilder() {
+        super();
     }
 
     /**
@@ -60,7 +64,7 @@ public final class MimeBuilder {
      * @param other
      *            header to copy.
      */
-    public static Header copy(Header other) {
+    public Header copy(Header other) {
         HeaderImpl copy = new HeaderImpl();
         for (Field otherField : other.getFields()) {
             copy.addField(otherField);
@@ -85,7 +89,7 @@ public final class MimeBuilder {
      *             is neither a {@link Message}, {@link Multipart} or
      *             {@link SingleBody}.
      */
-    public static BodyPart copy(Entity other) {
+    public BodyPart copy(Entity other) {
         BodyPart copy = new BodyPart(); 
         if (other.getHeader() != null) {
             copy.setHeader(copy(other.getHeader()));
@@ -114,7 +118,7 @@ public final class MimeBuilder {
      *             is neither a {@link Message}, {@link Multipart} or
      *             {@link SingleBody}.
      */
-    public static Multipart copy(Multipart other) {
+    public Multipart copy(Multipart other) {
         MultipartImpl copy = new MultipartImpl(other.getSubType());
         for (Entity otherBodyPart : other.getBodyParts()) {
             copy.addBodyPart(copy(otherBodyPart));
@@ -147,7 +151,7 @@ public final class MimeBuilder {
      *             a {@link MessageImpl}, {@link Multipart} or {@link SingleBody}
      *             (or contains such a <code>Body</code>).
      */
-    public static Body copy(Body body) {
+    public Body copy(Body body) {
         if (body == null)
             throw new IllegalArgumentException("Body is null");
 
@@ -181,7 +185,7 @@ public final class MimeBuilder {
      *             is neither a {@link MessageImpl}, {@link Multipart} or
      *             {@link SingleBody}.
      */
-    public static Message copy(Message other) {
+    public Message copy(Message other) {
         MessageImpl copy = new MessageImpl();
         if (other.getHeader() != null) {
             copy.setHeader(copy(other.getHeader()));
@@ -200,7 +204,7 @@ public final class MimeBuilder {
      * @throws IOException on I/O errors.
      * @throws MimeIOException on MIME protocol violations.
      */
-    public static Header parse(
+    public Header parse(
             final InputStream is,
             final DecodeMonitor monitor) throws IOException, MimeIOException {
         final HeaderImpl header = new HeaderImpl();
@@ -242,21 +246,29 @@ public final class MimeBuilder {
      * @throws MimeIOException
      *             on MIME protocol violations.
      */
-    public static Message parse(
+    public Message parse(
             final InputStream is, 
             final MimeEntityConfig config,
             final StorageProvider storageProvider, 
             final MutableBodyDescriptorFactory bodyDescFactory,
-            final DecodeMonitor monitor,
-            boolean contentDecoding,
-            boolean flatMode) throws IOException, MimeIOException {
+            final ParseParams params,
+            final DecodeMonitor monitor) throws IOException, MimeIOException {
         try {
             MessageImpl message = new MessageImpl();
             DecodeMonitor mon = monitor != null ? monitor : DecodeMonitor.SILENT;
             MimeStreamParser parser = new MimeStreamParser(config, bodyDescFactory, mon);
             parser.setContentHandler(new EntityBuilder(message, storageProvider, mon));
-            parser.setContentDecoding(contentDecoding);
-            if (flatMode) parser.setFlat(true);
+            if (params != null) {
+                parser.setContentDecoding(params.isContentDecoding());
+                if (params.isFlatMode()) {
+                    parser.setFlat();
+                } else {
+                    parser.setRecurse();
+                }
+            } else {
+                parser.setContentDecoding(true);
+                parser.setRecurse();
+            }
             parser.parse(is);
             return message;
         } catch (MimeException e) {
@@ -282,16 +294,16 @@ public final class MimeBuilder {
      * @throws MimeIOException
      *             on MIME protocol violations.
      */
-    public static Message parse(
+    public Message parse(
             final InputStream is, 
             final MimeEntityConfig config,
             final StorageProvider storageProvider, 
             final MutableBodyDescriptorFactory bodyDescFactory,
             final DecodeMonitor monitor) throws IOException, MimeIOException {
-        return parse(is, config, storageProvider, bodyDescFactory, monitor, true, false);
+        return parse(is, config, storageProvider, bodyDescFactory, null, monitor);
     }
     
-    public static Message parse(
+    public Message parse(
             final InputStream is, 
             final MimeEntityConfig config,
             final StorageProvider storageProvider,
@@ -299,7 +311,7 @@ public final class MimeBuilder {
         return parse(is, config, storageProvider, bodyDescFactory, null);
     }
 
-    public static Message parse(
+    public Message parse(
             final InputStream is, 
             final MimeEntityConfig config,
             final StorageProvider storageProvider) throws IOException, MimeIOException {
@@ -317,7 +329,7 @@ public final class MimeBuilder {
      * @throws MimeIOException
      *             on MIME protocol violations.
      */
-    public static Message parse(InputStream is) throws IOException, MimeIOException {
+    public Message parse(InputStream is) throws IOException, MimeIOException {
         return parse(is, null, DefaultStorageProvider.getInstance());
     }
 
@@ -332,7 +344,7 @@ public final class MimeBuilder {
      * @throws MimeIOException
      *             on MIME protocol violations.
      */
-    public static Message parse(InputStream is, MimeEntityConfig config) throws IOException,
+    public Message parse(InputStream is, MimeEntityConfig config) throws IOException,
             MimeIOException {
         return parse(is, config, DefaultStorageProvider.getInstance());
     }

Modified: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/ExampleMessagesRoundtripTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/ExampleMessagesRoundtripTest.java?rev=1063904&r1=1063903&r2=1063904&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/ExampleMessagesRoundtripTest.java (original)
+++ james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/ExampleMessagesRoundtripTest.java Wed Jan 26 22:38:38 2011
@@ -36,6 +36,7 @@ import junit.framework.TestSuite;
 import org.apache.james.mime4j.codec.CodecUtil;
 import org.apache.james.mime4j.dom.Message;
 import org.apache.james.mime4j.message.MimeBuilder;
+import org.apache.james.mime4j.message.MimeWriter;
 import org.apache.james.mime4j.stream.MimeEntityConfig;
 
 /**
@@ -58,9 +59,9 @@ public class ExampleMessagesRoundtripTes
             config.setMalformedHeaderStartsBody(true);
         }
         config.setMaxLineLen(-1);
-        Message inputMessage = MimeBuilder.parse(url.openStream(), config);
+        Message inputMessage = MimeBuilder.DEFAULT.parse(url.openStream(), config);
         ByteArrayOutputStream out = new ByteArrayOutputStream();
-        inputMessage.writeTo(out);
+        MimeWriter.DEFAULT.writeMessage(inputMessage, out);
         
         String s = url.toString();
         URL msgout = new URL(s.substring(0, s.lastIndexOf('.')) + ".out");

Modified: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/HeaderTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/HeaderTest.java?rev=1063904&r1=1063903&r2=1063904&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/HeaderTest.java (original)
+++ james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/HeaderTest.java Wed Jan 26 22:38:38 2011
@@ -26,7 +26,7 @@ import org.apache.james.mime4j.dom.Heade
 import org.apache.james.mime4j.dom.field.Field;
 import org.apache.james.mime4j.field.DefaultFieldParser;
 import org.apache.james.mime4j.message.HeaderImpl;
-import org.apache.james.mime4j.message.MessageWriter;
+import org.apache.james.mime4j.message.MimeWriter;
 import org.apache.james.mime4j.util.CharsetUtil;
 
 public class HeaderTest extends TestCase {
@@ -62,7 +62,7 @@ public class HeaderTest extends TestCase
         
         ByteArrayOutputStream buffer = new ByteArrayOutputStream();
         
-        MessageWriter.DEFAULT.writeHeader(header, buffer);
+        MimeWriter.DEFAULT.writeHeader(header, buffer);
         String s = buffer.toString(CharsetUtil.US_ASCII.name());
         
         assertEquals("Hello: Gr?ezi_z?m?\r\n\r\n", s);

Modified: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MessageCompleteMailTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MessageCompleteMailTest.java?rev=1063904&r1=1063903&r2=1063904&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MessageCompleteMailTest.java (original)
+++ james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MessageCompleteMailTest.java Wed Jan 26 22:38:38 2011
@@ -55,7 +55,7 @@ public class MessageCompleteMailTest ext
 
     private Message createMessage(byte[] octets) throws Exception {
         ByteArrayInputStream in = new ByteArrayInputStream(octets);
-        Message message = MimeBuilder.parse(in);
+        Message message = MimeBuilder.DEFAULT.parse(in);
         return message;
     }
 }

Modified: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MessageHeadlessParserTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MessageHeadlessParserTest.java?rev=1063904&r1=1063903&r2=1063904&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MessageHeadlessParserTest.java (original)
+++ james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MessageHeadlessParserTest.java Wed Jan 26 22:38:38 2011
@@ -44,7 +44,7 @@ public class MessageHeadlessParserTest e
 
 		MimeEntityConfig mimeEntityConfig = new MimeEntityConfig();
 		mimeEntityConfig.setMalformedHeaderStartsBody(true);
-		Message message = MimeBuilder.parse(new ByteArrayInputStream(headlessContent
+		Message message = MimeBuilder.DEFAULT.parse(new ByteArrayInputStream(headlessContent
 				.getBytes("UTF-8")), mimeEntityConfig);
 		assertEquals("text/plain", message.getMimeType());
 		assertEquals(1, message.getHeader().getFields().size());
@@ -62,7 +62,7 @@ public class MessageHeadlessParserTest e
 
 		MimeEntityConfig mimeEntityConfig = new MimeEntityConfig();
 		mimeEntityConfig.setMalformedHeaderStartsBody(true);
-		Message message = MimeBuilder.parse(new ByteArrayInputStream(headlessContent
+		Message message = MimeBuilder.DEFAULT.parse(new ByteArrayInputStream(headlessContent
 				.getBytes("UTF-8")), mimeEntityConfig);
 		assertEquals("text/plain", message.getMimeType());
 		assertEquals(0, message.getHeader().getFields().size());
@@ -89,7 +89,7 @@ public class MessageHeadlessParserTest e
 
 		MimeEntityConfig mimeEntityConfig = new MimeEntityConfig();
 		mimeEntityConfig.setHeadlessParsing(contentType);
-		Message message = MimeBuilder.parse(new ByteArrayInputStream(headlessContent
+		Message message = MimeBuilder.DEFAULT.parse(new ByteArrayInputStream(headlessContent
 				.getBytes("UTF-8")), mimeEntityConfig);
 		assertEquals("multipart/form-data", message.getMimeType());
 		assertEquals(1, message.getHeader().getFields().size());

Modified: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MessageParserTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MessageParserTest.java?rev=1063904&r1=1063903&r2=1063904&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MessageParserTest.java (original)
+++ james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MessageParserTest.java Wed Jan 26 22:38:38 2011
@@ -102,7 +102,7 @@ public class MessageParserTest extends T
             config.setMalformedHeaderStartsBody(true);
         }
         config.setMaxLineLen(-1);
-        Message m = MimeBuilder.parse(url.openStream(), config);
+        Message m = MimeBuilder.DEFAULT.parse(url.openStream(), config);
         
         String s = url.toString();
         String prefix = s.substring(0, s.lastIndexOf('.'));

Modified: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MessageTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MessageTest.java?rev=1063904&r1=1063903&r2=1063904&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MessageTest.java (original)
+++ james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MessageTest.java Wed Jan 26 22:38:38 2011
@@ -45,6 +45,7 @@ import org.apache.james.mime4j.message.B
 import org.apache.james.mime4j.message.HeaderImpl;
 import org.apache.james.mime4j.message.MessageImpl;
 import org.apache.james.mime4j.message.MimeBuilder;
+import org.apache.james.mime4j.message.MimeWriter;
 import org.apache.james.mime4j.message.MultipartImpl;
 
 public class MessageTest extends TestCase {
@@ -133,10 +134,10 @@ public class MessageTest extends TestCas
     public void testWriteTo() throws Exception {
         byte[] inputByte = getRawMessageAsByteArray();
 
-        Message m = MimeBuilder.parse(new ByteArrayInputStream(inputByte));
+        Message m = MimeBuilder.DEFAULT.parse(new ByteArrayInputStream(inputByte));
         ByteArrayOutputStream out = new ByteArrayOutputStream();
 
-        m.writeTo(out);
+        MimeWriter.DEFAULT.writeMessage(m, out);
 
         InputStream output = new ByteArrayInputStream(out.toByteArray());
 
@@ -155,14 +156,14 @@ public class MessageTest extends TestCas
 
         byte[] inputByte = getRawMessageAsByteArray();
 
-        Message m = MimeBuilder.parse(new ByteArrayInputStream(inputByte));
+        Message m = MimeBuilder.DEFAULT.parse(new ByteArrayInputStream(inputByte));
         m.getHeader().addField(DefaultFieldParser.parse(testheader));
 
         assertEquals("header added", m.getHeader().getField(headerName)
                 .getBody(), headerValue);
 
         ByteArrayOutputStream out = new ByteArrayOutputStream();
-        m.writeTo(out);
+        MimeWriter.DEFAULT.writeMessage(m, out);
         List<?> lines = IOUtils.readLines((new BufferedReader(
                 new InputStreamReader(new ByteArrayInputStream(out
                         .toByteArray())))));
@@ -254,7 +255,7 @@ public class MessageTest extends TestCas
     public void testSetSender() throws Exception {
         MessageImpl m = new MessageImpl();
 
-        m.setSender(AddressBuilder.parseMailbox("john.doe@example.net"));
+        m.setSender(AddressBuilder.DEFAULT.parseMailbox("john.doe@example.net"));
         assertEquals("john.doe@example.net", m.getHeader().getField("Sender")
                 .getBody());
 
@@ -276,8 +277,8 @@ public class MessageTest extends TestCas
     public void testSetFrom() throws Exception {
         MessageImpl m = new MessageImpl();
 
-        Mailbox mailbox1 = AddressBuilder.parseMailbox("john.doe@example.net");
-        Mailbox mailbox2 = AddressBuilder.parseMailbox("jane.doe@example.net");
+        Mailbox mailbox1 = AddressBuilder.DEFAULT.parseMailbox("john.doe@example.net");
+        Mailbox mailbox2 = AddressBuilder.DEFAULT.parseMailbox("jane.doe@example.net");
 
         m.setFrom(mailbox1);
         assertEquals("john.doe@example.net", m.getHeader().getField("From")
@@ -310,10 +311,10 @@ public class MessageTest extends TestCas
     public void testSetTo() throws Exception {
         MessageImpl m = new MessageImpl();
 
-        Mailbox mailbox1 = AddressBuilder.parseMailbox("john.doe@example.net");
-        Mailbox mailbox2 = AddressBuilder.parseMailbox("jane.doe@example.net");
+        Mailbox mailbox1 = AddressBuilder.DEFAULT.parseMailbox("john.doe@example.net");
+        Mailbox mailbox2 = AddressBuilder.DEFAULT.parseMailbox("jane.doe@example.net");
         Group group = new Group("Does", mailbox1, mailbox2);
-        Mailbox mailbox3 = AddressBuilder.parseMailbox("Mary Smith <mary@example.net>");
+        Mailbox mailbox3 = AddressBuilder.DEFAULT.parseMailbox("Mary Smith <mary@example.net>");
 
         m.setTo(group);
         assertEquals("Does: john.doe@example.net, jane.doe@example.net;", m
@@ -348,10 +349,10 @@ public class MessageTest extends TestCas
     public void testSetCc() throws Exception {
         MessageImpl m = new MessageImpl();
 
-        Mailbox mailbox1 = AddressBuilder.parseMailbox("john.doe@example.net");
-        Mailbox mailbox2 = AddressBuilder.parseMailbox("jane.doe@example.net");
+        Mailbox mailbox1 = AddressBuilder.DEFAULT.parseMailbox("john.doe@example.net");
+        Mailbox mailbox2 = AddressBuilder.DEFAULT.parseMailbox("jane.doe@example.net");
         Group group = new Group("Does", mailbox1, mailbox2);
-        Mailbox mailbox3 = AddressBuilder.parseMailbox("Mary Smith <mary@example.net>");
+        Mailbox mailbox3 = AddressBuilder.DEFAULT.parseMailbox("Mary Smith <mary@example.net>");
 
         m.setCc(group);
         assertEquals("Does: john.doe@example.net, jane.doe@example.net;", m
@@ -386,10 +387,10 @@ public class MessageTest extends TestCas
     public void testSetBcc() throws Exception {
         MessageImpl m = new MessageImpl();
 
-        Mailbox mailbox1 = AddressBuilder.parseMailbox("john.doe@example.net");
-        Mailbox mailbox2 = AddressBuilder.parseMailbox("jane.doe@example.net");
+        Mailbox mailbox1 = AddressBuilder.DEFAULT.parseMailbox("john.doe@example.net");
+        Mailbox mailbox2 = AddressBuilder.DEFAULT.parseMailbox("jane.doe@example.net");
         Group group = new Group("Does", mailbox1, mailbox2);
-        Mailbox mailbox3 = AddressBuilder.parseMailbox("Mary Smith <mary@example.net>");
+        Mailbox mailbox3 = AddressBuilder.DEFAULT.parseMailbox("Mary Smith <mary@example.net>");
 
         m.setBcc(group);
         assertEquals("Does: john.doe@example.net, jane.doe@example.net;", m
@@ -424,10 +425,10 @@ public class MessageTest extends TestCas
     public void testSetReplyTo() throws Exception {
         MessageImpl m = new MessageImpl();
 
-        Mailbox mailbox1 = AddressBuilder.parseMailbox("john.doe@example.net");
-        Mailbox mailbox2 = AddressBuilder.parseMailbox("jane.doe@example.net");
+        Mailbox mailbox1 = AddressBuilder.DEFAULT.parseMailbox("john.doe@example.net");
+        Mailbox mailbox2 = AddressBuilder.DEFAULT.parseMailbox("jane.doe@example.net");
         Group group = new Group("Does", mailbox1, mailbox2);
-        Mailbox mailbox3 = AddressBuilder.parseMailbox("Mary Smith <mary@example.net>");
+        Mailbox mailbox3 = AddressBuilder.DEFAULT.parseMailbox("Mary Smith <mary@example.net>");
 
         m.setReplyTo(group);
         assertEquals("Does: john.doe@example.net, jane.doe@example.net;", m

Modified: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MessageWriteToTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MessageWriteToTest.java?rev=1063904&r1=1063903&r2=1063904&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MessageWriteToTest.java (original)
+++ james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MessageWriteToTest.java Wed Jan 26 22:38:38 2011
@@ -24,6 +24,7 @@ import java.io.ByteArrayOutputStream;
 
 import org.apache.james.mime4j.ExampleMail;
 import org.apache.james.mime4j.message.MimeBuilder;
+import org.apache.james.mime4j.message.MimeWriter;
 
 import junit.framework.TestCase;
 
@@ -43,7 +44,7 @@ public class MessageWriteToTest extends 
         Message message = createMessage(ExampleMail.RFC822_SIMPLE_BYTES);
         assertFalse("Not multipart", message.isMultipart());
         ByteArrayOutputStream out = new ByteArrayOutputStream();
-        message.writeTo(out);
+        MimeWriter.DEFAULT.writeMessage(message, out);
         assertEquals(out.toByteArray(), ExampleMail.RFC822_SIMPLE_BYTES);
     }
     
@@ -61,7 +62,7 @@ public class MessageWriteToTest extends 
         Message message = createMessage(ExampleMail.MULTIPART_WITH_BINARY_ATTACHMENTS_BYTES);
         assertTrue("Is multipart", message.isMultipart());
         ByteArrayOutputStream out = new ByteArrayOutputStream();
-        message.writeTo(out);
+        MimeWriter.DEFAULT.writeMessage(message, out);
         assertEquals(ExampleMail.MULTIPART_WITH_BINARY_ATTACHMENTS_BYTES, out.toByteArray());
     }
     
@@ -69,7 +70,7 @@ public class MessageWriteToTest extends 
         Message message = createMessage(ExampleMail.MULTIPART_WITH_BINARY_ATTACHMENTS_NOPREAMBLE_BYTES);
         assertTrue("Is multipart", message.isMultipart());
         ByteArrayOutputStream out = new ByteArrayOutputStream();
-        message.writeTo(out);
+        MimeWriter.DEFAULT.writeMessage(message, out);
         assertEquals(ExampleMail.MULTIPART_WITH_BINARY_ATTACHMENTS_NOPREAMBLE_BYTES, out.toByteArray());
     }
     
@@ -77,13 +78,13 @@ public class MessageWriteToTest extends 
         Message message = createMessage(ExampleMail.MULTIPART_WITH_BINARY_ATTACHMENTS_PREAMBLE_EPILOGUE_BYTES);
         assertTrue("Is multipart", message.isMultipart());
         ByteArrayOutputStream out = new ByteArrayOutputStream();
-        message.writeTo(out);
+        MimeWriter.DEFAULT.writeMessage(message, out);
         assertEquals(ExampleMail.MULTIPART_WITH_BINARY_ATTACHMENTS_PREAMBLE_EPILOGUE_BYTES, out.toByteArray());
     }
     
     private Message createMessage(byte[] octets) throws Exception {
         ByteArrayInputStream in = new ByteArrayInputStream(octets);
-        Message message = MimeBuilder.parse(in);
+        Message message = MimeBuilder.DEFAULT.parse(in);
         return message;
     }
 }

Modified: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MimeBuilderCopyTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MimeBuilderCopyTest.java?rev=1063904&r1=1063903&r2=1063904&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MimeBuilderCopyTest.java (original)
+++ james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MimeBuilderCopyTest.java Wed Jan 26 22:38:38 2011
@@ -42,7 +42,7 @@ public class MimeBuilderCopyTest extends
     public void testCopyEmptyMessage() throws Exception {
         MessageImpl original = new MessageImpl();
 
-        Message copy = MimeBuilder.copy(original);
+        Message copy = MimeBuilder.DEFAULT.copy(original);
 
         assertNull(copy.getHeader());
         assertNull(copy.getBody());
@@ -59,7 +59,7 @@ public class MimeBuilderCopyTest extends
         original.setBody(body);
         original.setParent(parent);
 
-        Message copy = MimeBuilder.copy(original);
+        Message copy = MimeBuilder.DEFAULT.copy(original);
 
         assertNotNull(copy.getHeader());
         assertNotSame(header, copy.getHeader());
@@ -75,7 +75,7 @@ public class MimeBuilderCopyTest extends
     public void testCopyEmptyBodyPart() throws Exception {
         BodyPart original = new BodyPart();
 
-        BodyPart copy = MimeBuilder.copy(original);
+        BodyPart copy = MimeBuilder.DEFAULT.copy(original);
 
         assertNull(copy.getHeader());
         assertNull(copy.getBody());
@@ -92,7 +92,7 @@ public class MimeBuilderCopyTest extends
         original.setBody(body);
         original.setParent(parent);
 
-        BodyPart copy = MimeBuilder.copy(original);
+        BodyPart copy = MimeBuilder.DEFAULT.copy(original);
 
         assertNotNull(copy.getHeader());
         assertNotSame(header, copy.getHeader());
@@ -108,7 +108,7 @@ public class MimeBuilderCopyTest extends
     public void testCopyEmptyMultipart() throws Exception {
         Multipart original = new MultipartImpl("mixed");
 
-        Multipart copy = MimeBuilder.copy(original);
+        Multipart copy = MimeBuilder.DEFAULT.copy(original);
 
         assertSame(original.getPreamble(), copy.getPreamble());
         assertSame(original.getEpilogue(), copy.getEpilogue());
@@ -127,7 +127,7 @@ public class MimeBuilderCopyTest extends
         original.setParent(parent);
         original.addBodyPart(bodyPart);
 
-        Multipart copy = MimeBuilder.copy(original);
+        Multipart copy = MimeBuilder.DEFAULT.copy(original);
 
         assertSame(original.getPreamble(), copy.getPreamble());
         assertSame(original.getEpilogue(), copy.getEpilogue());
@@ -154,7 +154,7 @@ public class MimeBuilderCopyTest extends
         original.setHeader(new HeaderImpl());
         original.setBody(multipart);
 
-        Message copy = MimeBuilder.copy(original);
+        Message copy = MimeBuilder.DEFAULT.copy(original);
 
         Multipart multipartCopy = (Multipart) copy.getBody();
         List<Entity> bodyParts = multipartCopy.getBodyParts();
@@ -180,7 +180,7 @@ public class MimeBuilderCopyTest extends
         original.addField(f2);
         original.addField(f3);
 
-        Header copy = MimeBuilder.copy(original);
+        Header copy = MimeBuilder.DEFAULT.copy(original);
 
         // copy must have same fields as original
         assertEquals(Arrays.asList(f1, f2, f3), copy.getFields());

Modified: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MultipartFormTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MultipartFormTest.java?rev=1063904&r1=1063903&r2=1063904&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MultipartFormTest.java (original)
+++ james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MultipartFormTest.java Wed Jan 26 22:38:38 2011
@@ -30,7 +30,7 @@ import org.apache.james.mime4j.message.B
 import org.apache.james.mime4j.message.BodyPart;
 import org.apache.james.mime4j.message.HeaderImpl;
 import org.apache.james.mime4j.message.MessageImpl;
-import org.apache.james.mime4j.message.MessageWriter;
+import org.apache.james.mime4j.message.MimeWriter;
 import org.apache.james.mime4j.message.MultipartImpl;
 
 public class MultipartFormTest extends TestCase {
@@ -67,7 +67,7 @@ public class MultipartFormTest extends T
         multipart.addBodyPart(p3);
         
         ByteArrayOutputStream out = new ByteArrayOutputStream();
-        MessageWriter.DEFAULT.writeMultipart(multipart, out);
+        MimeWriter.DEFAULT.writeMultipart(multipart, out);
         out.close();
         
         String expected = "--foo\r\n" +

Modified: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/FieldsTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/FieldsTest.java?rev=1063904&r1=1063903&r2=1063904&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/FieldsTest.java (original)
+++ james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/FieldsTest.java Wed Jan 26 22:38:38 2011
@@ -242,14 +242,14 @@ public class FieldsTest extends TestCase
     }
 
     public void testSender() throws Exception {
-        MailboxField field = Fields.sender(AddressBuilder
+        MailboxField field = Fields.sender(AddressBuilder.DEFAULT
                 .parseMailbox("JD <john.doe@acme.org>"));
         assertEquals("Sender: JD <john.doe@acme.org>", decode(field));
     }
 
     public void testFrom() throws Exception {
-        Mailbox mailbox1 = AddressBuilder.parseMailbox("JD <john.doe@acme.org>");
-        Mailbox mailbox2 = AddressBuilder.parseMailbox("Mary Smith <mary@example.net>");
+        Mailbox mailbox1 = AddressBuilder.DEFAULT.parseMailbox("JD <john.doe@acme.org>");
+        Mailbox mailbox2 = AddressBuilder.DEFAULT.parseMailbox("Mary Smith <mary@example.net>");
 
         MailboxListField field = Fields.from(mailbox1);
         assertEquals("From: JD <john.doe@acme.org>", decode(field));
@@ -264,9 +264,9 @@ public class FieldsTest extends TestCase
     }
 
     public void testTo() throws Exception {
-        Mailbox mailbox1 = AddressBuilder.parseMailbox("JD <john.doe@acme.org>");
-        Mailbox mailbox2 = AddressBuilder.parseMailbox("jane.doe@example.org");
-        Mailbox mailbox3 = AddressBuilder.parseMailbox("Mary Smith <mary@example.net>");
+        Mailbox mailbox1 = AddressBuilder.DEFAULT.parseMailbox("JD <john.doe@acme.org>");
+        Mailbox mailbox2 = AddressBuilder.DEFAULT.parseMailbox("jane.doe@example.org");
+        Mailbox mailbox3 = AddressBuilder.DEFAULT.parseMailbox("Mary Smith <mary@example.net>");
         Group group = new Group("The Does", mailbox1, mailbox2);
 
         AddressListField field = Fields.to(group);
@@ -285,9 +285,9 @@ public class FieldsTest extends TestCase
     }
 
     public void testCc() throws Exception {
-        Mailbox mailbox1 = AddressBuilder.parseMailbox("JD <john.doe@acme.org>");
-        Mailbox mailbox2 = AddressBuilder.parseMailbox("jane.doe@example.org");
-        Mailbox mailbox3 = AddressBuilder.parseMailbox("Mary Smith <mary@example.net>");
+        Mailbox mailbox1 = AddressBuilder.DEFAULT.parseMailbox("JD <john.doe@acme.org>");
+        Mailbox mailbox2 = AddressBuilder.DEFAULT.parseMailbox("jane.doe@example.org");
+        Mailbox mailbox3 = AddressBuilder.DEFAULT.parseMailbox("Mary Smith <mary@example.net>");
         Group group = new Group("The Does", mailbox1, mailbox2);
 
         AddressListField field = Fields.cc(group);
@@ -306,9 +306,9 @@ public class FieldsTest extends TestCase
     }
 
     public void testBcc() throws Exception {
-        Mailbox mailbox1 = AddressBuilder.parseMailbox("JD <john.doe@acme.org>");
-        Mailbox mailbox2 = AddressBuilder.parseMailbox("jane.doe@example.org");
-        Mailbox mailbox3 = AddressBuilder.parseMailbox("Mary Smith <mary@example.net>");
+        Mailbox mailbox1 = AddressBuilder.DEFAULT.parseMailbox("JD <john.doe@acme.org>");
+        Mailbox mailbox2 = AddressBuilder.DEFAULT.parseMailbox("jane.doe@example.org");
+        Mailbox mailbox3 = AddressBuilder.DEFAULT.parseMailbox("Mary Smith <mary@example.net>");
         Group group = new Group("The Does", mailbox1, mailbox2);
 
         AddressListField field = Fields.bcc(group);
@@ -327,9 +327,9 @@ public class FieldsTest extends TestCase
     }
 
     public void testReplyTo() throws Exception {
-        Mailbox mailbox1 = AddressBuilder.parseMailbox("JD <john.doe@acme.org>");
-        Mailbox mailbox2 = AddressBuilder.parseMailbox("jane.doe@example.org");
-        Mailbox mailbox3 = AddressBuilder.parseMailbox("Mary Smith <mary@example.net>");
+        Mailbox mailbox1 = AddressBuilder.DEFAULT.parseMailbox("JD <john.doe@acme.org>");
+        Mailbox mailbox2 = AddressBuilder.DEFAULT.parseMailbox("jane.doe@example.org");
+        Mailbox mailbox3 = AddressBuilder.DEFAULT.parseMailbox("Mary Smith <mary@example.net>");
         Group group = new Group("The Does", mailbox1, mailbox2);
 
         AddressListField field = Fields.replyTo(group);
@@ -348,15 +348,14 @@ public class FieldsTest extends TestCase
     }
 
     public void testMailbox() throws Exception {
-        MailboxField field = Fields.mailbox("Resent-Sender", AddressBuilder
+        MailboxField field = Fields.mailbox("Resent-Sender", AddressBuilder.DEFAULT
                 .parseMailbox("JD <john.doe@acme.org>"));
-        assertEquals("Resent-Sender: JD <john.doe@acme.org>", decode(field
-                ));
+        assertEquals("Resent-Sender: JD <john.doe@acme.org>", decode(field));
     }
 
     public void testMailboxList() throws Exception {
-        Mailbox mailbox1 = AddressBuilder.parseMailbox("JD <john.doe@acme.org>");
-        Mailbox mailbox2 = AddressBuilder.parseMailbox("Mary Smith <mary@example.net>");
+        Mailbox mailbox1 = AddressBuilder.DEFAULT.parseMailbox("JD <john.doe@acme.org>");
+        Mailbox mailbox2 = AddressBuilder.DEFAULT.parseMailbox("Mary Smith <mary@example.net>");
 
         MailboxListField field = Fields.mailboxList("Resent-From", Arrays
                 .asList(mailbox1, mailbox2));
@@ -365,9 +364,9 @@ public class FieldsTest extends TestCase
     }
 
     public void testAddressList() throws Exception {
-        Mailbox mailbox1 = AddressBuilder.parseMailbox("JD <john.doe@acme.org>");
-        Mailbox mailbox2 = AddressBuilder.parseMailbox("jane.doe@example.org");
-        Mailbox mailbox3 = AddressBuilder.parseMailbox("Mary Smith <mary@example.net>");
+        Mailbox mailbox1 = AddressBuilder.DEFAULT.parseMailbox("JD <john.doe@acme.org>");
+        Mailbox mailbox2 = AddressBuilder.DEFAULT.parseMailbox("jane.doe@example.org");
+        Mailbox mailbox3 = AddressBuilder.DEFAULT.parseMailbox("Mary Smith <mary@example.net>");
         Group group = new Group("The Does", mailbox1, mailbox2);
 
         AddressListField field = Fields.addressList("Resent-To", Arrays.asList(

Modified: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/address/AddressTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/address/AddressTest.java?rev=1063904&r1=1063903&r2=1063904&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/address/AddressTest.java (original)
+++ james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/address/AddressTest.java Wed Jan 26 22:38:38 2011
@@ -42,7 +42,8 @@ public class AddressTest extends TestCas
     }
 
     public void testParse1() throws ParseException {
-        AddressList addrList = AddressBuilder.parseAddressList("John Doe <jdoe@machine(comment).  example>");
+        AddressList addrList = AddressBuilder.DEFAULT.parseAddressList(
+                "John Doe <jdoe@machine(comment).  example>");
         assertEquals(1, addrList.size());
         Mailbox mailbox = (Mailbox)addrList.get(0);
         assertEquals("John Doe", mailbox.getName());
@@ -51,7 +52,8 @@ public class AddressTest extends TestCas
     }
 
     public void testParse2() throws ParseException {
-        AddressList addrList = AddressBuilder.parseAddressList("Mary Smith \t    \t\t  <mary@example.net>");
+        AddressList addrList = AddressBuilder.DEFAULT.parseAddressList(
+                "Mary Smith \t    \t\t  <mary@example.net>");
         assertEquals(1, addrList.size());
         Mailbox mailbox = (Mailbox)addrList.get(0);
         assertEquals("Mary Smith", mailbox.getName());
@@ -60,7 +62,7 @@ public class AddressTest extends TestCas
     }
 
     public void testEmptyGroup() throws ParseException {
-        AddressList addrList = AddressBuilder.parseAddressList("undisclosed-recipients:;");
+        AddressList addrList = AddressBuilder.DEFAULT.parseAddressList("undisclosed-recipients:;");
         assertEquals(1, addrList.size());
         Group group = (Group)addrList.get(0);
         assertEquals(0, group.getMailboxes().size());
@@ -68,7 +70,10 @@ public class AddressTest extends TestCas
     }
 
     public void testMessyGroupAndMailbox() throws ParseException {
-        AddressList addrList = AddressBuilder.parseAddressList("Marketing  folks :  Jane Smith < jane @ example . net >, \" Jack \\\"Jackie\\\" Jones \" < jjones@example.com > (comment(comment)); ,, (comment)  , <@example . net,@example(ignore\\)).com:(ignore)john@(ignore)example.net>");
+        AddressList addrList = AddressBuilder.DEFAULT.parseAddressList(
+                "Marketing  folks :  Jane Smith < jane @ example . net >," +
+                " \" Jack \\\"Jackie\\\" Jones \" < jjones@example.com > (comment(comment)); ,, (comment)  ," +
+                " <@example . net,@example(ignore\\)).com:(ignore)john@(ignore)example.net>");
         assertEquals(2, addrList.size());
 
         Group group = (Group)addrList.get(0);
@@ -95,12 +100,12 @@ public class AddressTest extends TestCas
     }
 
     public void testEmptyAddressList() throws ParseException {
-        assertEquals(0, AddressBuilder.parseAddressList("  \t   \t ").size());
-        assertEquals(0, AddressBuilder.parseAddressList("  \t  ,  , , ,,, , \t ").size());
+        assertEquals(0, AddressBuilder.DEFAULT.parseAddressList("  \t   \t ").size());
+        assertEquals(0, AddressBuilder.DEFAULT.parseAddressList("  \t  ,  , , ,,, , \t ").size());
     }
 
     public void testSimpleForm() throws ParseException {
-        AddressList addrList = AddressBuilder.parseAddressList("\"a b c d e f g\" (comment) @example.net");
+        AddressList addrList = AddressBuilder.DEFAULT.parseAddressList("\"a b c d e f g\" (comment) @example.net");
         assertEquals(1, addrList.size());
         Mailbox mailbox = (Mailbox)addrList.get(0);
         assertEquals("a b c d e f g", mailbox.getLocalPart());
@@ -108,7 +113,7 @@ public class AddressTest extends TestCas
     }
 
     public void testFlatten() throws ParseException {
-        AddressList addrList = AddressBuilder.parseAddressList("dev : one@example.com, two@example.com; , ,,, marketing:three@example.com ,four@example.com;, five@example.com");
+        AddressList addrList = AddressBuilder.DEFAULT.parseAddressList("dev : one@example.com, two@example.com; , ,,, marketing:three@example.com ,four@example.com;, five@example.com");
         assertEquals(3, addrList.size());
         assertEquals(5, addrList.flatten().size());
     }
@@ -125,15 +130,15 @@ public class AddressTest extends TestCas
         // there shouldn't be any aspect of the RFC that is tested here
         // but not in the other unit tests.
 
-        AddressBuilder.parseAddressList("Alfred Neuman <Neuman@BBN-TENEXA>");
-        AddressBuilder.parseAddressList("Neuman@BBN-TENEXA");
-        AddressBuilder.parseAddressList("\"George, Ted\" <Shared@Group.Arpanet>");
-        AddressBuilder.parseAddressList("Wilt . (the Stilt) Chamberlain@NBA.US");
+        AddressBuilder.DEFAULT.parseAddressList("Alfred Neuman <Neuman@BBN-TENEXA>");
+        AddressBuilder.DEFAULT.parseAddressList("Neuman@BBN-TENEXA");
+        AddressBuilder.DEFAULT.parseAddressList("\"George, Ted\" <Shared@Group.Arpanet>");
+        AddressBuilder.DEFAULT.parseAddressList("Wilt . (the Stilt) Chamberlain@NBA.US");
 
         // NOTE: In RFC822 8.1.5, the following example did not have "Galloping Gourmet"
         // in double-quotes.  I can only assume this was a typo, since 6.2.4 specifically
         // disallows spaces in unquoted local-part.
-        AddressBuilder.parseAddressList("     Gourmets:  Pompous Person <WhoZiWhatZit@Cordon-Bleu>," +
+        AddressBuilder.DEFAULT.parseAddressList("     Gourmets:  Pompous Person <WhoZiWhatZit@Cordon-Bleu>," +
                 "                Childs@WGBH.Boston, \"Galloping Gourmet\"@" +
                 "                ANT.Down-Under (Australian National Television)," +
                 "                Cheapie@Discount-Liquors;," +
@@ -143,7 +148,7 @@ public class AddressTest extends TestCas
         // NOTE: In RFC822 8.3.3, the following example ended with a lone ">" after
         // Tops-20-Host.  I can only assume this was a typo, since 6.1 clearly shows
         // ">" requires a matching "<".
-        AddressBuilder.parseAddressList("Important folk:" +
+        AddressBuilder.DEFAULT.parseAddressList("Important folk:" +
                 "                   Tom Softwood <Balsa@Tree.Root>," +
                 "                   \"Sam Irving\"@Other-Host;," +
                 "                 Standard Distribution:" +
@@ -152,16 +157,16 @@ public class AddressTest extends TestCas
 
         // The following are from a Usenet post by Dan J. Bernstein:
         // http://groups.google.com/groups?selm=1996Aug1418.21.01.28081%40koobera.math.uic.edu
-        AddressBuilder.parseAddressList("\":sysmail\"@  Some-Group.\t         Some-Org, Muhammed.(I am  the greatest) Ali @(the)Vegas.WBA");
-        AddressBuilder.parseAddressList("me@home.com (comment (nested (deeply\\))))");
-        AddressBuilder.parseAddressList("mailing list: me@home.com, route two <you@work.com>, them@play.com ;");
+        AddressBuilder.DEFAULT.parseAddressList("\":sysmail\"@  Some-Group.\t         Some-Org, Muhammed.(I am  the greatest) Ali @(the)Vegas.WBA");
+        AddressBuilder.DEFAULT.parseAddressList("me@home.com (comment (nested (deeply\\))))");
+        AddressBuilder.DEFAULT.parseAddressList("mailing list: me@home.com, route two <you@work.com>, them@play.com ;");
 
     }
 
     public void testLexicalError() {
         // ensure that TokenMgrError doesn't get thrown
         try {
-            AddressBuilder.parseAddressList(")");
+            AddressBuilder.DEFAULT.parseAddressList(")");
             fail("Expected parsing error");
         }
         catch (ParseException e) {
@@ -188,7 +193,7 @@ public class AddressTest extends TestCas
 
     
     public void testAddressList() throws ParseException {
-        AddressList addlist = AddressBuilder.parseAddressList("foo@example.com, bar@example.com, third@example.com");
+        AddressList addlist = AddressBuilder.DEFAULT.parseAddressList("foo@example.com, bar@example.com, third@example.com");
         List<Address> al = new ArrayList<Address>();
         al.add(addlist.get(0));
 
@@ -284,12 +289,13 @@ public class AddressTest extends TestCas
         List<Mailbox> al = new ArrayList<Mailbox>();
         al.add(new Mailbox("test", "example.com"));
         al.add(new Mailbox("Foo!", "foo", "example.com"));
-        DomainList dl = new DomainList(new ArrayList<String>(Arrays.asList(new String[] {"foo.example.com"})), true);
+        DomainList dl = new DomainList(new ArrayList<String>(
+                Arrays.asList(new String[] {"foo.example.com"})), true);
         Mailbox mailbox = new Mailbox("Foo Bar", dl, "foo2", "example.com");
         assertSame(dl, mailbox.getRoute());
         al.add(mailbox);
         Group g = new Group("group", new MailboxList(al, false));
-        String s = AddressFormatter.format(g, false);
+        String s = AddressFormatter.DEFAULT.format(g, false);
         assertEquals("group: test@example.com, Foo! <foo@example.com>, Foo Bar <foo2@example.com>;", s);
     }
     
@@ -299,7 +305,7 @@ public class AddressTest extends TestCas
          * ParseException
          */
         try {
-            AddressBuilder.parseAddressList("\"\"bar@bar.com");
+            AddressBuilder.DEFAULT.parseAddressList("\"\"bar@bar.com");
             fail("ParseException expected");
         } catch (ParseException pe) {
         }
@@ -307,16 +313,16 @@ public class AddressTest extends TestCas
     
     public void testMailboxGetEncodedString() throws Exception {
         Mailbox m1 = new Mailbox("john.doe", "acme.org");
-        assertEquals("john.doe@acme.org", AddressFormatter.encode(m1));
+        assertEquals("john.doe@acme.org", AddressFormatter.DEFAULT.encode(m1));
         Mailbox m2 = new Mailbox("john doe", "acme.org");
-        assertEquals("\"john doe\"@acme.org", AddressFormatter.encode(m2));
+        assertEquals("\"john doe\"@acme.org", AddressFormatter.DEFAULT.encode(m2));
         Mailbox m3 = new Mailbox("John Doe", "john.doe", "acme.org");
-        assertEquals("John Doe <john.doe@acme.org>", AddressFormatter.encode(m3));
+        assertEquals("John Doe <john.doe@acme.org>", AddressFormatter.DEFAULT.encode(m3));
         Mailbox m4 = new Mailbox("John Doe @Home", "john.doe", "acme.org");
-        assertEquals("\"John Doe @Home\" <john.doe@acme.org>", AddressFormatter.encode(m4));
+        assertEquals("\"John Doe @Home\" <john.doe@acme.org>", AddressFormatter.DEFAULT.encode(m4));
         Mailbox m5 = new Mailbox("Hans M\374ller", "hans.mueller", "acme.org");
         assertEquals("=?ISO-8859-1?Q?Hans_M=FCller?= <hans.mueller@acme.org>",
-                AddressFormatter.encode(m5));
+                AddressFormatter.DEFAULT.encode(m5));
     }
 
     public void testGroupGetEncodedString() throws Exception {
@@ -327,22 +333,22 @@ public class AddressTest extends TestCas
         Group g = new Group("group @work", new MailboxList(al, false));
         assertEquals("\"group @work\": test@example.com, "
                 + "Foo! <foo@example.com>, =?ISO-8859-1?Q?Hans_M=FCller?="
-                + " <hans.mueller@acme.org>;", AddressFormatter.encode(g));
+                + " <hans.mueller@acme.org>;", AddressFormatter.DEFAULT.encode(g));
     }
 
     public void testEmptyGroupGetEncodedString() throws Exception {
         MailboxList emptyMailboxes = new MailboxList(null, true);
         Group g = new Group("Undisclosed recipients", emptyMailboxes);
-        assertEquals("Undisclosed recipients:;", AddressFormatter.encode(g));
+        assertEquals("Undisclosed recipients:;", AddressFormatter.DEFAULT.encode(g));
     }
 
     public void testParseAddress() throws Exception {
-        Address address = AddressBuilder.parseAddress("Mary Smith <mary@example.net>");
+        Address address = AddressBuilder.DEFAULT.parseAddress("Mary Smith <mary@example.net>");
         assertTrue(address instanceof Mailbox);
         assertEquals("Mary Smith", ((Mailbox) address).getName());
         assertEquals("mary@example.net", ((Mailbox) address).getAddress());
 
-        address = AddressBuilder.parseAddress("group: Mary Smith <mary@example.net>;");
+        address = AddressBuilder.DEFAULT.parseAddress("group: Mary Smith <mary@example.net>;");
         assertTrue(address instanceof Group);
         assertEquals("group", ((Group) address).getName());
         assertEquals("Mary Smith", ((Group) address).getMailboxes().get(0)
@@ -351,15 +357,15 @@ public class AddressTest extends TestCas
                 .get(0).getAddress());
 
         try {
-            AddressBuilder.parseGroup("john.doe@acme.org, jane.doe@acme.org");
+            AddressBuilder.DEFAULT.parseGroup("john.doe@acme.org, jane.doe@acme.org");
             fail();
         } catch (ParseException expected) {
         }
     }
     
     public void testParseGroup() throws Exception {
-        Group group = AddressBuilder
-                .parseGroup("group: john.doe@acme.org, Mary Smith <mary@example.net>;");
+        Group group = AddressBuilder.DEFAULT.parseGroup(
+                "group: john.doe@acme.org, Mary Smith <mary@example.net>;");
         assertEquals("group", group.getName());
 
         MailboxList mailboxes = group.getMailboxes();
@@ -374,41 +380,42 @@ public class AddressTest extends TestCas
         assertEquals("mary@example.net", mailbox2.getAddress());
 
         try {
-            AddressBuilder.parseGroup("john.doe@acme.org");
+            AddressBuilder.DEFAULT.parseGroup("john.doe@acme.org");
             fail();
         } catch (ParseException expected) {
         }
 
         try {
-            AddressBuilder.parseGroup("g1: john.doe@acme.org;, g2: mary@example.net;");
+            AddressBuilder.DEFAULT.parseGroup("g1: john.doe@acme.org;, g2: mary@example.net;");
             fail();
         } catch (ParseException expected) {
         }
     }
 
     public void testParseMailbox() throws Exception {
-        Mailbox mailbox1 = AddressBuilder.parseMailbox("john.doe@acme.org");
+        Mailbox mailbox1 = AddressBuilder.DEFAULT.parseMailbox("john.doe@acme.org");
         assertNull(mailbox1.getName());
         assertEquals("john.doe@acme.org", mailbox1.getAddress());
 
-        Mailbox mailbox2 = AddressBuilder.parseMailbox("Mary Smith <mary@example.net>");
+        Mailbox mailbox2 = AddressBuilder.DEFAULT.parseMailbox("Mary Smith <mary@example.net>");
         assertEquals("Mary Smith", mailbox2.getName());
         assertEquals("mary@example.net", mailbox2.getAddress());
 
         // non-ascii should be allowed in quoted strings
-        Mailbox mailbox3 = AddressBuilder
-                .parseMailbox("\"Hans M\374ller\" <hans.mueller@acme.org>");
+        Mailbox mailbox3 = AddressBuilder.DEFAULT.parseMailbox(
+                "\"Hans M\374ller\" <hans.mueller@acme.org>");
         assertEquals("Hans M\374ller", mailbox3.getName());
         assertEquals("hans.mueller@acme.org", mailbox3.getAddress());
 
         try {
-            AddressBuilder.parseMailbox("g: Mary Smith <mary@example.net>;");
+            AddressBuilder.DEFAULT.parseMailbox("g: Mary Smith <mary@example.net>;");
             fail();
         } catch (ParseException expected) {
         }
 
         try {
-            AddressBuilder.parseMailbox("Mary Smith <mary@example.net>, hans.mueller@acme.org");
+            AddressBuilder.DEFAULT.parseMailbox(
+                    "Mary Smith <mary@example.net>, hans.mueller@acme.org");
             fail();
         } catch (ParseException expected) {
         }

Modified: james/mime4j/trunk/examples/src/main/java/org/apache/james/mime4j/samples/dom/MultipartMessage.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/examples/src/main/java/org/apache/james/mime4j/samples/dom/MultipartMessage.java?rev=1063904&r1=1063903&r2=1063904&view=diff
==============================================================================
--- james/mime4j/trunk/examples/src/main/java/org/apache/james/mime4j/samples/dom/MultipartMessage.java (original)
+++ james/mime4j/trunk/examples/src/main/java/org/apache/james/mime4j/samples/dom/MultipartMessage.java Wed Jan 26 22:38:38 2011
@@ -36,6 +36,7 @@ import org.apache.james.mime4j.field.add
 import org.apache.james.mime4j.message.BodyFactory;
 import org.apache.james.mime4j.message.BodyPart;
 import org.apache.james.mime4j.message.MessageImpl;
+import org.apache.james.mime4j.message.MimeWriter;
 import org.apache.james.mime4j.message.MultipartImpl;
 import org.apache.james.mime4j.storage.Storage;
 import org.apache.james.mime4j.storage.StorageOutputStream;
@@ -57,13 +58,13 @@ public class MultipartMessage {
 
         // Date and From are required fields
         message.setDate(new Date());
-        message.setFrom(AddressBuilder.parseMailbox("John Doe <jdoe@machine.example>"));
+        message.setFrom(AddressBuilder.DEFAULT.parseMailbox("John Doe <jdoe@machine.example>"));
 
         // Message-ID should be present
         message.createMessageId("machine.example");
 
         // set some optional fields
-        message.setTo(AddressBuilder.parseMailbox("Mary Smith <mary@example.net>"));
+        message.setTo(AddressBuilder.DEFAULT.parseMailbox("Mary Smith <mary@example.net>"));
         message.setSubject("An image for you");
 
         // 3) set a multipart body
@@ -88,7 +89,7 @@ public class MultipartMessage {
 
         // 4) print message to standard output
 
-        message.writeTo(System.out);
+        MimeWriter.DEFAULT.writeMessage(message, System.out);
 
         // 5) message is no longer needed and should be disposed of
 



Mime
View raw message