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>
git-svn-id: https://svn.apache.org/repos/asf/james/mime4j/branches/apache-mime4j-0.7@1679163 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/core/src/main/java/org/apache/james/mime4j/codec/QuotedPrintableInputStream.java b/core/src/main/java/org/apache/james/mime4j/codec/QuotedPrintableInputStream.java
index ea1f876..4d64867 100644
--- a/core/src/main/java/org/apache/james/mime4j/codec/QuotedPrintableInputStream.java
+++ b/core/src/main/java/org/apache/james/mime4j/codec/QuotedPrintableInputStream.java
@@ -45,6 +45,7 @@
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;
@@ -181,7 +182,6 @@
return index == from ? -1 : index - from;
}
- boolean lastWasCR = false;
while (pos < limit && index < to) {
int b = encoded[pos++] & 0xFF;
diff --git a/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableInputStreamTest.java b/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableInputStreamTest.java
index 566099c..b410e9e 100644
--- a/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableInputStreamTest.java
+++ b/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableInputStreamTest.java
@@ -95,6 +95,12 @@
assertEquals("Soft line Hard line\r\n", new String(read(decoder), "ISO8859-1"));
}
+ public void testSpaceBeforeSoftBreakStrictMode() throws IOException, UnsupportedEncodingException {
+ ByteArrayInputStream bis = new ByteArrayInputStream("text before eq sign =\r\n text after LF".getBytes("US-ASCII"));
+ QuotedPrintableInputStream decoder = new QuotedPrintableInputStream(bis,DecodeMonitor.STRICT);
+ assertEquals("text before eq sign text after LF", new String(read(decoder), "ISO8859-1"));
+ }
+
public void testSoftBreakTrailingBalnksDecode() throws IOException, UnsupportedEncodingException {
ByteArrayInputStream bis = new ByteArrayInputStream("Soft line = \t \r\nHard line \r\n".getBytes("US-ASCII"));
QuotedPrintableInputStream decoder = new QuotedPrintableInputStream(bis);