1
0
mirror of https://github.com/moparisthebest/davmail synced 2024-12-13 03:02:22 -05:00

Fix : force encoding to UTF-8 only on caldav connections and URIUtil.decode on DELETE

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@181 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2008-11-29 14:24:12 +00:00
parent 9aca6b5ae7
commit 6e384ae98a
5 changed files with 34 additions and 22 deletions

View File

@ -29,12 +29,16 @@ public class AbstractConnection extends Thread {
protected ExchangeSession session; protected ExchangeSession session;
// Initialize the streams and start the thread // Initialize the streams and start the thread
public AbstractConnection(String name, Socket clientSocket) { public AbstractConnection(String name, Socket clientSocket, String encoding) {
super(name+"-"+clientSocket.getPort()); super(name + "-" + clientSocket.getPort());
this.client = clientSocket; this.client = clientSocket;
try { try {
if (encoding == null) {
//noinspection IOResourceOpenedButNotSafelyClosed //noinspection IOResourceOpenedButNotSafelyClosed
in = new BufferedReader(new InputStreamReader(client.getInputStream()));
} else {
in = new BufferedReader(new InputStreamReader(client.getInputStream(), "UTF-8")); in = new BufferedReader(new InputStreamReader(client.getInputStream(), "UTF-8"));
}
os = client.getOutputStream(); os = client.getOutputStream();
} catch (IOException e) { } catch (IOException e) {
close(); close();
@ -44,6 +48,7 @@ public class AbstractConnection extends Thread {
/** /**
* Send message to client followed by CRLF. * Send message to client followed by CRLF.
*
* @param message message * @param message message
* @throws IOException on error * @throws IOException on error
*/ */
@ -53,6 +58,7 @@ public class AbstractConnection extends Thread {
/** /**
* Send prefix and message to client followed by CRLF. * Send prefix and message to client followed by CRLF.
*
* @param prefix prefix * @param prefix prefix
* @param message message * @param message message
* @throws IOException on error * @throws IOException on error
@ -66,13 +72,14 @@ public class AbstractConnection extends Thread {
logBuffer.append(message); logBuffer.append(message);
DavGatewayTray.debug(logBuffer.toString()); DavGatewayTray.debug(logBuffer.toString());
os.write(message.getBytes()); os.write(message.getBytes());
os.write((char)13); os.write((char) 13);
os.write((char)10); os.write((char) 10);
os.flush(); os.flush();
} }
/** /**
* Send only bytes to client. * Send only bytes to client.
*
* @param messageBytes content * @param messageBytes content
* @throws IOException on error * @throws IOException on error
*/ */
@ -97,9 +104,9 @@ public class AbstractConnection extends Thread {
if (line != null) { if (line != null) {
if (line.startsWith("PASS")) { if (line.startsWith("PASS")) {
DavGatewayTray.debug("< PASS ********"); DavGatewayTray.debug("< PASS ********");
} else if (state == SmtpConnection.PASSWORD){ } else if (state == SmtpConnection.PASSWORD) {
DavGatewayTray.debug("< ********"); DavGatewayTray.debug("< ********");
} else if (line.startsWith("Authorization:")){ } else if (line.startsWith("Authorization:")) {
DavGatewayTray.debug("< Authorization: ********"); DavGatewayTray.debug("< Authorization: ********");
} else { } else {
DavGatewayTray.debug("< " + line); DavGatewayTray.debug("< " + line);

View File

@ -27,7 +27,7 @@ public class CaldavConnection extends AbstractConnection {
// Initialize the streams and start the thread // Initialize the streams and start the thread
public CaldavConnection(Socket clientSocket) { public CaldavConnection(Socket clientSocket) {
super("CaldavConnection", clientSocket); super("CaldavConnection", clientSocket, "UTF-8");
} }
protected Map<String, String> parseHeaders() throws IOException { protected Map<String, String> parseHeaders() throws IOException {

View File

@ -419,8 +419,11 @@ public class ExchangeSession {
// TODO : test, bcc ? // TODO : test, bcc ?
putmethod.setRequestHeader("Translate", "f"); putmethod.setRequestHeader("Translate", "f");
putmethod.setRequestHeader("Content-Type", "message/rfc822"); putmethod.setRequestHeader("Content-Type", "message/rfc822");
putmethod.setRequestBody(messageBody); InputStream bodyStream = null;
try { try {
// use same encoding as client socket reader
bodyStream = new ByteArrayInputStream(messageBody.getBytes());
putmethod.setRequestBody(bodyStream);
int code = wdr.retrieveSessionInstance().executeMethod(putmethod); int code = wdr.retrieveSessionInstance().executeMethod(putmethod);
if (code == HttpURLConnection.HTTP_OK) { if (code == HttpURLConnection.HTTP_OK) {
@ -429,6 +432,13 @@ public class ExchangeSession {
throw new IOException("Unable to create message " + code + " " + putmethod.getStatusLine()); throw new IOException("Unable to create message " + code + " " + putmethod.getStatusLine());
} }
} finally { } finally {
if (bodyStream != null) {
try {
bodyStream.close();
} catch (IOException e) {
LOGGER.error(e);
}
}
putmethod.releaseConnection(); putmethod.releaseConnection();
} }
} }
@ -684,8 +694,8 @@ public class ExchangeSession {
inHTML = false; inHTML = false;
} }
if (inHTML) { if (inHTML) {
line = line.replaceAll("&#8217;", "'"); // line = line.replaceAll("&#8217;", "'");
line = line.replaceAll("&#8230;", "..."); // line = line.replaceAll("&#8230;", "...");
} }
isoWriter.write(line); isoWriter.write(line);
isoWriter.write((char) 13); isoWriter.write((char) 13);
@ -908,13 +918,8 @@ public class ExchangeSession {
} }
public int deleteEvent(String path) throws IOException { public int deleteEvent(String path) throws IOException {
//wdr.setDebug(4); wdr.deleteMethod(calendarUrl + "/" + URIUtil.decode(path));
wdr.deleteMethod(calendarUrl + "/" + path);
//wdr.setDebug(0);
int status = wdr.getStatusCode(); int status = wdr.getStatusCode();
if (status == HttpStatus.SC_NOT_FOUND) {
status = HttpStatus.SC_OK;
}
return status; return status;
} }

View File

@ -20,7 +20,7 @@ public class ImapConnection extends AbstractConnection {
// Initialize the streams and start the thread // Initialize the streams and start the thread
public ImapConnection(Socket clientSocket) { public ImapConnection(Socket clientSocket) {
super("ImapConnection", clientSocket); super("ImapConnection", clientSocket, null);
} }
public void run() { public void run() {

View File

@ -23,7 +23,7 @@ public class SmtpConnection extends AbstractConnection {
// Initialize the streams and start the thread // Initialize the streams and start the thread
public SmtpConnection(Socket clientSocket) { public SmtpConnection(Socket clientSocket) {
super("SmtpConnection", clientSocket); super("SmtpConnection", clientSocket, null);
} }
public void run() { public void run() {