james-mime4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1679164 - in /james/mime4j/trunk/core/src: main/java/org/apache/james/mime4j/codec/QuotedPrintableInputStream.java test/java/org/apache/james/mime4j/codec/QuotedPrintableInputStreamTest.java
Date Wed, 13 May 2015 09:24:30 GMT
Author: olegk
Date: Wed May 13 09:24:29 2015
New Revision: 1679164

URL: http://svn.apache.org/r1679164
Log:
MIME4J-244: QP decoder incorrectly throws IOException in strict mode when LF is the first
character in content stream
Contributed by Detelin Hadzhiev <detelin.hadzhiev at softwareag.com>

Modified:
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/codec/QuotedPrintableInputStream.java
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableInputStreamTest.java

Modified: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/codec/QuotedPrintableInputStream.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/codec/QuotedPrintableInputStream.java?rev=1679164&r1=1679163&r2=1679164&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/codec/QuotedPrintableInputStream.java
(original)
+++ james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/codec/QuotedPrintableInputStream.java
Wed May 13 09:24:29 2015
@@ -45,6 +45,7 @@ public class QuotedPrintableInputStream
     private int pos = 0; // current index into encoded buffer
     private int limit = 0; // current size of encoded buffer
 
+    private boolean lastWasCR = false;
     private boolean closed;
 
     private final DecodeMonitor monitor;
@@ -180,7 +181,6 @@ public class QuotedPrintableInputStream
                 return index == off ? -1 : index - off;
             }
 
-            boolean lastWasCR = false;
             while (pos < limit && index < to) {
                 int b = encoded[pos++] & 0xFF;
 

Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableInputStreamTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableInputStreamTest.java?rev=1679164&r1=1679163&r2=1679164&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableInputStreamTest.java
(original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableInputStreamTest.java
Wed May 13 09:24:29 2015
@@ -21,6 +21,8 @@ package org.apache.james.mime4j.codec;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
 import java.io.UnsupportedEncodingException;
 
 import org.apache.commons.io.IOUtils;
@@ -35,6 +37,16 @@ public class QuotedPrintableInputStreamT
         return IOUtils.toString(is, Charsets.ISO_8859_1.name());
     }
 
+    private static String readTextByOne(final InputStream is) throws IOException {
+        StringBuilder buf = new StringBuilder();
+        Reader reader = new InputStreamReader(is, Charsets.ISO_8859_1.name());
+        int ch;
+        while ((ch = reader.read()) != -1) {
+            buf.append((char) ch);
+        }
+        return buf.toString();
+    }
+
     @Test
     public void testBasicDecode() throws IOException, UnsupportedEncodingException {
         InputStream bis = InputStreams.createAscii("=e1=e2=E3=E4\r\n");
@@ -111,6 +123,13 @@ public class QuotedPrintableInputStreamT
     }
 
     @Test
+    public void testSpaceBeforeSoftBreakStrictMode() throws IOException, UnsupportedEncodingException
{
+        InputStream bis = InputStreams.createAscii("text before eq sign =\r\n text after
LF");
+        QuotedPrintableInputStream decoder = new QuotedPrintableInputStream(bis,DecodeMonitor.STRICT);
+        Assert.assertEquals("text before eq sign  text after LF", readTextByOne(decoder));
+    }
+
+    @Test
     public void testSoftBreakTrailingBalnksDecode() throws IOException, UnsupportedEncodingException
{
         InputStream bis = InputStreams.createAscii("Soft line   = \t \r\nHard line   \r\n");
         QuotedPrintableInputStream decoder = new QuotedPrintableInputStream(bis);



Mime
View raw message