From 179a5304d666f2ee99839ab67eba5350d9495346 Mon Sep 17 00:00:00 2001 From: mguessan Date: Mon, 19 Jul 2010 09:05:44 +0000 Subject: [PATCH] POP: replace deprecated write method, use DoubleDotOutputStream instead git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1199 3d1905a2-6b24-0410-a738-b14d5a86fcbd --- .../davmail/exchange/ExchangeSession.java | 49 +------------------ src/java/davmail/pop/PopConnection.java | 6 ++- src/java/davmail/util/IOUtil.java | 46 +++++++++++++++++ 3 files changed, 51 insertions(+), 50 deletions(-) create mode 100644 src/java/davmail/util/IOUtil.java diff --git a/src/java/davmail/exchange/ExchangeSession.java b/src/java/davmail/exchange/ExchangeSession.java index ab8ac851..e99be5d0 100644 --- a/src/java/davmail/exchange/ExchangeSession.java +++ b/src/java/davmail/exchange/ExchangeSession.java @@ -532,6 +532,7 @@ public abstract class ExchangeSession { static { POP_MESSAGE_ATTRIBUTES.add("uid"); + POP_MESSAGE_ATTRIBUTES.add("imapUid"); POP_MESSAGE_ATTRIBUTES.add("messageSize"); } @@ -1357,54 +1358,6 @@ public abstract class ExchangeSession { return buffer.toString().trim(); } - /** - * Write MIME message to os - * - * @param os output stream - * @param doubleDot replace '.' lines with '..' (POP protocol) - * @throws IOException on error - * @deprecated move to byte array handling instead - */ - @Deprecated - public void write(OutputStream os, boolean doubleDot) throws IOException { - BufferedReader reader = getContentReader(this); - try { - OutputStreamWriter isoWriter = new OutputStreamWriter(os); - String line; - while ((line = reader.readLine()) != null) { - if (doubleDot && ".".equals(line)) { - line = ".."; - // patch text/calendar to include utf-8 encoding - } else if ("Content-Type: text/calendar;".equals(line)) { - StringBuilder headerBuffer = new StringBuilder(); - headerBuffer.append(line); - while ((line = reader.readLine()) != null && line.startsWith("\t")) { - headerBuffer.append((char) 13); - headerBuffer.append((char) 10); - headerBuffer.append(line); - } - if (headerBuffer.indexOf("charset") < 0) { - headerBuffer.append(";charset=utf-8"); - } - headerBuffer.append((char) 13); - headerBuffer.append((char) 10); - headerBuffer.append(line); - line = headerBuffer.toString(); - } - isoWriter.write(line); - isoWriter.write((char) 13); - isoWriter.write((char) 10); - } - isoWriter.flush(); - } finally { - try { - reader.close(); - } catch (IOException e) { - LOGGER.warn("Error closing message input stream", e); - } - } - } - /** * Load message content in a Mime message * diff --git a/src/java/davmail/pop/PopConnection.java b/src/java/davmail/pop/PopConnection.java index c0d6fa79..8dd5662d 100644 --- a/src/java/davmail/pop/PopConnection.java +++ b/src/java/davmail/pop/PopConnection.java @@ -20,9 +20,11 @@ package davmail.pop; import davmail.AbstractConnection; import davmail.BundleMessage; +import davmail.exchange.DoubleDotOutputStream; import davmail.exchange.ExchangeSession; import davmail.exchange.ExchangeSessionFactory; import davmail.ui.tray.DavGatewayTray; +import davmail.util.IOUtil; import java.io.FilterOutputStream; import java.io.IOException; @@ -195,7 +197,7 @@ public class PopConnection extends AbstractConnection { try { int messageNumber = Integer.valueOf(tokens.nextToken()) - 1; sendOK(""); - messages.get(messageNumber).write(os, true); + IOUtil.write(messages.get(messageNumber).getRawInputStream(), new DoubleDotOutputStream(os)); sendClient(""); sendClient("."); } catch (SocketException e) { @@ -232,7 +234,7 @@ public class PopConnection extends AbstractConnection { int lines = Integer.valueOf(tokens.nextToken()); ExchangeSession.Message m = messages.get(message - 1); sendOK(""); - m.write(new TopOutputStream(os, lines), true); + IOUtil.write(m.getRawInputStream(), new TopOutputStream(new DoubleDotOutputStream(os), lines)); sendClient(""); sendClient("."); } catch (NumberFormatException e) { diff --git a/src/java/davmail/util/IOUtil.java b/src/java/davmail/util/IOUtil.java new file mode 100644 index 00000000..feeea698 --- /dev/null +++ b/src/java/davmail/util/IOUtil.java @@ -0,0 +1,46 @@ +/* + * DavMail POP/IMAP/SMTP/CalDav/LDAP Exchange Gateway + * Copyright (C) 2010 Mickael Guessant + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package davmail.util; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +/** + * Input output functions. + */ +public class IOUtil { + private IOUtil() { + } + + /** + * Write all inputstream content to outputstream. + * + * @param inputStream input stream + * @param outputStream output stream + * @throws IOException on error + */ + public static void write(InputStream inputStream, OutputStream outputStream) throws IOException { + byte[] bytes = new byte[8192]; + int length; + while ((length = inputStream.read(bytes)) > 0) { + outputStream.write(bytes, 0, length); + } + } +}