From d1278edad49edb7f61e44e10d356b5dc0460773a Mon Sep 17 00:00:00 2001 From: mguessan Date: Mon, 19 Jul 2010 15:15:54 +0000 Subject: [PATCH] POP: fix message termination, append CRLF only when necessary git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1206 3d1905a2-6b24-0410-a738-b14d5a86fcbd --- .../davmail/exchange/DoubleDotOutputStream.java | 17 +++++++++++++++++ src/java/davmail/pop/PopConnection.java | 12 ++++++------ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/java/davmail/exchange/DoubleDotOutputStream.java b/src/java/davmail/exchange/DoubleDotOutputStream.java index 17b6ea49..5a766a1e 100644 --- a/src/java/davmail/exchange/DoubleDotOutputStream.java +++ b/src/java/davmail/exchange/DoubleDotOutputStream.java @@ -56,4 +56,21 @@ public class DoubleDotOutputStream extends FilterOutputStream { out.write(b); } + /** + * Send termination characters. + * Do not close actual outputstream + * + * @throws IOException on error + */ + @Override + public void close() throws IOException { + if (currentState != State.CRLF) { + out.write('\r'); + out.write('\n'); + } + out.write('.'); + out.write('\r'); + out.write('\n'); + } + } diff --git a/src/java/davmail/pop/PopConnection.java b/src/java/davmail/pop/PopConnection.java index 8dd5662d..31260d50 100644 --- a/src/java/davmail/pop/PopConnection.java +++ b/src/java/davmail/pop/PopConnection.java @@ -197,9 +197,9 @@ public class PopConnection extends AbstractConnection { try { int messageNumber = Integer.valueOf(tokens.nextToken()) - 1; sendOK(""); - IOUtil.write(messages.get(messageNumber).getRawInputStream(), new DoubleDotOutputStream(os)); - sendClient(""); - sendClient("."); + DoubleDotOutputStream doubleDotOutputStream = new DoubleDotOutputStream(os); + IOUtil.write(messages.get(messageNumber).getRawInputStream(), doubleDotOutputStream); + doubleDotOutputStream.close(); } catch (SocketException e) { // can not send error to client after a socket exception DavGatewayTray.warn(new BundleMessage("LOG_CLIENT_CLOSED_CONNECTION"), e); @@ -234,9 +234,9 @@ public class PopConnection extends AbstractConnection { int lines = Integer.valueOf(tokens.nextToken()); ExchangeSession.Message m = messages.get(message - 1); sendOK(""); - IOUtil.write(m.getRawInputStream(), new TopOutputStream(new DoubleDotOutputStream(os), lines)); - sendClient(""); - sendClient("."); + DoubleDotOutputStream doubleDotOutputStream = new DoubleDotOutputStream(os); + IOUtil.write(m.getRawInputStream(), doubleDotOutputStream); + doubleDotOutputStream.close(); } catch (NumberFormatException e) { sendERR("invalid command"); } catch (IndexOutOfBoundsException e) {