james-mime4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1137643 - in /james/mime4j/trunk: benchmark/src/main/java/org/apache/james/mime4j/ dom/src/main/java/org/apache/james/mime4j/dom/ dom/src/main/java/org/apache/james/mime4j/message/ dom/src/test/java/org/apache/james/mime4j/dom/ examples/sr...
Date Mon, 20 Jun 2011 14:49:11 GMT
Author: olegk
Date: Mon Jun 20 14:49:10 2011
New Revision: 1137643

URL: http://svn.apache.org/viewvc?rev=1137643&view=rev
Log:
Eliminated MessageBuilderImpl to match changes made on the writer side of the DOM API

Removed:
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MessageBuilderImpl.java
Modified:
    james/mime4j/trunk/benchmark/src/main/java/org/apache/james/mime4j/LongMultipartReadBench.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/message/MessageServiceFactoryImpl.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MimeBuilder.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MimeWriter.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/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

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=1137643&r1=1137642&r2=1137643&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
Mon Jun 20 14:49:10 2011
@@ -26,6 +26,7 @@ import java.io.InputStream;
 
 import org.apache.james.mime4j.codec.CodecUtil;
 import org.apache.james.mime4j.dom.Header;
+import org.apache.james.mime4j.dom.MessageBuilder;
 import org.apache.james.mime4j.message.MimeBuilder;
 import org.apache.james.mime4j.message.SimpleContentHandler;
 import org.apache.james.mime4j.parser.AbstractContentHandler;
