james-mime4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject svn commit: r894617 - in /james/mime4j/branches/cycleclean: benchmark/src/main/java/org/apache/james/mime4j/ core/src/main/java/org/apache/james/mime4j/message/
Date Wed, 30 Dec 2009 14:13:06 GMT
Author: bago
Date: Wed Dec 30 14:13:06 2009
New Revision: 894617

URL: http://svn.apache.org/viewvc?rev=894617&view=rev
Log:
Removed decoding capabilities from our ContentHandlers, preferring relying on MimeStreamParser.setContentDecoding(true)
(MIME4J-154)

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/message/Message.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/MessageBuilder.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/SimpleContentHandler.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=894617&r1=894616&r2=894617&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
Wed Dec 30 14:13:06 2009
@@ -146,8 +146,10 @@
         public void run(byte[] content, int repetitions) throws Exception {
             ContentHandler contentHandler = new SimpleContentHandler() {
                 @Override
-                public void bodyDecoded(BodyDescriptor bd, InputStream is)
+                public void body(BodyDescriptor bd, InputStream is)
                         throws IOException {
+                	byte[] b = new byte[4096];
+					while (is.read(b) != -1);
                 }
 
                 @Override
@@ -157,6 +159,7 @@
 
             for (int i = 0; i < repetitions; i++) {
                 MimeStreamParser parser = new MimeStreamParser();
+                parser.setContentDecoding(true);
                 parser.setContentHandler(contentHandler);
                 parser.parse(new ByteArrayInputStream(content));
             }

Modified: 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/message/Message.java?rev=894617&r1=894616&r2=894617&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/message/Message.java
Wed Dec 30 14:13:06 2009
@@ -137,6 +137,7 @@
             MimeIOException {
         try {
             MimeStreamParser parser = new MimeStreamParser(config);
+            parser.setContentDecoding(true);
             parser.setContentHandler(new MessageBuilder(this, storageProvider));
             parser.parse(is);
         } catch (MimeException e) {

Modified: 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=894617&r1=894616&r2=894617&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/MessageBuilder.java
(original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/MessageBuilder.java
Wed Dec 30 14:13:06 2009
@@ -24,8 +24,6 @@
 import java.util.Stack;
 
 import org.apache.james.mime4j.MimeException;
-import org.apache.james.mime4j.codec.Base64InputStream;
-import org.apache.james.mime4j.codec.QuotedPrintableInputStream;
 import org.apache.james.mime4j.descriptor.BodyDescriptor;
 import org.apache.james.mime4j.field.DefaultFieldParser;
 import org.apache.james.mime4j.field.Field;
@@ -35,7 +33,6 @@
 import org.apache.james.mime4j.storage.StorageProvider;
 import org.apache.james.mime4j.util.ByteArrayBuffer;
 import org.apache.james.mime4j.util.ByteSequence;
-import org.apache.james.mime4j.util.MimeUtil;
 
 /**
  * A <code>ContentHandler</code> for building an <code>Entity</code>
to be
@@ -132,10 +129,15 @@
     public void body(BodyDescriptor bd, final InputStream is) throws MimeException, IOException
{
         expect(Entity.class);
         
-        final String enc = bd.getTransferEncoding();
+        // 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);
@@ -144,11 +146,12 @@
         } else {
             decodedStream = is;
         }
+        */
         
         if (bd.getMimeType().startsWith("text/")) {
-            body = bodyFactory.textBody(decodedStream, bd.getCharset());
+            body = bodyFactory.textBody(is, bd.getCharset());
         } else {
-            body = bodyFactory.binaryBody(decodedStream);
+            body = bodyFactory.binaryBody(is);
         }
         
         Entity entity = ((Entity) stack.peek());

Modified: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/SimpleContentHandler.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/SimpleContentHandler.java?rev=894617&r1=894616&r2=894617&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/SimpleContentHandler.java
(original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/SimpleContentHandler.java
Wed Dec 30 14:13:06 2009
@@ -20,24 +20,17 @@
 package org.apache.james.mime4j.message;
 
 import org.apache.james.mime4j.MimeException;
-import org.apache.james.mime4j.codec.Base64InputStream;
-import org.apache.james.mime4j.codec.QuotedPrintableInputStream;
-import org.apache.james.mime4j.descriptor.BodyDescriptor;
 import org.apache.james.mime4j.field.DefaultFieldParser;
 import org.apache.james.mime4j.field.Field;
 import org.apache.james.mime4j.parser.AbstractContentHandler;
 import org.apache.james.mime4j.parser.RawField;
-import org.apache.james.mime4j.util.MimeUtil;
-
-import java.io.InputStream;
-import java.io.IOException;
 
 /**
  * Abstract implementation of ContentHandler that automates common
- * tasks. Currently performs header parsing and applies content-transfer
- * decoding to body parts.
+ * tasks. Currently performs header parsing.
  *
- * 
+ * Older versions of this class performed decoding of content streams.
+ * This can be now easily achieved by calling setContentDecoding(true) on the MimeStreamParser.
  */
 public abstract class SimpleContentHandler extends  AbstractContentHandler {
 
@@ -46,21 +39,6 @@
      */
     public abstract void headers(Header header);
 
-    /**
-     * Called when the body of a discrete (non-multipart) entity is encountered.
-
-     * @param bd encapsulates the values (either read from the
-     *        message stream or, if not present, determined implictly
-     *        as described in the
-     *        MIME rfc:s) of the <code>Content-Type</code> and
-     *        <code>Content-Transfer-Encoding</code> header fields.
-     * @param is the contents of the body. Base64 or quoted-printable
-     *        decoding will be applied transparently.
-     * @throws IOException should be thrown on I/O errors.
-     */
-    public abstract void bodyDecoded(BodyDescriptor bd, InputStream is) throws IOException;
-
-
     /* Implement introduced callbacks. */
 
     private Header currHeader;
@@ -92,19 +70,4 @@
         headers(tmp);
     }
 
-    /**
-     * @see org.apache.james.mime4j.parser.AbstractContentHandler#body(org.apache.james.mime4j.descriptor.BodyDescriptor,
java.io.InputStream)
-     */
-    @Override
-    public final void body(BodyDescriptor bd, InputStream is) throws IOException {
-        if (MimeUtil.isBase64Encoding(bd.getTransferEncoding())) {
-            bodyDecoded(bd, new Base64InputStream(is));
-        }
-        else if (MimeUtil.isQuotedPrintableEncoded(bd.getTransferEncoding())) {
-            bodyDecoded(bd, new QuotedPrintableInputStream(is));
-        }
-        else {
-            bodyDecoded(bd, is);
-        }
-    }
 }



Mime
View raw message