1
0
mirror of https://github.com/moparisthebest/davmail synced 2024-12-14 19:52:21 -05:00

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
This commit is contained in:
mguessan 2010-07-19 09:05:44 +00:00
parent ff9b8940ac
commit 179a5304d6
3 changed files with 51 additions and 50 deletions

View File

@ -532,6 +532,7 @@ public abstract class ExchangeSession {
static { static {
POP_MESSAGE_ATTRIBUTES.add("uid"); POP_MESSAGE_ATTRIBUTES.add("uid");
POP_MESSAGE_ATTRIBUTES.add("imapUid");
POP_MESSAGE_ATTRIBUTES.add("messageSize"); POP_MESSAGE_ATTRIBUTES.add("messageSize");
} }
@ -1357,54 +1358,6 @@ public abstract class ExchangeSession {
return buffer.toString().trim(); 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 * Load message content in a Mime message
* *

View File

@ -20,9 +20,11 @@ package davmail.pop;
import davmail.AbstractConnection; import davmail.AbstractConnection;
import davmail.BundleMessage; import davmail.BundleMessage;
import davmail.exchange.DoubleDotOutputStream;
import davmail.exchange.ExchangeSession; import davmail.exchange.ExchangeSession;
import davmail.exchange.ExchangeSessionFactory; import davmail.exchange.ExchangeSessionFactory;
import davmail.ui.tray.DavGatewayTray; import davmail.ui.tray.DavGatewayTray;
import davmail.util.IOUtil;
import java.io.FilterOutputStream; import java.io.FilterOutputStream;
import java.io.IOException; import java.io.IOException;
@ -195,7 +197,7 @@ public class PopConnection extends AbstractConnection {
try { try {
int messageNumber = Integer.valueOf(tokens.nextToken()) - 1; int messageNumber = Integer.valueOf(tokens.nextToken()) - 1;
sendOK(""); sendOK("");
messages.get(messageNumber).write(os, true); IOUtil.write(messages.get(messageNumber).getRawInputStream(), new DoubleDotOutputStream(os));
sendClient(""); sendClient("");
sendClient("."); sendClient(".");
} catch (SocketException e) { } catch (SocketException e) {
@ -232,7 +234,7 @@ public class PopConnection extends AbstractConnection {
int lines = Integer.valueOf(tokens.nextToken()); int lines = Integer.valueOf(tokens.nextToken());
ExchangeSession.Message m = messages.get(message - 1); ExchangeSession.Message m = messages.get(message - 1);
sendOK(""); sendOK("");
m.write(new TopOutputStream(os, lines), true); IOUtil.write(m.getRawInputStream(), new TopOutputStream(new DoubleDotOutputStream(os), lines));
sendClient(""); sendClient("");
sendClient("."); sendClient(".");
} catch (NumberFormatException e) { } catch (NumberFormatException e) {

View File

@ -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);
}
}
}