james-mime4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject svn commit: r897169 [1/2] - in /james/mime4j/branches/cycleclean: benchmark/src/main/java/org/apache/james/mime4j/ core/src/main/java/org/apache/james/mime4j/dom/ core/src/main/java/org/apache/james/mime4j/message/ core/src/main/java/org/apache/james/m...
Date Fri, 08 Jan 2010 11:20:28 GMT
Author: bago
Date: Fri Jan  8 11:20:17 2010
New Revision: 897169

URL: http://svn.apache.org/viewvc?rev=897169&view=rev
Log:
Renamed packages (related to MIME4J-157):
o.a.j.m.message => o.a.j.m.dom
o.a.j.m.message.impl => o.a.j.m.message

Added:
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/dom/
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/dom/BinaryBody.java   (contents, props changed)
      - copied, changed from r897165, james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/BinaryBody.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/dom/Body.java   (contents, props changed)
      - copied, changed from r897165, james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/Body.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/dom/Disposable.java   (contents, props changed)
      - copied, changed from r897165, james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/Disposable.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/dom/Entity.java   (contents, props changed)
      - copied, changed from r897165, james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/Entity.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/dom/Header.java   (contents, props changed)
      - copied, changed from r897165, james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/Header.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/dom/Message.java   (contents, props changed)
      - copied, changed from r897165, james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/Message.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/dom/Multipart.java   (contents, props changed)
      - copied, changed from r897165, james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/Multipart.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/dom/SingleBody.java   (contents, props changed)
      - copied, changed from r897165, james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/SingleBody.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/dom/TextBody.java   (contents, props changed)
      - copied, changed from r897165, james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/TextBody.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/BodyCopier.java   (with props)
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/BodyFactory.java   (with props)
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/BodyPart.java   (with props)
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/HeaderImpl.java   (with props)
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/MessageBuilder.java   (with props)
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/MessageImpl.java   (with props)
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/MessageWriter.java   (with props)
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/MultipartImpl.java   (with props)
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/SimpleContentHandler.java   (with props)
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/StorageBinaryBody.java   (with props)
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/StorageTextBody.java   (with props)
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/StringTextBody.java   (with props)
    james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/dom/
    james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/dom/CopyConstructorTest.java   (contents, props changed)
      - copied, changed from r897165, james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/CopyConstructorTest.java
    james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/dom/EntityTest.java   (contents, props changed)
      - copied, changed from r897165, james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/EntityTest.java
    james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/dom/ExampleMessagesRoundtripTest.java   (contents, props changed)
      - copied, changed from r897165, james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/ExampleMessagesRoundtripTest.java
    james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/dom/HeaderTest.java   (contents, props changed)
      - copied, changed from r897165, james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/HeaderTest.java
    james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/dom/MessageCompleteMailTest.java   (contents, props changed)
      - copied, changed from r897165, james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/MessageCompleteMailTest.java
    james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/dom/MessageHeadlessParserTest.java   (contents, props changed)
      - copied, changed from r897165, james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/MessageHeadlessParserTest.java
    james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/dom/MessageParserTest.java   (contents, props changed)
      - copied, changed from r897165, james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/MessageParserTest.java
    james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/dom/MessageTest.java   (contents, props changed)
      - copied, changed from r897165, james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/MessageTest.java
    james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/dom/MessageWriteToTest.java   (contents, props changed)
      - copied, changed from r897165, james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/MessageWriteToTest.java
    james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/dom/MultipartFormTest.java   (contents, props changed)
      - copied, changed from r897165, james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/MultipartFormTest.java
    james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/SingleBodyCopyTest.java   (with props)
Removed:
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/BinaryBody.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/Body.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/Disposable.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/Entity.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/Header.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/Message.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/Multipart.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/SingleBody.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/TextBody.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/impl/
    james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/CopyConstructorTest.java
    james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/EntityTest.java
    james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/ExampleMessagesRoundtripTest.java
    james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/HeaderTest.java
    james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/MessageCompleteMailTest.java
    james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/MessageHeadlessParserTest.java
    james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/MessageParserTest.java
    james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/MessageTest.java
    james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/MessageWriteToTest.java
    james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/MultipartFormTest.java
    james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/impl/
Modified:
    james/mime4j/branches/cycleclean/benchmark/src/main/java/org/apache/james/mime4j/LongMultipartReadBench.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/util/StringArrayMap.java
    james/mime4j/branches/cycleclean/examples/src/main/java/org/apache/james/mime4j/samples/dom/MultipartMessage.java
    james/mime4j/branches/cycleclean/examples/src/main/java/org/apache/james/mime4j/samples/dom/TextPlainMessage.java
    james/mime4j/branches/cycleclean/examples/src/main/java/org/apache/james/mime4j/samples/transform/TransformMessage.java
    james/mime4j/branches/cycleclean/examples/src/main/java/org/apache/james/mime4j/samples/tree/MessageTree.java

Modified: james/mime4j/branches/cycleclean/benchmark/src/main/java/org/apache/james/mime4j/LongMultipartReadBench.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/benchmark/src/main/java/org/apache/james/mime4j/LongMultipartReadBench.java?rev=897169&r1=897168&r2=897169&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/benchmark/src/main/java/org/apache/james/mime4j/LongMultipartReadBench.java (original)
+++ james/mime4j/branches/cycleclean/benchmark/src/main/java/org/apache/james/mime4j/LongMultipartReadBench.java Fri Jan  8 11:20:17 2010
@@ -25,9 +25,9 @@
 import java.io.InputStream;
 
 import org.apache.james.mime4j.codec.CodecUtil;
-import org.apache.james.mime4j.message.Header;
-import org.apache.james.mime4j.message.impl.MessageImpl;
-import org.apache.james.mime4j.message.impl.SimpleContentHandler;
+import org.apache.james.mime4j.dom.Header;
+import org.apache.james.mime4j.message.MessageImpl;
+import org.apache.james.mime4j.message.SimpleContentHandler;
 import org.apache.james.mime4j.parser.MimeStreamParser;
 import org.apache.james.mime4j.parser.MimeTokenStream;
 import org.apache.james.mime4j.storage.DefaultStorageProvider;

