james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nik...@apache.org
Subject svn commit: r678383 - in /james/mime4j/trunk/src: main/java/org/apache/james/mime4j/message/ test/resources/testmsgs/
Date Mon, 21 Jul 2008 10:20:04 GMT
Author: niklas
Date: Mon Jul 21 03:20:00 2008
New Revision: 678383

URL: http://svn.apache.org/viewvc?rev=678383&view=rev
Log:
Resolved MIME4J-59: The TextBody instances created when parsing a message will now handle
the decoding/encoding of qp and base64 bodies automatically as it was done in Mime4j 0.3.

Added:
    james/mime4j/trunk/src/test/resources/testmsgs/qp-body.msg
    james/mime4j/trunk/src/test/resources/testmsgs/qp-body.xml
    james/mime4j/trunk/src/test/resources/testmsgs/qp-body_decoded.xml
    james/mime4j/trunk/src/test/resources/testmsgs/qp-body_decoded_1.txt
Modified:
    james/mime4j/trunk/src/main/java/org/apache/james/mime4j/message/Message.java
    james/mime4j/trunk/src/main/java/org/apache/james/mime4j/message/TempFileTextBody.java

Modified: james/mime4j/trunk/src/main/java/org/apache/james/mime4j/message/Message.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/src/main/java/org/apache/james/mime4j/message/Message.java?rev=678383&r1=678382&r2=678383&view=diff
==============================================================================
--- james/mime4j/trunk/src/main/java/org/apache/james/mime4j/message/Message.java (original)
+++ james/mime4j/trunk/src/main/java/org/apache/james/mime4j/message/Message.java Mon Jul
21 03:20:00 2008
@@ -184,7 +184,7 @@
             
             final Body body;
             if (bd.getMimeType().startsWith("text/")) {
-                body = new TempFileTextBody(is, bd.getCharset());
+                body = new TempFileTextBody(is, bd.getCharset(), enc);
             } else {
                 body = new TempFileBinaryBody(is, enc);
             }

Modified: james/mime4j/trunk/src/main/java/org/apache/james/mime4j/message/TempFileTextBody.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/src/main/java/org/apache/james/mime4j/message/TempFileTextBody.java?rev=678383&r1=678382&r2=678383&view=diff
==============================================================================
--- james/mime4j/trunk/src/main/java/org/apache/james/mime4j/message/TempFileTextBody.java
(original)
+++ james/mime4j/trunk/src/main/java/org/apache/james/mime4j/message/TempFileTextBody.java
Mon Jul 21 03:20:00 2008
@@ -28,8 +28,11 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.james.mime4j.decoder.Base64InputStream;
+import org.apache.james.mime4j.decoder.QuotedPrintableInputStream;
 import org.apache.james.mime4j.util.CharsetUtil;
 import org.apache.james.mime4j.util.CodecUtil;
+import org.apache.james.mime4j.util.MimeUtil;
 import org.apache.james.mime4j.util.TempFile;
 import org.apache.james.mime4j.util.TempPath;
 import org.apache.james.mime4j.util.TempStorage;
@@ -46,21 +49,30 @@
     
     private String mimeCharset = null;
     private TempFile tempFile = null;
+    private final String transferEncoding;
 
     public TempFileTextBody(InputStream is) throws IOException {
-        this(is, null);
+        this(is, null, null);
     }
     
