From 14ee970b185e6870604758765ec205523b82959a Mon Sep 17 00:00:00 2001 From: cketti Date: Fri, 5 Feb 2010 02:36:52 +0000 Subject: [PATCH] Fixed EOLConvertingOutputStream. write('\r');flush();write('\n'); would lead to "\r\n\r\n" instead of simply "\r\n"; --- .../transport/EOLConvertingOutputStream.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/com/fsck/k9/mail/transport/EOLConvertingOutputStream.java b/src/com/fsck/k9/mail/transport/EOLConvertingOutputStream.java index 43d9dd63a..d35cc5e02 100644 --- a/src/com/fsck/k9/mail/transport/EOLConvertingOutputStream.java +++ b/src/com/fsck/k9/mail/transport/EOLConvertingOutputStream.java @@ -6,7 +6,8 @@ import java.io.OutputStream; public class EOLConvertingOutputStream extends FilterOutputStream { - int lastChar; + private int lastChar; + private boolean ignoreNextIfLF = false; public EOLConvertingOutputStream(OutputStream out) { @@ -16,15 +17,16 @@ public class EOLConvertingOutputStream extends FilterOutputStream @Override public void write(int oneByte) throws IOException { - if (oneByte == '\n') + if (!ignoreNextIfLF) { - if (lastChar != '\r') + if ((oneByte == '\n') && (lastChar != '\r')) { super.write('\r'); } + super.write(oneByte); + lastChar = oneByte; } - super.write(oneByte); - lastChar = oneByte; + ignoreNextIfLF = false; } @Override @@ -34,6 +36,11 @@ public class EOLConvertingOutputStream extends FilterOutputStream { super.write('\n'); lastChar = '\n'; + + // We have to ignore the next character if it is . Otherwise it + // will be expanded to an additional sequence although it + // belongs to the one just completed. + ignoreNextIfLF = true; } super.flush(); }