Copied: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/dom/BinaryBody.java (from r897165, james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/BinaryBody.java)
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/dom/BinaryBody.java?p2=james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/dom/BinaryBody.java&p1=james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/BinaryBody.java&r1=897165&r2=897169&rev=897169&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/BinaryBody.java (original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/dom/BinaryBody.java Fri Jan  8 11:20:17 2010
@@ -17,7 +17,7 @@
  * under the License.                                           *
  ****************************************************************/
 
-package org.apache.james.mime4j.message;
+package org.apache.james.mime4j.dom;
 
 /**
  * A body containing binary data.

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

Copied: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/dom/Body.java (from r897165, james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/Body.java)
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/dom/Body.java?p2=james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/dom/Body.java&p1=james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/Body.java&r1=897165&r2=897169&rev=897169&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/Body.java (original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/dom/Body.java Fri Jan  8 11:20:17 2010
@@ -17,7 +17,7 @@
  * under the License.                                           *
  ****************************************************************/
 
-package org.apache.james.mime4j.message;
+package org.apache.james.mime4j.dom;
 
 /**
  * Encapsulates the body of an entity (see RFC 2045).

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

Copied: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/dom/Disposable.java (from r897165, james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/Disposable.java)
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/dom/Disposable.java?p2=james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/dom/Disposable.java&p1=james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/Disposable.java&r1=897165&r2=897169&rev=897169&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/Disposable.java (original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/dom/Disposable.java Fri Jan  8 11:20:17 2010
@@ -17,7 +17,7 @@
  * under the License.                                           *
  ****************************************************************/
 
-package org.apache.james.mime4j.message;
+package org.apache.james.mime4j.dom;
 
 /**
  * A <tt>Disposable</tt> is an object that should be disposed of explicitly

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

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

Copied: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/dom/Entity.java (from r897165, james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/Entity.java)
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/dom/Entity.java?p2=james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/dom/Entity.java&p1=james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/Entity.java&r1=897165&r2=897169&rev=897169&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/Entity.java (original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/dom/Entity.java Fri Jan  8 11:20:17 2010
@@ -17,7 +17,7 @@
  * under the License.                                           *
  ****************************************************************/
 
-package org.apache.james.mime4j.message;
+package org.apache.james.mime4j.dom;
 
 import java.util.Collections;
 import java.util.Date;
@@ -181,7 +181,7 @@
      * 
      * @param textBody
      *            the <code>TextBody</code> to set as body.
-     * @see org.apache.james.mime4j.message.impl.BodyFactory#textBody(String)
+     * @see org.apache.james.mime4j.message.BodyFactory#textBody(String)
      */
     public void setText(TextBody textBody) {
         setText(textBody, "plain");
@@ -198,7 +198,7 @@
      * @param subtype
      *            the text subtype (e.g. &quot;plain&quot;, &quot;html&quot; or
      *            &quot;xml&quot;).
-     * @see org.apache.james.mime4j.message.impl.BodyFactory#textBody(String)
+     * @see org.apache.james.mime4j.message.BodyFactory#textBody(String)
      */
     public void setText(TextBody textBody, String subtype) {
         String mimeType = "text/" + subtype;
@@ -486,7 +486,7 @@
      * Subclasses that need to free resources should override this method and
      * invoke super.dispose().
      * 
-     * @see org.apache.james.mime4j.message.Disposable#dispose()
+     * @see org.apache.james.mime4j.dom.Disposable#dispose()
      */
     public void dispose() {
         if (body != null) {

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

Copied: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/dom/Header.java (from r897165, james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/Header.java)
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/dom/Header.java?p2=james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/dom/Header.java&p1=james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/Header.java&r1=897165&r2=897169&rev=897169&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/Header.java (original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/dom/Header.java Fri Jan  8 11:20:17 2010
@@ -17,7 +17,7 @@
  * under the License.                                           *
  ****************************************************************/
 
-package org.apache.james.mime4j.message;
+package org.apache.james.mime4j.dom;
 
 import java.util.Collections;
 import java.util.HashMap;

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

Copied: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/dom/Message.java (from r897165, james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/Message.java)
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/dom/Message.java?p2=james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/dom/Message.java&p1=james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/Message.java&r1=897165&r2=897169&rev=897169&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/Message.java (original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/dom/Message.java Fri Jan  8 11:20:17 2010
@@ -17,7 +17,7 @@
  * under the License.                                           *
  ****************************************************************/
 
-package org.apache.james.mime4j.message;
+package org.apache.james.mime4j.dom;
 
 import java.io.IOException;
 import java.io.OutputStream;

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

Copied: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/dom/Multipart.java (from r897165, james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/Multipart.java)
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/dom/Multipart.java?p2=james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/dom/Multipart.java&p1=james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/Multipart.java&r1=897165&r2=897169&rev=897169&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/Multipart.java (original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/dom/Multipart.java Fri Jan  8 11:20:17 2010
@@ -17,7 +17,7 @@
  * under the License.                                           *
  ****************************************************************/
 
-package org.apache.james.mime4j.message;
+package org.apache.james.mime4j.dom;
 
 import java.util.Collections;
 import java.util.LinkedList;
@@ -68,14 +68,14 @@
     }
 
     /**
-     * @see org.apache.james.mime4j.message.Body#getParent()
+     * @see org.apache.james.mime4j.dom.Body#getParent()
      */
     public Entity getParent() {
         return parent;
     }
 
     /**
-     * @see org.apache.james.mime4j.message.Body#setParent(org.apache.james.mime4j.message.Entity)
+     * @see org.apache.james.mime4j.dom.Body#setParent(org.apache.james.mime4j.dom.Entity)
      */
     public void setParent(Entity parent) {
         this.parent = parent;
@@ -227,7 +227,7 @@
      * Disposes of the BodyParts of this Multipart. Note that the dispose call
      * does not get forwarded to the parent entity of this Multipart.
      * 
-     * @see org.apache.james.mime4j.message.Disposable#dispose()
+     * @see org.apache.james.mime4j.dom.Disposable#dispose()
      */
     public void dispose() {
         for (Entity bodyPart : bodyParts) {

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

Copied: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/dom/SingleBody.java (from r897165, james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/SingleBody.java)
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/dom/SingleBody.java?p2=james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/dom/SingleBody.java&p1=james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/SingleBody.java&r1=897165&r2=897169&rev=897169&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/SingleBody.java (original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/dom/SingleBody.java Fri Jan  8 11:20:17 2010
@@ -17,7 +17,7 @@
  * under the License.                                           *
  ****************************************************************/
 
-package org.apache.james.mime4j.message;
+package org.apache.james.mime4j.dom;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -39,14 +39,14 @@
     }
 
     /**
-     * @see org.apache.james.mime4j.message.Body#getParent()
+     * @see org.apache.james.mime4j.dom.Body#getParent()
      */
     public Entity getParent() {
         return parent;
     }
 
     /**
-     * @see org.apache.james.mime4j.message.Body#setParent(org.apache.james.mime4j.message.Entity)
+     * @see org.apache.james.mime4j.dom.Body#setParent(org.apache.james.mime4j.dom.Entity)
      */
     public void setParent(Entity parent) {
         this.parent = parent;
@@ -115,7 +115,7 @@
      * 
      * The default implementation of this method does nothing.
      * 
-     * @see org.apache.james.mime4j.message.Disposable#dispose()
+     * @see org.apache.james.mime4j.dom.Disposable#dispose()
      */
     public void dispose() {
     }

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

Copied: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/dom/TextBody.java (from r897165, james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/TextBody.java)
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/dom/TextBody.java?p2=james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/dom/TextBody.java&p1=james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/TextBody.java&r1=897165&r2=897169&rev=897169&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/TextBody.java (original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/dom/TextBody.java Fri Jan  8 11:20:17 2010
@@ -17,7 +17,7 @@
  * under the License.                                           *
  ****************************************************************/
 
-package org.apache.james.mime4j.message;
+package org.apache.james.mime4j.dom;
 
 import java.io.IOException;
 import java.io.Reader;

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

Added: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/BodyCopier.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/BodyCopier.java?rev=897169&view=auto
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/BodyCopier.java (added)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/BodyCopier.java Fri Jan  8 11:20:17 2010
@@ -0,0 +1,74 @@
+/****************************************************************
+ * 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 org.apache.james.mime4j.dom.Body;
+import org.apache.james.mime4j.dom.Disposable;
+import org.apache.james.mime4j.dom.Message;
+import org.apache.james.mime4j.dom.Multipart;
+import org.apache.james.mime4j.dom.SingleBody;
+
+/**
+ * Utility class for copying message bodies.
+ */
+public class BodyCopier {
+
+    private BodyCopier() {
+    }
+
+    /**
+     * Returns a copy of the given {@link Body} that can be used (and modified)
+     * independently of the original. The copy should be
+     * {@link Disposable#dispose() disposed of} when it is no longer needed.
+     * <p>
+     * The {@link Body#getParent() parent} of the returned copy is
+     * <code>null</code>, that is, the copy is detached from the parent
+     * entity of the original.
+     * 
+     * @param body
+     *            body to copy.
+     * @return a copy of the given body.
+     * @throws UnsupportedOperationException
+     *             if <code>body</code> is an instance of {@link SingleBody}
+     *             that does not support the {@link SingleBody#copy() copy()}
+     *             operation (or contains such a <code>SingleBody</code>).
+     * @throws IllegalArgumentException
+     *             if <code>body</code> is <code>null</code> or
+     *             <code>body</code> is a <code>Body</code> that is neither
+     *             a {@link MessageImpl}, {@link Multipart} or {@link SingleBody}
+     *             (or contains such a <code>Body</code>).
+     */
+    public static Body copy(Body body) {
+        if (body == null)
+            throw new IllegalArgumentException("Body is null");
+
+        if (body instanceof Message)
+            return new MessageImpl((Message) body);
+
+        if (body instanceof Multipart)
+            return new MultipartImpl((Multipart) body);
+
+        if (body instanceof SingleBody)
+            return ((SingleBody) body).copy();
+
+        throw new IllegalArgumentException("Unsupported body class");
+    }
+
+}

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

Added: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/BodyFactory.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/BodyFactory.java?rev=897169&view=auto
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/BodyFactory.java (added)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/BodyFactory.java Fri Jan  8 11:20:17 2010
@@ -0,0 +1,314 @@
+/****************************************************************
+ * 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;
+import java.io.InputStream;
+import java.nio.charset.Charset;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.james.mime4j.dom.BinaryBody;
+import org.apache.james.mime4j.dom.Disposable;
+import org.apache.james.mime4j.dom.SingleBody;
+import org.apache.james.mime4j.dom.TextBody;
+import org.apache.james.mime4j.storage.DefaultStorageProvider;
+import org.apache.james.mime4j.storage.MultiReferenceStorage;
+import org.apache.james.mime4j.storage.Storage;
+import org.apache.james.mime4j.storage.StorageProvider;
+import org.apache.james.mime4j.util.CharsetUtil;
+
+/**
+ * Factory for creating message bodies.
+ */
+public class BodyFactory {
+
+    private static Log log = LogFactory.getLog(BodyFactory.class);
+
+    private static final Charset FALLBACK_CHARSET = CharsetUtil.DEFAULT_CHARSET;
+
+    private StorageProvider storageProvider;
+
+    /**
+     * Creates a new <code>BodyFactory</code> instance that uses the default
+     * storage provider for creating message bodies from input streams.
+     */
+    public BodyFactory() {
+        this.storageProvider = DefaultStorageProvider.getInstance();
+    }
+
+    /**
+     * Creates a new <code>BodyFactory</code> instance that uses the given
+     * storage provider for creating message bodies from input streams.
+     * 
+     * @param storageProvider
+     *            a storage provider or <code>null</code> to use the default
+     *            one.
+     */
+    public BodyFactory(StorageProvider storageProvider) {
+        if (storageProvider == null)
+            storageProvider = DefaultStorageProvider.getInstance();
+
+        this.storageProvider = storageProvider;
+    }
+
+    /**
+     * Returns the <code>StorageProvider</code> this <code>BodyFactory</code>
+     * uses to create message bodies from input streams.
+     * 
+     * @return a <code>StorageProvider</code>.
+     */
+    public StorageProvider getStorageProvider() {
+        return storageProvider;
+    }
+
+    /**
+     * Creates a {@link BinaryBody} that holds the content of the given input
+     * stream.
+     * 
+     * @param is
+     *            input stream to create a message body from.
+     * @return a binary body.
+     * @throws IOException
+     *             if an I/O error occurs.
+     */
+    public BinaryBody binaryBody(InputStream is) throws IOException {
+        if (is == null)
+            throw new IllegalArgumentException();
+
+        Storage storage = storageProvider.store(is);
+        return new StorageBinaryBody(new MultiReferenceStorage(storage));
+    }
+
+    /**
+     * Creates a {@link BinaryBody} that holds the content of the given
+     * {@link Storage}.
+     * <p>
+     * Note that the caller must not invoke {@link Storage#delete() delete()} on
+     * the given <code>Storage</code> object after it has been passed to this
+     * method. Instead the message body created by this method takes care of
+     * deleting the storage when it gets disposed of (see
+     * {@link Disposable#dispose()}).
+     * 
+     * @param storage
+     *            storage to create a message body from.
+     * @return a binary body.
+     * @throws IOException
+     *             if an I/O error occurs.
+     */
+    public BinaryBody binaryBody(Storage storage) throws IOException {
+        if (storage == null)
+            throw new IllegalArgumentException();
+
+        return new StorageBinaryBody(new MultiReferenceStorage(storage));
+    }
+
+    /**
+     * Creates a {@link TextBody} that holds the content of the given input
+     * stream.
+     * <p>
+     * &quot;us-ascii&quot; is used to decode the byte content of the
+     * <code>Storage</code> into a character stream when calling
+     * {@link TextBody#getReader() getReader()} on the returned object.
+     * 
+     * @param is
+     *            input stream to create a message body from.
+     * @return a text body.
+     * @throws IOException
+     *             if an I/O error occurs.
+     */
+    public TextBody textBody(InputStream is) throws IOException {
+        if (is == null)
+            throw new IllegalArgumentException();
+
+        Storage storage = storageProvider.store(is);
+        return new StorageTextBody(new MultiReferenceStorage(storage),
+                CharsetUtil.DEFAULT_CHARSET);
+    }
+
+    /**
+     * Creates a {@link TextBody} that holds the content of the given input
+     * stream.
+     * <p>
+     * The charset corresponding to the given MIME charset name is used to
+     * decode the byte content of the input stream into a character stream when
+     * calling {@link TextBody#getReader() getReader()} on the returned object.
+     * If the MIME charset has no corresponding Java charset or the Java charset
+     * cannot be used for decoding then &quot;us-ascii&quot; is used instead.
+     * 
+     * @param is
+     *            input stream to create a message body from.
+     * @param mimeCharset
+     *            name of a MIME charset.
+     * @return a text body.
+     * @throws IOException
+     *             if an I/O error occurs.
+     */
+    public TextBody textBody(InputStream is, String mimeCharset)
+            throws IOException {
+        if (is == null)
+            throw new IllegalArgumentException();
+        if (mimeCharset == null)
+            throw new IllegalArgumentException();
+
+        Storage storage = storageProvider.store(is);
+        Charset charset = toJavaCharset(mimeCharset, false);
+        return new StorageTextBody(new MultiReferenceStorage(storage), charset);
+    }
+
+    /**
+     * Creates a {@link TextBody} that holds the content of the given
+     * {@link Storage}.
+     * <p>
+     * &quot;us-ascii&quot; is used to decode the byte content of the
+     * <code>Storage</code> into a character stream when calling
+     * {@link TextBody#getReader() getReader()} on the returned object.
+     * <p>
+     * Note that the caller must not invoke {@link Storage#delete() delete()} on
+     * the given <code>Storage</code> object after it has been passed to this
+     * method. Instead the message body created by this method takes care of
+     * deleting the storage when it gets disposed of (see
+     * {@link Disposable#dispose()}).
+     * 
+     * @param storage
+     *            storage to create a message body from.
+     * @return a text body.
+     * @throws IOException
+     *             if an I/O error occurs.
+     */
+    public TextBody textBody(Storage storage) throws IOException {
+        if (storage == null)
+            throw new IllegalArgumentException();
+
+        return new StorageTextBody(new MultiReferenceStorage(storage),
+                CharsetUtil.DEFAULT_CHARSET);
+    }
+
+    /**
+     * Creates a {@link TextBody} that holds the content of the given
+     * {@link Storage}.
+     * <p>
+     * The charset corresponding to the given MIME charset name is used to
+     * decode the byte content of the <code>Storage</code> into a character
+     * stream when calling {@link TextBody#getReader() getReader()} on the
+     * returned object. If the MIME charset has no corresponding Java charset or
+     * the Java charset cannot be used for decoding then &quot;us-ascii&quot; is
+     * used instead.
+     * <p>
+     * Note that the caller must not invoke {@link Storage#delete() delete()} on
+     * the given <code>Storage</code> object after it has been passed to this
+     * method. Instead the message body created by this method takes care of
+     * deleting the storage when it gets disposed of (see
+     * {@link Disposable#dispose()}).
+     * 
+     * @param storage
+     *            storage to create a message body from.
+     * @param mimeCharset
+     *            name of a MIME charset.
+     * @return a text body.
+     * @throws IOException
+     *             if an I/O error occurs.
+     */
+    public TextBody textBody(Storage storage, String mimeCharset)
+            throws IOException {
+        if (storage == null)
+            throw new IllegalArgumentException();
+        if (mimeCharset == null)
+            throw new IllegalArgumentException();
+
+        Charset charset = toJavaCharset(mimeCharset, false);
+        return new StorageTextBody(new MultiReferenceStorage(storage), charset);
+    }
+
+    /**
+     * Creates a {@link TextBody} that holds the content of the given string.
+     * <p>
+     * &quot;us-ascii&quot; is used to encode the characters of the string into
+     * a byte stream when calling
+     * {@link SingleBody#writeTo(java.io.OutputStream) writeTo(OutputStream)} on
+     * the returned object.
+     * 
+     * @param text
+     *            text to create a message body from.
+     * @return a text body.
+     */
+    public TextBody textBody(String text) {
+        if (text == null)
+            throw new IllegalArgumentException();
+
+        return new StringTextBody(text, CharsetUtil.DEFAULT_CHARSET);
+    }
+
+    /**
+     * Creates a {@link TextBody} that holds the content of the given string.
+     * <p>
+     * The charset corresponding to the given MIME charset name is used to
+     * encode the characters of the string into a byte stream when calling
+     * {@link SingleBody#writeTo(java.io.OutputStream) writeTo(OutputStream)} on
+     * the returned object. If the MIME charset has no corresponding Java
+     * charset or the Java charset cannot be used for encoding then
+     * &quot;us-ascii&quot; is used instead.
+     * 
+     * @param text
+     *            text to create a message body from.
+     * @param mimeCharset
+     *            name of a MIME charset.
+     * @return a text body.
+     */
+    public TextBody textBody(String text, String mimeCharset) {
+        if (text == null)
+            throw new IllegalArgumentException();
+        if (mimeCharset == null)
+            throw new IllegalArgumentException();
+
+        Charset charset = toJavaCharset(mimeCharset, true);
+        return new StringTextBody(text, charset);
+    }
+
+    private static Charset toJavaCharset(String mimeCharset, boolean forEncoding) {
+        String charset = CharsetUtil.toJavaCharset(mimeCharset);
+        if (charset == null) {
+            if (log.isWarnEnabled())
+                log.warn("MIME charset '" + mimeCharset + "' has no "
+                        + "corresponding Java charset. Using "
+                        + FALLBACK_CHARSET + " instead.");
+            return FALLBACK_CHARSET;
+        }
+
+        if (forEncoding && !CharsetUtil.isEncodingSupported(charset)) {
+            if (log.isWarnEnabled())
+                log.warn("MIME charset '" + mimeCharset
+                        + "' does not support encoding. Using "
+                        + FALLBACK_CHARSET + " instead.");
+            return FALLBACK_CHARSET;
+        }
+
+        if (!forEncoding && !CharsetUtil.isDecodingSupported(charset)) {
+            if (log.isWarnEnabled())
+                log.warn("MIME charset '" + mimeCharset
+                        + "' does not support decoding. Using "
+                        + FALLBACK_CHARSET + " instead.");
+            return FALLBACK_CHARSET;
+        }
+
+        return Charset.forName(charset);
+    }
+
+}

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

Added: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/BodyPart.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/BodyPart.java?rev=897169&view=auto
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/BodyPart.java (added)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/BodyPart.java Fri Jan  8 11:20:17 2010
@@ -0,0 +1,116 @@
+/****************************************************************
+ * 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.util.Date;
+import java.util.Map;
+
+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.Multipart;
+import org.apache.james.mime4j.dom.SingleBody;
+import org.apache.james.mime4j.field.ContentDispositionField;
+import org.apache.james.mime4j.field.ContentTransferEncodingField;
+import org.apache.james.mime4j.field.ContentTypeField;
+import org.apache.james.mime4j.field.impl.ContentTransferEncodingFieldImpl;
+import org.apache.james.mime4j.field.impl.ContentTypeFieldImpl;
+import org.apache.james.mime4j.field.impl.Fields;
+import org.apache.james.mime4j.util.MimeUtil;
+
+/**
+ * Represents a MIME body part  (see RFC 2045).
+ */
+public class BodyPart extends Entity {
+
+    /**
+     * Creates a new empty <code>BodyPart</code>.
+     */
+    public BodyPart() {
+    }
+
+    /**
+     * Creates a new <code>BodyPart</code> from the specified
+     * <code>BodyPart</code>. The <code>BodyPart</code> instance is initialized
+     * with copies of header and body of the specified <code>BodyPart</code>.
+     * The parent entity of the new body part is <code>null</code>.
+     * 
+     * @param other
+     *            body part to copy.
+     * @throws UnsupportedOperationException
+     *             if <code>other</code> contains a {@link SingleBody} that
+     *             does not support the {@link SingleBody#copy() copy()}
+     *             operation.
+     * @throws IllegalArgumentException
+     *             if <code>other</code> contains a <code>Body</code> that
+     *             is neither a {@link Message}, {@link Multipart} or
+     *             {@link SingleBody}.
+     */
+    public BodyPart(Entity other) {
+        if (other.getHeader() != null) {
+            setHeader(new Header(other.getHeader()));
+        }
+
+        if (other.getBody() != null) {
+            Body bodyCopy = BodyCopier.copy(other.getBody());
+            setBody(bodyCopy);
+        }
+    }
+
+	@Override
+	protected String newUniqueBoundary() {
+		return MimeUtil.createUniqueBoundary();
+	}
+
+    protected ContentDispositionField newContentDisposition(
+            String dispositionType, String filename, long size,
+            Date creationDate, Date modificationDate, Date readDate) {
+        return Fields.contentDisposition(dispositionType, filename, size,
+                creationDate, modificationDate, readDate);
+    }
+
+    protected ContentDispositionField newContentDisposition(
+            String dispositionType, Map<String, String> parameters) {
+        return Fields.contentDisposition(dispositionType, parameters);
+    }
+
+    protected ContentTypeField newContentType(String mimeType,
+            Map<String, String> parameters) {
+        return Fields.contentType(mimeType, parameters);
+    }
+
+    protected ContentTransferEncodingField newContentTransferEncoding(
+            String contentTransferEncoding) {
+        return Fields.contentTransferEncoding(contentTransferEncoding);
+    }
+
+    protected String calcTransferEncoding(ContentTransferEncodingField f) {
+        return ContentTransferEncodingFieldImpl.getEncoding(f);
+    }
+
+    protected String calcMimeType(ContentTypeField child, ContentTypeField parent) {
+        return ContentTypeFieldImpl.getMimeType(child, parent);
+    }
+
+    protected String calcCharset(ContentTypeField contentType) {
+        return ContentTypeFieldImpl.getCharset(contentType); 
+    }
+
+}

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

Added: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/HeaderImpl.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/HeaderImpl.java?rev=897169&view=auto
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/HeaderImpl.java (added)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/HeaderImpl.java Fri Jan  8 11:20:17 2010
@@ -0,0 +1,90 @@
+/****************************************************************
+ * 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;
+import java.io.InputStream;
+
+import org.apache.james.mime4j.MimeException;
+import org.apache.james.mime4j.MimeIOException;
+import org.apache.james.mime4j.dom.Header;
+import org.apache.james.mime4j.field.Field;
+import org.apache.james.mime4j.field.impl.DefaultFieldParser;
+import org.apache.james.mime4j.parser.MimeStreamParser;
+import org.apache.james.mime4j.stream.AbstractContentHandler;
+import org.apache.james.mime4j.stream.RawField;
+
+/**
+ * The header of an entity (see RFC 2045).
+ */
+public class HeaderImpl extends Header {
+
+    /**
+     * Creates a new empty <code>Header</code>.
+     */
+    public HeaderImpl() {
+    }
+
+    /**
+     * Creates a new <code>Header</code> from the specified
+     * <code>Header</code>. The <code>Header</code> instance is initialized
+     * with a copy of the list of {@link Field}s of the specified
+     * <code>Header</code>. The <code>Field</code> objects are not copied
+     * because they are immutable and can safely be shared between headers.
+     * 
+     * @param other
+     *            header to copy.
+     */
+    public HeaderImpl(Header other) {
+        for (Field otherField : other.getFields()) {
+            addField(otherField);
+        }
+    }
+
+    /**
+     * Creates a new <code>Header</code> from the specified stream.
+     * 
+     * @param is the stream to read the header from.
+     * 
+     * @throws IOException on I/O errors.
+     * @throws MimeIOException on MIME protocol violations.
+     */
+    public HeaderImpl(InputStream is) 
+            throws IOException, MimeIOException {
+        final MimeStreamParser parser = new MimeStreamParser();
+        parser.setContentHandler(new AbstractContentHandler() {
+            @Override
+            public void endHeader() {
+                parser.stop();
+            }
+            @Override
+            public void field(RawField field) throws MimeException {
+                Field parsedField = DefaultFieldParser.parse(field.getRaw()); 
+                addField(parsedField);
+            }
+        });
+        try {
+            parser.parse(is);
+        } catch (MimeException ex) {
+            throw new MimeIOException(ex);
+        }
+    }
+
+}

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

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

Added: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/MessageBuilder.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/MessageBuilder.java?rev=897169&view=auto
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/MessageBuilder.java (added)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/MessageBuilder.java Fri Jan  8 11:20:17 2010
@@ -0,0 +1,236 @@
+/****************************************************************
+ * 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;
+import java.io.InputStream;
+import java.util.Stack;
+
+import org.apache.james.mime4j.MimeException;
+import org.apache.james.mime4j.codec.DecodeMonitor;
+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.Multipart;
+import org.apache.james.mime4j.field.Field;
+import org.apache.james.mime4j.field.impl.DefaultFieldParser;
+import org.apache.james.mime4j.field.impl.LoggingMonitor;
+import org.apache.james.mime4j.parser.MimeStreamParser;
+import org.apache.james.mime4j.storage.StorageProvider;
+import org.apache.james.mime4j.stream.BodyDescriptor;
+import org.apache.james.mime4j.stream.ContentHandler;
+import org.apache.james.mime4j.stream.RawField;
+import org.apache.james.mime4j.util.ByteArrayBuffer;
+import org.apache.james.mime4j.util.ByteSequence;
+
+/**
+ * A <code>ContentHandler</code> for building an <code>Entity</code> to be
+ * used in conjunction with a {@link MimeStreamParser}.
+ */
+public class MessageBuilder implements ContentHandler {
+
+    private final Entity entity;
+    private final BodyFactory bodyFactory;
+    private Stack<Object> stack = new Stack<Object>();
+    private final DecodeMonitor monitor;
+    
+    public MessageBuilder(Entity entity) {
+        this(entity, null);
+    }
+    
+    public MessageBuilder(Entity entity, StorageProvider storageProvider) {
+        this(entity, storageProvider, LoggingMonitor.MONITOR);
+    }
+    
+    public MessageBuilder(Entity entity, StorageProvider storageProvider, DecodeMonitor monitor) {
+        this.entity = entity;
+        this.bodyFactory = new BodyFactory(storageProvider);
+        this.monitor = monitor != null ? monitor : LoggingMonitor.MONITOR;
+    }
+    
+    private void expect(Class<?> c) {
+        if (!c.isInstance(stack.peek())) {
+            throw new IllegalStateException("Internal stack error: "
+                    + "Expected '" + c.getName() + "' found '"
+                    + stack.peek().getClass().getName() + "'");
+        }
+    }
+    
+    /**
+     * @see org.apache.james.mime4j.stream.ContentHandler#startMessage()
+     */
+    public void startMessage() throws MimeException {
+        if (stack.isEmpty()) {
+            stack.push(this.entity);
+        } else {
+            expect(Entity.class);
+            Message m = new MessageImpl();
+            ((Entity) stack.peek()).setBody(m);
+            stack.push(m);
+        }
+    }
+    
+    /**
+     * @see org.apache.james.mime4j.stream.ContentHandler#endMessage()
+     */
+    public void endMessage() throws MimeException {
+        expect(Message.class);
+        stack.pop();
+    }
+    
+    /**
+     * @see org.apache.james.mime4j.stream.ContentHandler#startHeader()
+     */
+    public void startHeader() throws MimeException {
+        stack.push(new Header());
+    }
+    
+    /**
+     * @see org.apache.james.mime4j.stream.ContentHandler#field(Field)
+     */
+    public void field(RawField field) throws MimeException {
+        expect(Header.class);
+        Field parsedField = DefaultFieldParser.parse(field.getRaw(), monitor); 
+        ((Header) stack.peek()).addField(parsedField);
+    }
+    
+    /**
+     * @see org.apache.james.mime4j.stream.ContentHandler#endHeader()
+     */
+    public void endHeader() throws MimeException {
+        expect(Header.class);
+        Header h = (Header) stack.pop();
+        expect(Entity.class);
+        ((Entity) stack.peek()).setHeader(h);
+    }
+    
+    /**
+     * @see org.apache.james.mime4j.stream.ContentHandler#startMultipart(org.apache.james.mime4j.stream.BodyDescriptor)
+     */
+    public void startMultipart(final BodyDescriptor bd) throws MimeException {
+        expect(Entity.class);
+        
+        final Entity e = (Entity) stack.peek();
+        final String subType = bd.getSubType();
+        final Multipart multiPart = new MultipartImpl(subType);
+        e.setBody(multiPart);
+        stack.push(multiPart);
+    }
+    
+    /**
+     * @see org.apache.james.mime4j.stream.ContentHandler#body(org.apache.james.mime4j.stream.BodyDescriptor, java.io.InputStream)
+     */
+    public void body(BodyDescriptor bd, final InputStream is) throws MimeException, IOException {
+        expect(Entity.class);
+        
+        // NO NEED TO MANUALLY RUN DECODING. 
+        // The parser has a "setContentDecoding" method. We should
+        // simply instantiate the MimeStreamParser with that method.
+        
+        // final String enc = bd.getTransferEncoding();
+        
+        final Body body;
+        
+        /*
+        final InputStream decodedStream;
+        if (MimeUtil.ENC_BASE64.equals(enc)) {
+            decodedStream = new Base64InputStream(is);
+        } else if (MimeUtil.ENC_QUOTED_PRINTABLE.equals(enc)) {
+            decodedStream = new QuotedPrintableInputStream(is);
+        } else {
+            decodedStream = is;
+        }
+        */
+        
+        if (bd.getMimeType().startsWith("text/")) {
+            body = bodyFactory.textBody(is, bd.getCharset());
+        } else {
+            body = bodyFactory.binaryBody(is);
+        }
+        
+        Entity entity = ((Entity) stack.peek());
+        entity.setBody(body);
+    }
+    
+    /**
+     * @see org.apache.james.mime4j.stream.ContentHandler#endMultipart()
+     */
+    public void endMultipart() throws MimeException {
+        stack.pop();
+    }
+    
+    /**
+     * @see org.apache.james.mime4j.stream.ContentHandler#startBodyPart()
+     */
+    public void startBodyPart() throws MimeException {
+        expect(Multipart.class);
+        
+        BodyPart bodyPart = new BodyPart();
+        ((Multipart) stack.peek()).addBodyPart(bodyPart);
+        stack.push(bodyPart);
+    }
+    
+    /**
+     * @see org.apache.james.mime4j.stream.ContentHandler#endBodyPart()
+     */
+    public void endBodyPart() throws MimeException {
+        expect(BodyPart.class);
+        stack.pop();
+    }
+    
+    /**
+     * @see org.apache.james.mime4j.stream.ContentHandler#epilogue(java.io.InputStream)
+     */
+    public void epilogue(InputStream is) throws MimeException, IOException {
+        expect(MultipartImpl.class);
+        ByteSequence bytes = loadStream(is);
+        ((MultipartImpl) stack.peek()).setEpilogueRaw(bytes);
+    }
+    
+    /**
+     * @see org.apache.james.mime4j.stream.ContentHandler#preamble(java.io.InputStream)
+     */
+    public void preamble(InputStream is) throws MimeException, IOException {
+        expect(MultipartImpl.class);
+        ByteSequence bytes = loadStream(is);
+        ((MultipartImpl) stack.peek()).setPreambleRaw(bytes);
+    }
+    
+    /**
+     * Unsupported.
+     * @see org.apache.james.mime4j.stream.ContentHandler#raw(java.io.InputStream)
+     */
+    public void raw(InputStream is) throws MimeException, IOException {
+        throw new UnsupportedOperationException("Not supported");
+    }
+
+    private static ByteSequence loadStream(InputStream in) throws IOException {
+        ByteArrayBuffer bab = new ByteArrayBuffer(64);
+
+        int b;
+        while ((b = in.read()) != -1) {
+            bab.append(b);
+        }
+
+        return bab;
+    }
+
+}
\ No newline at end of file

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

Propchange: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/MessageBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

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

Added: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/MessageImpl.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/MessageImpl.java?rev=897169&view=auto
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/MessageImpl.java (added)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/MessageImpl.java Fri Jan  8 11:20:17 2010
@@ -0,0 +1,244 @@
+/****************************************************************
+ * 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;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Collection;
+import java.util.Date;
+import java.util.Map;
+import java.util.TimeZone;
+
+import org.apache.james.mime4j.MimeException;
+import org.apache.james.mime4j.MimeIOException;
+import org.apache.james.mime4j.codec.DecodeMonitor;
+import org.apache.james.mime4j.dom.Body;
+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.SingleBody;
+import org.apache.james.mime4j.field.AddressListField;
+import org.apache.james.mime4j.field.ContentDispositionField;
+import org.apache.james.mime4j.field.ContentTransferEncodingField;
+import org.apache.james.mime4j.field.ContentTypeField;
+import org.apache.james.mime4j.field.DateTimeField;
+import org.apache.james.mime4j.field.FieldName;
+import org.apache.james.mime4j.field.MailboxField;
+import org.apache.james.mime4j.field.MailboxListField;
+import org.apache.james.mime4j.field.UnstructuredField;
+import org.apache.james.mime4j.field.address.Address;
+import org.apache.james.mime4j.field.address.Mailbox;
+import org.apache.james.mime4j.field.impl.ContentTransferEncodingFieldImpl;
+import org.apache.james.mime4j.field.impl.ContentTypeFieldImpl;
+import org.apache.james.mime4j.field.impl.Fields;
+import org.apache.james.mime4j.field.impl.LoggingMonitor;
+import org.apache.james.mime4j.parser.MimeStreamParser;
+import org.apache.james.mime4j.storage.DefaultStorageProvider;
+import org.apache.james.mime4j.storage.StorageProvider;
+import org.apache.james.mime4j.stream.MimeEntityConfig;
+import org.apache.james.mime4j.util.MimeUtil;
+
+/**
+ * Represents a MIME message. The following code parses a stream into a
+ * <code>Message</code> object.
+ * 
+ * <pre>
+ * Message msg = new Message(new FileInputStream(&quot;mime.msg&quot;));
+ * </pre>
+ */
+public class MessageImpl extends Message {
+
+    private DecodeMonitor monitor;
+
+    /**
+     * Creates a new empty <code>Message</code>.
+     */
+    public MessageImpl() {
+    }
+
+    /**
+     * Creates a new <code>Message</code> from the specified
+     * <code>Message</code>. The <code>Message</code> instance is
+     * initialized with copies of header and body of the specified
+     * <code>Message</code>. The parent entity of the new message is
+     * <code>null</code>.
+     * 
+     * @param other
+     *            message to copy.
+     * @throws UnsupportedOperationException
+     *             if <code>other</code> contains a {@link SingleBody} that
+     *             does not support the {@link SingleBody#copy() copy()}
+     *             operation.
+     * @throws IllegalArgumentException
+     *             if <code>other</code> contains a <code>Body</code> that
+     *             is neither a {@link MessageImpl}, {@link Multipart} or
+     *             {@link SingleBody}.
+     */
+    public MessageImpl(Message other) {
+        if (other.getHeader() != null) {
+            setHeader(new Header(other.getHeader()));
+        }
+
+        if (other.getBody() != null) {
+            Body bodyCopy = BodyCopier.copy(other.getBody());
+            setBody(bodyCopy);
+        }
+    }
+
+    /**
+     * 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 MessageImpl(InputStream is) throws IOException, MimeIOException {
+        this(is, null, DefaultStorageProvider.getInstance());
+    }
+
+    /**
+     * 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 MessageImpl(InputStream is, MimeEntityConfig config) throws IOException,
+            MimeIOException {
+        this(is, config, DefaultStorageProvider.getInstance());
+    }
+
+    /**
+     * 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.
+     * @throws IOException
+     *             on I/O errors.
+     * @throws MimeIOException
+     *             on MIME protocol violations.
+     */
+    public MessageImpl(InputStream is, MimeEntityConfig config,
+            StorageProvider storageProvider, DecodeMonitor monitor) throws IOException,
+            MimeIOException {
+        try {
+            MimeStreamParser parser = new MimeStreamParser(config, monitor);
+            parser.setContentDecoding(true);
+            this.monitor = monitor != null ? monitor : LoggingMonitor.MONITOR;
+            parser.setContentHandler(new MessageBuilder(this, storageProvider, this.monitor));
+            parser.parse(is);
+        } catch (MimeException e) {
+            throw new MimeIOException(e);
+        }
+    }
+
+    public MessageImpl(InputStream is, MimeEntityConfig config,
+            StorageProvider storageProvider) throws IOException, MimeIOException {
+        this(is, config, storageProvider, LoggingMonitor.MONITOR);
+    }
+
+    /**
+     * @see org.apache.james.mime4j.message.Message#writeTo(java.io.OutputStream)
+     */
+    public void writeTo(OutputStream out) throws IOException {
+        MessageWriter.DEFAULT.writeEntity(this, out);
+    }
+
+	@Override
+	protected String newUniqueBoundary() {
+		return MimeUtil.createUniqueBoundary();
+	}
+
+	protected UnstructuredField newMessageId(String hostname) {
+		return Fields.messageId(hostname);
+	}
+
+	protected DateTimeField newDate(Date date, TimeZone zone) {
+		return Fields.date(FieldName.DATE, date, zone);
+	}
+
+	protected MailboxField newMailbox(String fieldName, Mailbox mailbox) {
+		return Fields.mailbox(fieldName, mailbox);
+	}
+
+	protected MailboxListField newMailboxList(String fieldName,
+			Collection<Mailbox> mailboxes) {
+		return Fields.mailboxList(fieldName, mailboxes);
+	}
+
+	protected AddressListField newAddressList(String fieldName,
+			Collection<Address> addresses) {
+		return Fields.addressList(fieldName, addresses);
+	}
+
+	protected UnstructuredField newSubject(String subject) {
+		return Fields.subject(subject);
+	}
+
+    protected ContentDispositionField newContentDisposition(
+            String dispositionType, String filename, long size,
+            Date creationDate, Date modificationDate, Date readDate) {
+        return Fields.contentDisposition(dispositionType, filename, size,
+                creationDate, modificationDate, readDate);
+    }
+
+    protected ContentDispositionField newContentDisposition(
+            String dispositionType, Map<String, String> parameters) {
+        return Fields.contentDisposition(dispositionType, parameters);
+    }
+
+    protected ContentTypeField newContentType(String mimeType,
+            Map<String, String> parameters) {
+        return Fields.contentType(mimeType, parameters);
+    }
+
+    protected ContentTransferEncodingField newContentTransferEncoding(
+            String contentTransferEncoding) {
+        return Fields.contentTransferEncoding(contentTransferEncoding);
+    }
+
+    protected String calcTransferEncoding(ContentTransferEncodingField f) {
+        return ContentTransferEncodingFieldImpl.getEncoding(f);
+    }
+
+    protected String calcMimeType(ContentTypeField child, ContentTypeField parent) {
+        return ContentTypeFieldImpl.getMimeType(child, parent);
+    }
+
+    protected String calcCharset(ContentTypeField contentType) {
+        return ContentTypeFieldImpl.getCharset(contentType); 
+    }
+
+}

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

Added: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/MessageWriter.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/MessageWriter.java?rev=897169&view=auto
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/MessageWriter.java (added)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/MessageWriter.java Fri Jan  8 11:20:17 2010
@@ -0,0 +1,237 @@
+/****************************************************************
+ * 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;
+import java.io.OutputStream;
+
+import org.apache.james.mime4j.codec.CodecUtil;
+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.Multipart;
+import org.apache.james.mime4j.dom.SingleBody;
+import org.apache.james.mime4j.field.ContentTypeField;
+import org.apache.james.mime4j.field.Field;
+import org.apache.james.mime4j.field.FieldName;
+import org.apache.james.mime4j.util.ByteArrayBuffer;
+import org.apache.james.mime4j.util.ByteSequence;
+import org.apache.james.mime4j.util.ContentUtil;
+import org.apache.james.mime4j.util.MimeUtil;
+
+/**
+ * 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 MessageWriter {
+
+    private static final byte[] CRLF = { '\r', '\n' };
+    private static final byte[] DASHES = { '-', '-' };
+
+    /**
+     * The default message writer.
+     */
+    public static final MessageWriter DEFAULT = new MessageWriter();
+
+    /**
+     * Protected constructor prevents direct instantiation.
+     */
+    protected MessageWriter() {
+    }
+
+    /**
+     * Write the specified <code>Body</code> to the specified
+     * <code>OutputStream</code>.
+     * 
+     * @param body
+     *            the <code>Body</code> to write.
+     * @param out
+     *            the OutputStream to write to.
+     * @throws IOException
+     *             if an I/O error occurs.
+     */
+    public void writeBody(Body body, OutputStream out) throws IOException {
+        if (body instanceof Message) {
+            writeEntity((Message) body, out);
+        } else if (body instanceof Multipart) {
+            writeMultipart((Multipart) body, out);
+        } else if (body instanceof SingleBody) {
+            ((SingleBody) body).writeTo(out);
+        } else
+            throw new IllegalArgumentException("Unsupported body class");
+    }
+
+    /**
+     * Write the specified <code>Entity</code> to the specified
+     * <code>OutputStream</code>.
+     * 
+     * @param entity
+     *            the <code>Entity</code> to write.
+     * @param out
+     *            the OutputStream to write to.
+     * @throws IOException
+     *             if an I/O error occurs.
+     */
+    public void writeEntity(Entity entity, OutputStream out) throws IOException {
+        final Header header = entity.getHeader();
+        if (header == null)
+            throw new IllegalArgumentException("Missing header");
+
+        writeHeader(header, out);
+
+        final Body body = entity.getBody();
+        if (body == null)
+            throw new IllegalArgumentException("Missing body");
+
+        boolean binaryBody = body instanceof BinaryBody;
+        OutputStream encOut = encodeStream(out, entity
+                .getContentTransferEncoding(), binaryBody);
+
+        writeBody(body, encOut);
+
+        // close if wrapped (base64 or quoted-printable)
+        if (encOut != out)
+            encOut.close();
+    }
+
+    /**
+     * Write the specified <code>Multipart</code> to the specified
+     * <code>OutputStream</code>.
+     * 
+     * @param multipart
+     *            the <code>Multipart</code> to write.
+     * @param out
+     *            the OutputStream to write to.
+     * @throws IOException
+     *             if an I/O error occurs.
+     */
+    public void writeMultipart(Multipart multipart, OutputStream out)
+            throws IOException {
+        ContentTypeField contentType = getContentType(multipart);
+
+        ByteSequence boundary = getBoundary(contentType);
+
+        ByteSequence preamble;
+        ByteSequence epilogue;
+        if (multipart instanceof MultipartImpl) {
+            preamble = ((MultipartImpl) multipart).getPreambleRaw();
+            epilogue = ((MultipartImpl) multipart).getEpilogueRaw();
+        } else {
+            preamble = ContentUtil.encode(multipart.getPreamble());
+            epilogue = ContentUtil.encode(multipart.getEpilogue());
+        }
+        writeBytes(preamble, out);
+        out.write(CRLF);
+
+        for (Entity bodyPart : multipart.getBodyParts()) {
+            out.write(DASHES);
+            writeBytes(boundary, out);
+            out.write(CRLF);
+
+            writeEntity(bodyPart, out);
+            out.write(CRLF);
+        }
+
+        out.write(DASHES);
+        writeBytes(boundary, out);
+        out.write(DASHES);
+        out.write(CRLF);
+
+        writeBytes(epilogue, out);
+    }
+
+    /**
+     * Write the specified <code>Header</code> to the specified
+     * <code>OutputStream</code>.
+     * 
+     * @param header
+     *            the <code>Header</code> to write.
+     * @param out
+     *            the OutputStream to write to.
+     * @throws IOException
+     *             if an I/O error occurs.
+     */
+    public void writeHeader(Header header, OutputStream out) throws IOException {
+        for (Field field : header) {
+            field.writeTo(out);
+            out.write(CRLF);
+        }
+
+        out.write(CRLF);
+    }
+
+    protected OutputStream encodeStream(OutputStream out, String encoding,
+            boolean binaryBody) throws IOException {
+        if (MimeUtil.isBase64Encoding(encoding)) {
+            return CodecUtil.wrapBase64(out);
+        } else if (MimeUtil.isQuotedPrintableEncoded(encoding)) {
+            return CodecUtil.wrapQuotedPrintable(out, binaryBody);
+        } else {
+            return out;
+        }
+    }
+
+    private ContentTypeField getContentType(Multipart multipart) {
+        Entity parent = multipart.getParent();
+        if (parent == null)
+            throw new IllegalArgumentException(
+                    "Missing parent entity in multipart");
+
+        Header header = parent.getHeader();
+        if (header == null)
+            throw new IllegalArgumentException(
+                    "Missing header in parent entity");
+
+        ContentTypeField contentType = (ContentTypeField) header
+                .getField(FieldName.CONTENT_TYPE);
+        if (contentType == null)
+            throw new IllegalArgumentException(
+                    "Content-Type field not specified");
+
+        return contentType;
+    }
+
+    private ByteSequence getBoundary(ContentTypeField contentType) {
+        String boundary = contentType.getBoundary();
+        if (boundary == null)
+            throw new IllegalArgumentException(
+                    "Multipart boundary not specified");
+
+        return ContentUtil.encode(boundary);
+    }
+
+    private void writeBytes(ByteSequence byteSequence, OutputStream out)
+            throws IOException {
+        if (byteSequence instanceof ByteArrayBuffer) {
+            ByteArrayBuffer bab = (ByteArrayBuffer) byteSequence;
+            out.write(bab.buffer(), 0, bab.length());
+        } else {
+            out.write(byteSequence.toByteArray());
+        }
+    }
+
+}

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



Mime
View raw message