-    public TempFileTextBody(InputStream is, String mimeCharset) 
-            throws IOException {
+    public TempFileTextBody(final InputStream is, final String mimeCharset, 
+            final String transferEncoding) throws IOException {
         
         this.mimeCharset = mimeCharset;
-        
+        this.transferEncoding = transferEncoding;        
         TempPath tempPath = TempStorage.getInstance().getRootTempPath();
         tempFile = tempPath.createTempFile("attachment", ".txt");
         
         OutputStream out = tempFile.getOutputStream();
-        CodecUtil.copy(is, out);
+        final InputStream decodedStream;
+        if (MimeUtil.ENC_BASE64.equals(transferEncoding)) {
+            decodedStream = new Base64InputStream(is);
+        } else if (MimeUtil.ENC_QUOTED_PRINTABLE.equals(transferEncoding)) {
+            decodedStream = new QuotedPrintableInputStream(is);
+        } else {
+            decodedStream = is;
+        }
+        CodecUtil.copy(decodedStream, out);
         out.close();
     }
     
@@ -110,6 +122,15 @@
      * @see org.apache.james.mime4j.message.Body#writeTo(java.io.OutputStream, int)
      */
     public void writeTo(OutputStream out, int mode) throws IOException {
-        CodecUtil.copy(tempFile.getInputStream(), out);	
+        final InputStream inputStream = tempFile.getInputStream();
+        if (MimeUtil.ENC_BASE64.equals(transferEncoding)) {
+            CodecUtil.encodeBase64(inputStream, out);
+            out.write(CodecUtil.CRLF_CRLF);
+        } else if (MimeUtil.ENC_QUOTED_PRINTABLE.equals(transferEncoding)) {
+            CodecUtil.encodeQuotedPrintableBinary(inputStream,out);
+            out.write(CodecUtil.CRLF_CRLF);
+        } else {
+            CodecUtil.copy(inputStream,out);
+        }
     }
 }

Added: james/mime4j/trunk/src/test/resources/testmsgs/qp-body.msg
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/src/test/resources/testmsgs/qp-body.msg?rev=678383&view=auto
==============================================================================
--- james/mime4j/trunk/src/test/resources/testmsgs/qp-body.msg (added)
+++ james/mime4j/trunk/src/test/resources/testmsgs/qp-body.msg Mon Jul 21 03:20:00 2008
@@ -0,0 +1,6 @@
+Mime-Version: 1.0
+Subject: subject
+Content-Type: text/plain; charset="iso-8859-15"
+Content-Transfer-Encoding: quoted-printable
+
+7bit content with euro =A4 symbol=20

Added: james/mime4j/trunk/src/test/resources/testmsgs/qp-body.xml
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/src/test/resources/testmsgs/qp-body.xml?rev=678383&view=auto
==============================================================================
--- james/mime4j/trunk/src/test/resources/testmsgs/qp-body.xml (added)
+++ james/mime4j/trunk/src/test/resources/testmsgs/qp-body.xml Mon Jul 21 03:20:00 2008
@@ -0,0 +1,15 @@
+<message>
+<header>
+<field>
+Mime-Version: 1.0</field>
+<field>
+Subject: subject</field>
+<field>
+Content-Type: text/plain; charset="iso-8859-15"</field>
+<field>
+Content-Transfer-Encoding: quoted-printable</field>
+</header>
+<body>
+7bit content with euro =A4 symbol=20
+</body>
+</message>

Added: james/mime4j/trunk/src/test/resources/testmsgs/qp-body_decoded.xml
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/src/test/resources/testmsgs/qp-body_decoded.xml?rev=678383&view=auto
==============================================================================
--- james/mime4j/trunk/src/test/resources/testmsgs/qp-body_decoded.xml (added)
+++ james/mime4j/trunk/src/test/resources/testmsgs/qp-body_decoded.xml Mon Jul 21 03:20:00
2008
@@ -0,0 +1,13 @@
+<message>
+<header>
+<field>
+Mime-Version: 1.0</field>
+<field>
+Subject: subject</field>
+<field>
+Content-Type: text/plain; charset="iso-8859-15"</field>
+<field>
+Content-Transfer-Encoding: quoted-printable</field>
+</header>
+<text-body name="qp-body_decoded_1.txt"/>
+</message>

Added: james/mime4j/trunk/src/test/resources/testmsgs/qp-body_decoded_1.txt
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/src/test/resources/testmsgs/qp-body_decoded_1.txt?rev=678383&view=auto
==============================================================================
--- james/mime4j/trunk/src/test/resources/testmsgs/qp-body_decoded_1.txt (added)
+++ james/mime4j/trunk/src/test/resources/testmsgs/qp-body_decoded_1.txt Mon Jul 21 03:20:00
2008
@@ -0,0 +1 @@
+7bit content with euro ยค symbol 



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message