@@ -170,9 +171,10 @@ public class LongMultipartReadBench {
     private static final class MessageTest implements Test {
         public void run(byte[] content, int repetitions) throws Exception {
             DefaultStorageProvider.setInstance(new MemoryStorageProvider());
+            MessageBuilder builder = new MimeBuilder();
 
             for (int i = 0; i < repetitions; i++) {
-                MimeBuilder.DEFAULT.parse(new ByteArrayInputStream(content));
+                builder.parseMessage(new ByteArrayInputStream(content));
             }
         }
     }

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=1137643&r1=1137642&r2=1137643&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 Mon
Jun 20 14:49:10 2011
@@ -33,6 +33,6 @@ public interface MessageBuilder {
           
     Message newMessage(Message source);
           
-    Message parse(InputStream source) throws MimeException, IOException;
+    Message parseMessage(InputStream source) throws MimeException, IOException;
           
 }
\ No newline at end of file

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MessageServiceFactoryImpl.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MessageServiceFactoryImpl.java?rev=1137643&r1=1137642&r2=1137643&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MessageServiceFactoryImpl.java
(original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MessageServiceFactoryImpl.java
Mon Jun 20 14:49:10 2011
@@ -40,7 +40,7 @@ public class MessageServiceFactoryImpl e
 
     @Override
     public MessageBuilder newMessageBuilder() {
-        MessageBuilderImpl m = new MessageBuilderImpl();
+        MimeBuilder m = new MimeBuilder();
         if (bodyFactory != null) m.setBodyFactory(bodyFactory);
         if (mimeEntityConfig != null) m.setMimeEntityConfig(mimeEntityConfig);
         if (mutableBodyDescriptorFactory != null) m.setMutableBodyDescriptorFactory(mutableBodyDescriptorFactory);

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=1137643&r1=1137642&r2=1137643&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
Mon Jun 20 14:49:10 2011
@@ -30,6 +30,7 @@ import org.apache.james.mime4j.dom.Dispo
 import org.apache.james.mime4j.dom.Entity;
 import org.apache.james.mime4j.dom.Header;
 import org.apache.james.mime4j.dom.Message;
+import org.apache.james.mime4j.dom.MessageBuilder;
 import org.apache.james.mime4j.dom.Multipart;
 import org.apache.james.mime4j.dom.SingleBody;
 import org.apache.james.mime4j.dom.field.ParsedField;
@@ -45,14 +46,49 @@ import org.apache.james.mime4j.stream.Mu
 /**
  * Utility class for copying message and parsing message elements.
  */
-public class MimeBuilder {
+public class MimeBuilder implements MessageBuilder {
 
-    public static final MimeBuilder DEFAULT = new MimeBuilder();
+    private FieldParser<? extends ParsedField> fieldParser = null;
+    private BodyFactory bodyFactory = null;
+    private MimeEntityConfig config = null;
+    private MutableBodyDescriptorFactory bodyDescFactory = null;
+    private boolean contentDecoding = true;
+    private boolean flatMode = false;
+    private DecodeMonitor monitor = null;
     
-    protected MimeBuilder() {
+    public MimeBuilder() {
         super();
     }
 
+    public void setFieldParser(final FieldParser<? extends ParsedField> fieldParser)
{
+        this.fieldParser = fieldParser;
+    }
+
+    public void setBodyFactory(final BodyFactory bodyFactory) {
+        this.bodyFactory = bodyFactory;
+    }
+
+    public void setMimeEntityConfig(final MimeEntityConfig config) {
+        this.config = config;
+    }
+
+    public void setMutableBodyDescriptorFactory(
+            final MutableBodyDescriptorFactory bodyDescFactory) {
+        this.bodyDescFactory  = bodyDescFactory;
+    }
+
+    public void setDecodeMonitor(final DecodeMonitor monitor) {
+        this.monitor = monitor;
+    }
+
+    public void setContentDecoding(boolean contentDecoding) {
+        this.contentDecoding = contentDecoding;
+    }
+
+    public void setFlatMode(boolean flatMode) {
+        this.flatMode = flatMode;
+    }
+    
     /**
      * Creates a new <code>Header</code> from the specified
      * <code>Header</code>. The <code>Header</code> instance is initialized
@@ -203,10 +239,7 @@ public class MimeBuilder {
      * @throws IOException on I/O errors.
      * @throws MimeIOException on MIME protocol violations.
      */
-    public Header parse(
-            final InputStream is,
-            final FieldParser<? extends ParsedField> fieldParser,
-            final DecodeMonitor monitor) throws IOException, MimeIOException {
+    public Header parseHeader(final InputStream is) throws IOException, MimeIOException {
         final HeaderImpl header = new HeaderImpl();
         final MimeStreamParser parser = new MimeStreamParser();
         parser.setContentHandler(new AbstractContentHandler() {
@@ -233,33 +266,15 @@ public class MimeBuilder {
         return header;
     }
 
-    /**
-     * Parses the specified MIME message stream into a <code>Message</code>
-     * instance using given {@link MimeEntityConfig} and {@link StorageProvider}.
-     * 
-     * @param is
-     *            the stream to parse.
-     * @param config
-     *            {@link MimeEntityConfig} to use.
-     * @param bodyFactory
-     *            {@link BodyFactory} to use for storing text and binary
-     *            message bodies.
-     * @param bodyDescFactory
-     *            {@link MutableBodyDescriptorFactory} to use for creating body descriptors.
-     * @throws IOException
-     *             on I/O errors.
-     * @throws MimeIOException
-     *             on MIME protocol violations.
-     */
-    public Message parse(
-            final InputStream is, 
-            final MimeEntityConfig config,
-            final DecodeMonitor monitor,
-            final FieldParser<? extends ParsedField> fieldParser,
-            final BodyFactory bodyFactory, 
-            final MutableBodyDescriptorFactory bodyDescFactory,
-            final boolean contentDecoding,
-            final boolean flatMode) throws IOException, MimeIOException {
+    public Message newMessage() {
+        return new MessageImpl();
+    }
+
+    public Message newMessage(final Message source) {
+        return copy(source);
+    }
+
+    public Message parseMessage(final InputStream is) throws IOException, MimeIOException
{
         try {
             MessageImpl message = new MessageImpl();
             MimeEntityConfig cfg = config != null ? config : new MimeEntityConfig();
@@ -286,80 +301,4 @@ public class MimeBuilder {
         }
     }
 
-    /**
-     * Parses the specified MIME message stream into a <code>Message</code>
-     * instance using given {@link MimeEntityConfig} and {@link StorageProvider}.
-     * 
-     * @param is
-     *            the stream to parse.
-     * @param config
-     *            {@link MimeEntityConfig} to use.
-     * @param storageProvider
-     *            {@link StorageProvider} to use for storing text and binary
-     *            message bodies.
-     * @param bodyDescFactory
-     *            {@link MutableBodyDescriptorFactory} to use for creating body descriptors.
-     * @throws IOException
-     *             on I/O errors.
-     * @throws MimeIOException
-     *             on MIME protocol violations.
-     */
-    public Message parse(
-            final InputStream is, 
-            final MimeEntityConfig config,
-            final DecodeMonitor monitor,
-            final FieldParser<? extends ParsedField> fieldParser,
-            final BodyFactory bodyFactory, 
-            final MutableBodyDescriptorFactory bodyDescFactory) throws IOException, MimeIOException
{
-        return parse(is, config, monitor, fieldParser, bodyFactory, bodyDescFactory, true,
false);
-    }
-    
-    public Message parse(
-            final InputStream is, 
-            final MimeEntityConfig config,
-            final FieldParser<? extends ParsedField> fieldParser,
-            final BodyFactory bodyFactory, 
-            final MutableBodyDescriptorFactory bodyDescFactory) throws IOException, MimeIOException
{
-        return parse(is, config, null, fieldParser, bodyFactory, bodyDescFactory);
-    }
-
-    public Message parse(
-            final InputStream is, 
-            final MimeEntityConfig config,
-            final FieldParser<? extends ParsedField> fieldParser,
-            final BodyFactory bodyFactory) throws IOException, MimeIOException {
-        return parse(is, config, null, fieldParser, bodyFactory, null);
-    }
-
-    /**
-     * Parses the specified MIME message stream into a <code>Message</code>
-     * instance.
-     * 
-     * @param is
-     *            the stream to parse.
-     * @throws IOException
-     *             on I/O errors.
-     * @throws MimeIOException
-     *             on MIME protocol violations.
-     */
-    public Message parse(InputStream is) throws IOException, MimeIOException {
-        return parse(is, null, null, null);
-    }
-
-    /**
-     * Parses the specified MIME message stream into a <code>Message</code>
-     * instance using given {@link MimeEntityConfig}.
-     * 
-     * @param is
-     *            the stream to parse.
-     * @throws IOException
-     *             on I/O errors.
-     * @throws MimeIOException
-     *             on MIME protocol violations.
-     */
-    public Message parse(InputStream is, MimeEntityConfig config) throws IOException,
-            MimeIOException {
-        return parse(is, config, null, null);
-    }
-    
 }

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MimeWriter.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MimeWriter.java?rev=1137643&r1=1137642&r2=1137643&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MimeWriter.java (original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MimeWriter.java Mon
Jun 20 14:49:10 2011
@@ -41,12 +41,6 @@ import org.apache.james.mime4j.util.Mime
 
 /**
  * Writes a message (or a part of a message) to an output stream.
- * <p>
- * This class cannot be instantiated; instead the static instance
- * {@link #DEFAULT} implements the default strategy for writing a message.
- * <p>
- * This class may be subclassed to implement custom strategies for writing
- * messages.
  */
 public class MimeWriter implements MessageFormatter {
 
@@ -54,14 +48,9 @@ public class MimeWriter implements Messa
     private static final byte[] DASHES = { '-', '-' };
 
     /**
-     * The default message writer.
-     */
-    public static final MimeWriter DEFAULT = new MimeWriter();
-
-    /**
      * Protected constructor prevents direct instantiation.
      */
-    protected MimeWriter() {
+    public MimeWriter() {
     }
 
     /**

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=1137643&r1=1137642&r2=1137643&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
Mon Jun 20 14:49:10 2011
@@ -62,9 +62,12 @@ public class ExampleMessagesRoundtripTes
             config.setMalformedHeaderStartsBody(true);
         }
         config.setMaxLineLen(-1);
-        Message inputMessage = MimeBuilder.DEFAULT.parse(url.openStream(), config);
+        MimeBuilder builder = new MimeBuilder();
+        MimeWriter writer = new MimeWriter();
+        builder.setMimeEntityConfig(config);
+        Message inputMessage = builder.parseMessage(url.openStream());
         ByteArrayOutputStream out = new ByteArrayOutputStream();
-        MimeWriter.DEFAULT.writeMessage(inputMessage, out);
+        writer.writeMessage(inputMessage, out);
         
         String s = url.toString();
         URL msgout = new URL(s.substring(0, s.lastIndexOf('.')) + ".out");
@@ -74,7 +77,7 @@ public class ExampleMessagesRoundtripTes
 	        assertEquals("Wrong Expected result", new String(expectedstream.toByteArray()),
new String(out.toByteArray()));
         } catch (FileNotFoundException e) {
         	FileOutputStream fos = new FileOutputStream(msgout.getPath()+".expected");
-	        MimeWriter.DEFAULT.writeMessage(inputMessage, fos);
+        	writer.writeMessage(inputMessage, fos);
         	fos.close();
         	fail("Expected file created");
         }

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=1137643&r1=1137642&r2=1137643&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 Mon Jun
20 14:49:10 2011
@@ -63,7 +63,8 @@ public class HeaderTest extends TestCase
         
         ByteArrayOutputStream outstream = new ByteArrayOutputStream();
         
-        MimeWriter.DEFAULT.writeHeader(header, outstream);
+        MimeWriter writer = new MimeWriter();
+        writer.writeHeader(header, outstream);
         byte[] b = outstream.toByteArray();
         ByteArrayBuffer buf = new ByteArrayBuffer(b.length);
         buf.append(b, 0, b.length);

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=1137643&r1=1137642&r2=1137643&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
Mon Jun 20 14:49:10 2011
@@ -55,7 +55,8 @@ public class MessageCompleteMailTest ext
 
     private Message createMessage(byte[] octets) throws Exception {
         ByteArrayInputStream in = new ByteArrayInputStream(octets);
-        Message message = MimeBuilder.DEFAULT.parse(in);
+        MimeBuilder builder = new MimeBuilder();
+        Message message = builder.parseMessage(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=1137643&r1=1137642&r2=1137643&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
Mon Jun 20 14:49:10 2011
@@ -42,10 +42,12 @@ public class MessageHeadlessParserTest e
 				+ "\r\n"
 				+ "Instead this should be better parsed as a text/plain body\r\n";
 
-		MimeEntityConfig mimeEntityConfig = new MimeEntityConfig();
-		mimeEntityConfig.setMalformedHeaderStartsBody(true);
-		Message message = MimeBuilder.DEFAULT.parse(new ByteArrayInputStream(headlessContent
-				.getBytes("UTF-8")), mimeEntityConfig);
+		MimeEntityConfig config = new MimeEntityConfig();
+		config.setMalformedHeaderStartsBody(true);
+        MimeBuilder builder = new MimeBuilder();
+        builder.setMimeEntityConfig(config);
+		Message message = builder.parseMessage(
+		        new ByteArrayInputStream(headlessContent.getBytes("UTF-8")));
 		assertEquals("text/plain", message.getMimeType());
 		assertEquals(1, message.getHeader().getFields().size());
 		BufferedReader reader = new BufferedReader(((TextBody) message.getBody()).getReader());
@@ -60,10 +62,12 @@ public class MessageHeadlessParserTest e
 				+ "\r\n"
 				+ "Instead this should be better parsed as a text/plain body\r\n";
 
-		MimeEntityConfig mimeEntityConfig = new MimeEntityConfig();
-		mimeEntityConfig.setMalformedHeaderStartsBody(true);
-		Message message = MimeBuilder.DEFAULT.parse(new ByteArrayInputStream(headlessContent
-				.getBytes("UTF-8")), mimeEntityConfig);
+        MimeEntityConfig config = new MimeEntityConfig();
+        config.setMalformedHeaderStartsBody(true);
+        MimeBuilder builder = new MimeBuilder();
+        builder.setMimeEntityConfig(config);
+        Message message = builder.parseMessage(
+                new ByteArrayInputStream(headlessContent.getBytes("UTF-8")));
 		assertEquals("text/plain", message.getMimeType());
 		assertEquals(0, message.getHeader().getFields().size());
 		BufferedReader reader = new BufferedReader(((TextBody) message.getBody()).getReader());
@@ -87,10 +91,13 @@ public class MessageHeadlessParserTest e
 				+ "Content-Type: image/jpeg\r\n" + "\r\n"
 				+ "all kind of stuff\r\n" + "--foo--\r\n";
 
-		MimeEntityConfig mimeEntityConfig = new MimeEntityConfig();
-		mimeEntityConfig.setHeadlessParsing(contentType);
-		Message message = MimeBuilder.DEFAULT.parse(new ByteArrayInputStream(headlessContent
-				.getBytes("UTF-8")), mimeEntityConfig);
+		MimeEntityConfig config = new MimeEntityConfig();
+		config.setHeadlessParsing(contentType);
+        MimeBuilder builder = new MimeBuilder();
+        builder.setMimeEntityConfig(config);
+
+		Message message = builder.parseMessage(
+		        new ByteArrayInputStream(headlessContent.getBytes("UTF-8")));
 		assertEquals("multipart/form-data", message.getMimeType());
 		assertEquals(1, message.getHeader().getFields().size());
 		ContentTypeField contentTypeField = ((ContentTypeField) message

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=1137643&r1=1137642&r2=1137643&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
Mon Jun 20 14:49:10 2011
@@ -108,7 +108,9 @@ public class MessageParserTest extends T
             config.setMalformedHeaderStartsBody(true);
         }
         config.setMaxLineLen(-1);
-        Message m = MimeBuilder.DEFAULT.parse(url.openStream(), config);
+        MimeBuilder builder = new MimeBuilder();
+        builder.setMimeEntityConfig(config);
+        Message m = builder.parseMessage(url.openStream());
         
         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=1137643&r1=1137642&r2=1137643&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 Mon
Jun 20 14:49:10 2011
@@ -134,10 +134,13 @@ public class MessageTest extends TestCas
     public void testWriteTo() throws Exception {
         byte[] inputByte = getRawMessageAsByteArray();
 
-        Message m = MimeBuilder.DEFAULT.parse(new ByteArrayInputStream(inputByte));
+        MimeBuilder builder = new MimeBuilder();
+        MimeWriter writer = new MimeWriter();
+        
+        Message m = builder.parseMessage(new ByteArrayInputStream(inputByte));
         ByteArrayOutputStream out = new ByteArrayOutputStream();
 
-        MimeWriter.DEFAULT.writeMessage(m, out);
+        writer.writeMessage(m, out);
 
         InputStream output = new ByteArrayInputStream(out.toByteArray());
 
@@ -156,14 +159,17 @@ public class MessageTest extends TestCas
 
         byte[] inputByte = getRawMessageAsByteArray();
 
-        Message m = MimeBuilder.DEFAULT.parse(new ByteArrayInputStream(inputByte));
+        MimeBuilder builder = new MimeBuilder();
+        MimeWriter writer = new MimeWriter();
+        
+        Message m = builder.parseMessage(new ByteArrayInputStream(inputByte));
         m.getHeader().addField(DefaultFieldParser.parse(testheader));
 
         assertEquals("header added", m.getHeader().getField(headerName)
                 .getBody(), headerValue);
 
         ByteArrayOutputStream out = new ByteArrayOutputStream();
-        MimeWriter.DEFAULT.writeMessage(m, out);
+        writer.writeMessage(m, out);
         List<?> lines = IOUtils.readLines((new BufferedReader(
                 new InputStreamReader(new ByteArrayInputStream(out
                         .toByteArray())))));

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=1137643&r1=1137642&r2=1137643&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
Mon Jun 20 14:49:10 2011
@@ -44,7 +44,8 @@ public class MessageWriteToTest extends 
         Message message = createMessage(ExampleMail.RFC822_SIMPLE_BYTES);
         assertFalse("Not multipart", message.isMultipart());
         ByteArrayOutputStream out = new ByteArrayOutputStream();
-        MimeWriter.DEFAULT.writeMessage(message, out);
+        MimeWriter writer = new MimeWriter();
+        writer.writeMessage(message, out);
         assertEquals(out.toByteArray(), ExampleMail.RFC822_SIMPLE_BYTES);
     }
     
@@ -62,7 +63,8 @@ public class MessageWriteToTest extends 
         Message message = createMessage(ExampleMail.MULTIPART_WITH_BINARY_ATTACHMENTS_BYTES);
         assertTrue("Is multipart", message.isMultipart());
         ByteArrayOutputStream out = new ByteArrayOutputStream();
-        MimeWriter.DEFAULT.writeMessage(message, out);
+        MimeWriter writer = new MimeWriter();
+        writer.writeMessage(message, out);
         assertEquals(ExampleMail.MULTIPART_WITH_BINARY_ATTACHMENTS_BYTES, out.toByteArray());
     }
     
@@ -70,7 +72,8 @@ public class MessageWriteToTest extends 
         Message message = createMessage(ExampleMail.MULTIPART_WITH_BINARY_ATTACHMENTS_NOPREAMBLE_BYTES);
         assertTrue("Is multipart", message.isMultipart());
         ByteArrayOutputStream out = new ByteArrayOutputStream();
-        MimeWriter.DEFAULT.writeMessage(message, out);
+        MimeWriter writer = new MimeWriter();
+        writer.writeMessage(message, out);
         assertEquals(ExampleMail.MULTIPART_WITH_BINARY_ATTACHMENTS_NOPREAMBLE_BYTES, out.toByteArray());
     }
     
@@ -78,13 +81,15 @@ public class MessageWriteToTest extends 
         Message message = createMessage(ExampleMail.MULTIPART_WITH_BINARY_ATTACHMENTS_PREAMBLE_EPILOGUE_BYTES);
         assertTrue("Is multipart", message.isMultipart());
         ByteArrayOutputStream out = new ByteArrayOutputStream();
-        MimeWriter.DEFAULT.writeMessage(message, out);
+        MimeWriter writer = new MimeWriter();
+        writer.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.DEFAULT.parse(in);
+        MimeBuilder builder = new MimeBuilder();
+        Message message = builder.parseMessage(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=1137643&r1=1137642&r2=1137643&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
Mon Jun 20 14:49:10 2011
@@ -42,7 +42,8 @@ public class MimeBuilderCopyTest extends
     public void testCopyEmptyMessage() throws Exception {
         MessageImpl original = new MessageImpl();
 
-        Message copy = MimeBuilder.DEFAULT.copy(original);
+        MimeBuilder builder = new MimeBuilder();
+        Message copy = builder.copy(original);
 
         assertNull(copy.getHeader());
         assertNull(copy.getBody());
@@ -59,7 +60,8 @@ public class MimeBuilderCopyTest extends
         original.setBody(body);
         original.setParent(parent);
 
-        Message copy = MimeBuilder.DEFAULT.copy(original);
+        MimeBuilder builder = new MimeBuilder();
+        Message copy = builder.copy(original);
 
         assertNotNull(copy.getHeader());
         assertNotSame(header, copy.getHeader());
@@ -75,7 +77,8 @@ public class MimeBuilderCopyTest extends
     public void testCopyEmptyBodyPart() throws Exception {
         BodyPart original = new BodyPart();
 
-        BodyPart copy = MimeBuilder.DEFAULT.copy(original);
+        MimeBuilder builder = new MimeBuilder();
+        BodyPart copy = builder.copy(original);
 
         assertNull(copy.getHeader());
         assertNull(copy.getBody());
@@ -92,7 +95,8 @@ public class MimeBuilderCopyTest extends
         original.setBody(body);
         original.setParent(parent);
 
-        BodyPart copy = MimeBuilder.DEFAULT.copy(original);
+        MimeBuilder builder = new MimeBuilder();
+        BodyPart copy = builder.copy(original);
 
         assertNotNull(copy.getHeader());
         assertNotSame(header, copy.getHeader());
@@ -108,7 +112,8 @@ public class MimeBuilderCopyTest extends
     public void testCopyEmptyMultipart() throws Exception {
         Multipart original = new MultipartImpl("mixed");
 
-        Multipart copy = MimeBuilder.DEFAULT.copy(original);
+        MimeBuilder builder = new MimeBuilder();
+        Multipart copy = builder.copy(original);
 
         assertSame(original.getPreamble(), copy.getPreamble());
         assertSame(original.getEpilogue(), copy.getEpilogue());
@@ -127,7 +132,8 @@ public class MimeBuilderCopyTest extends
         original.setParent(parent);
         original.addBodyPart(bodyPart);
 
-        Multipart copy = MimeBuilder.DEFAULT.copy(original);
+        MimeBuilder builder = new MimeBuilder();
+        Multipart copy = builder.copy(original);
 
         assertSame(original.getPreamble(), copy.getPreamble());
         assertSame(original.getEpilogue(), copy.getEpilogue());
@@ -154,7 +160,8 @@ public class MimeBuilderCopyTest extends
         original.setHeader(new HeaderImpl());
         original.setBody(multipart);
 
-        Message copy = MimeBuilder.DEFAULT.copy(original);
+        MimeBuilder builder = new MimeBuilder();
+        Message copy = builder.copy(original);
 
         Multipart multipartCopy = (Multipart) copy.getBody();
         List<Entity> bodyParts = multipartCopy.getBodyParts();
@@ -180,7 +187,8 @@ public class MimeBuilderCopyTest extends
         original.addField(f2);
         original.addField(f3);
 
-        Header copy = MimeBuilder.DEFAULT.copy(original);
+        MimeBuilder builder = new MimeBuilder();
+        Header copy = builder.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=1137643&r1=1137642&r2=1137643&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
Mon Jun 20 14:49:10 2011
@@ -67,7 +67,8 @@ public class MultipartFormTest extends T
         multipart.addBodyPart(p3);
         
         ByteArrayOutputStream out = new ByteArrayOutputStream();
-        MimeWriter.DEFAULT.writeMultipart(multipart, out);
+        MimeWriter writer = new MimeWriter();
+        writer.writeMultipart(multipart, out);
         out.close();
         
         String expected = "--foo\r\n" +

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=1137643&r1=1137642&r2=1137643&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
Mon Jun 20 14:49:10 2011
@@ -30,6 +30,7 @@ import java.util.Date;
 import javax.imageio.ImageIO;
 
 import org.apache.james.mime4j.dom.BinaryBody;
+import org.apache.james.mime4j.dom.MessageFormatter;
 import org.apache.james.mime4j.dom.Multipart;
 import org.apache.james.mime4j.dom.TextBody;
 import org.apache.james.mime4j.field.address.AddressBuilder;
@@ -89,7 +90,8 @@ public class MultipartMessage {
 
         // 4) print message to standard output
 
-        MimeWriter.DEFAULT.writeMessage(message, System.out);
+        MessageFormatter writer = new MimeWriter();
+        writer.writeMessage(message, System.out);
 
         // 5) message is no longer needed and should be disposed of
 

Modified: james/mime4j/trunk/examples/src/main/java/org/apache/james/mime4j/samples/dom/TextPlainMessage.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/examples/src/main/java/org/apache/james/mime4j/samples/dom/TextPlainMessage.java?rev=1137643&r1=1137642&r2=1137643&view=diff
==============================================================================
--- james/mime4j/trunk/examples/src/main/java/org/apache/james/mime4j/samples/dom/TextPlainMessage.java
(original)
+++ james/mime4j/trunk/examples/src/main/java/org/apache/james/mime4j/samples/dom/TextPlainMessage.java
Mon Jun 20 14:49:10 2011
@@ -22,6 +22,7 @@ package org.apache.james.mime4j.samples.
 import java.io.IOException;
 import java.util.Date;
 
+import org.apache.james.mime4j.dom.MessageFormatter;
 import org.apache.james.mime4j.dom.TextBody;
 import org.apache.james.mime4j.field.address.AddressBuilder;
 import org.apache.james.mime4j.field.address.ParseException;
@@ -63,7 +64,8 @@ public class TextPlainMessage {
 
         // 4) print message to standard output
 
-        MimeWriter.DEFAULT.writeMessage(message, System.out);
+        MessageFormatter writer = new MimeWriter();
+        writer.writeMessage(message, System.out);
 
         // 5) message is no longer needed and should be disposed of
 

Modified: james/mime4j/trunk/examples/src/main/java/org/apache/james/mime4j/samples/transform/TransformMessage.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/examples/src/main/java/org/apache/james/mime4j/samples/transform/TransformMessage.java?rev=1137643&r1=1137642&r2=1137643&view=diff
==============================================================================
--- james/mime4j/trunk/examples/src/main/java/org/apache/james/mime4j/samples/transform/TransformMessage.java
(original)
+++ james/mime4j/trunk/examples/src/main/java/org/apache/james/mime4j/samples/transform/TransformMessage.java
Mon Jun 20 14:49:10 2011
@@ -27,6 +27,8 @@ import java.util.Random;
 import org.apache.james.mime4j.dom.Body;
 import org.apache.james.mime4j.dom.Entity;
 import org.apache.james.mime4j.dom.Message;
+import org.apache.james.mime4j.dom.MessageBuilder;
+import org.apache.james.mime4j.dom.MessageFormatter;
 import org.apache.james.mime4j.dom.Multipart;
 import org.apache.james.mime4j.dom.TextBody;
 import org.apache.james.mime4j.dom.field.ParseException;
@@ -64,9 +66,11 @@ public class TransformMessage {
         // Create a new message by transforming the template.
         Message transformed = transform(template);
 
+        MessageFormatter writer = new MimeWriter();
+        
         // Print transformed message.
         System.out.println("\n\nTransformed message:\n--------------------\n");
-        MimeWriter.DEFAULT.writeMessage(transformed, System.out);
+        writer.writeMessage(transformed, System.out);
 
         // Messages should be disposed of when they are no longer needed.
         // Disposing of a message also disposes of all child elements (e.g. body
@@ -76,7 +80,7 @@ public class TransformMessage {
         // Print original message to illustrate that it was not affected by the
         // transformation.
         System.out.println("\n\nOriginal template:\n------------------\n");
-        MimeWriter.DEFAULT.writeMessage(template, System.out);
+        writer.writeMessage(template, System.out);
 
         // Original message is no longer needed.
         template.dispose();
@@ -92,7 +96,8 @@ public class TransformMessage {
     private static Message transform(Message original) throws IOException, ParseException
{
         // Create a copy of the template. The copy can be modified without
         // affecting the original.
-        Message message = MimeBuilder.DEFAULT.copy(original);
+        MessageBuilder builder = new MimeBuilder();
+        Message message = builder.newMessage(original);
 
         // In this example we know we have a multipart message. Use
         // Message#isMultipart() if uncertain.

Modified: james/mime4j/trunk/examples/src/main/java/org/apache/james/mime4j/samples/tree/MessageTree.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/examples/src/main/java/org/apache/james/mime4j/samples/tree/MessageTree.java?rev=1137643&r1=1137642&r2=1137643&view=diff
==============================================================================
--- james/mime4j/trunk/examples/src/main/java/org/apache/james/mime4j/samples/tree/MessageTree.java
(original)
+++ james/mime4j/trunk/examples/src/main/java/org/apache/james/mime4j/samples/tree/MessageTree.java
Mon Jun 20 14:49:10 2011
@@ -40,11 +40,13 @@ import javax.swing.event.TreeSelectionLi
 import javax.swing.tree.DefaultMutableTreeNode;
 import javax.swing.tree.TreeSelectionModel;
 
+import org.apache.james.mime4j.MimeException;
 import org.apache.james.mime4j.dom.BinaryBody;
 import org.apache.james.mime4j.dom.Body;
 import org.apache.james.mime4j.dom.Entity;
 import org.apache.james.mime4j.dom.Header;
 import org.apache.james.mime4j.dom.Message;
+import org.apache.james.mime4j.dom.MessageBuilder;
 import org.apache.james.mime4j.dom.Multipart;
 import org.apache.james.mime4j.dom.TextBody;
 import org.apache.james.mime4j.dom.address.Mailbox;
@@ -364,8 +366,8 @@ public class MessageTree extends JPanel 
 
     public static void main(String[] args) {
         try {
-
-            final Message message = MimeBuilder.DEFAULT.parse(new FileInputStream(args[0]));
+            final MessageBuilder builder = new MimeBuilder();
+            final Message message = builder.parseMessage(new FileInputStream(args[0]));
 
             javax.swing.SwingUtilities.invokeLater(new Runnable() {
                 public void run() {
@@ -381,6 +383,8 @@ public class MessageTree extends JPanel 
             System.err.println("The file '" + args[0] + "' could not be found.");
         } catch (IOException e) {
             System.err.println("The file '" + args[0] + "' could not be read.");
+        } catch (MimeException e) {
+            System.err.println("The file '" + args[0] + "' is invalid.");
         }
     }
 



Mime
View raw message