mirror of
https://github.com/moparisthebest/davmail
synced 2024-12-13 19:22: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:
parent
9aca6b5ae7
commit
6e384ae98a
@ -29,12 +29,16 @@ public class AbstractConnection extends Thread {
|
||||
protected ExchangeSession session;
|
||||
|
||||
// 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());
|
||||
this.client = clientSocket;
|
||||
try {
|
||||
if (encoding == null) {
|
||||
//noinspection IOResourceOpenedButNotSafelyClosed
|
||||
in = new BufferedReader(new InputStreamReader(client.getInputStream()));
|
||||
} else {
|
||||
in = new BufferedReader(new InputStreamReader(client.getInputStream(), "UTF-8"));
|
||||
}
|
||||
os = client.getOutputStream();
|
||||
} catch (IOException e) {
|
||||
close();
|
||||
@ -44,6 +48,7 @@ public class AbstractConnection extends Thread {
|
||||
|
||||
/**
|
||||
* Send message to client followed by CRLF.
|
||||
*
|
||||
* @param message message
|
||||
* @throws IOException on error
|
||||
*/
|
||||
@ -53,6 +58,7 @@ public class AbstractConnection extends Thread {
|
||||
|
||||
/**
|
||||
* Send prefix and message to client followed by CRLF.
|
||||
*
|
||||
* @param prefix prefix
|
||||
* @param message message
|
||||
* @throws IOException on error
|
||||
@ -73,6 +79,7 @@ public class AbstractConnection extends Thread {
|
||||
|
||||
/**
|
||||
* Send only bytes to client.
|
||||
*
|
||||
* @param messageBytes content
|
||||
* @throws IOException on error
|
||||
*/
|
||||
|
@ -27,7 +27,7 @@ public class CaldavConnection extends AbstractConnection {
|
||||
|
||||
// Initialize the streams and start the thread
|
||||
public CaldavConnection(Socket clientSocket) {
|
||||
super("CaldavConnection", clientSocket);
|
||||
super("CaldavConnection", clientSocket, "UTF-8");
|
||||
}
|
||||
|
||||
protected Map<String, String> parseHeaders() throws IOException {
|
||||
|
@ -419,8 +419,11 @@ public class ExchangeSession {
|
||||
// TODO : test, bcc ?
|
||||
putmethod.setRequestHeader("Translate", "f");
|
||||
putmethod.setRequestHeader("Content-Type", "message/rfc822");
|
||||
putmethod.setRequestBody(messageBody);
|
||||
InputStream bodyStream = null;
|
||||
try {
|
||||
// use same encoding as client socket reader
|
||||
bodyStream = new ByteArrayInputStream(messageBody.getBytes());
|
||||
putmethod.setRequestBody(bodyStream);
|
||||
int code = wdr.retrieveSessionInstance().executeMethod(putmethod);
|
||||
|
||||
if (code == HttpURLConnection.HTTP_OK) {
|
||||
@ -429,6 +432,13 @@ public class ExchangeSession {
|
||||
throw new IOException("Unable to create message " + code + " " + putmethod.getStatusLine());
|
||||
}
|
||||
} finally {
|
||||
if (bodyStream != null) {
|
||||
try {
|
||||
bodyStream.close();
|
||||
} catch (IOException e) {
|
||||
LOGGER.error(e);
|
||||
}
|
||||
}
|
||||
putmethod.releaseConnection();
|
||||
}
|
||||
}
|
||||
@ -684,8 +694,8 @@ public class ExchangeSession {
|
||||
inHTML = false;
|
||||
}
|
||||
if (inHTML) {
|
||||
line = line.replaceAll("’", "'");
|
||||
line = line.replaceAll("…", "...");
|
||||
// line = line.replaceAll("’", "'");
|
||||
// line = line.replaceAll("…", "...");
|
||||
}
|
||||
isoWriter.write(line);
|
||||
isoWriter.write((char) 13);
|
||||
@ -908,13 +918,8 @@ public class ExchangeSession {
|
||||
}
|
||||
|
||||
public int deleteEvent(String path) throws IOException {
|
||||
//wdr.setDebug(4);
|
||||
wdr.deleteMethod(calendarUrl + "/" + path);
|
||||
//wdr.setDebug(0);
|
||||
wdr.deleteMethod(calendarUrl + "/" + URIUtil.decode(path));
|
||||
int status = wdr.getStatusCode();
|
||||
if (status == HttpStatus.SC_NOT_FOUND) {
|
||||
status = HttpStatus.SC_OK;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ public class ImapConnection extends AbstractConnection {
|
||||
|
||||
// Initialize the streams and start the thread
|
||||
public ImapConnection(Socket clientSocket) {
|
||||
super("ImapConnection", clientSocket);
|
||||
super("ImapConnection", clientSocket, null);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
|
@ -23,7 +23,7 @@ public class SmtpConnection extends AbstractConnection {
|
||||
|
||||
// Initialize the streams and start the thread
|
||||
public SmtpConnection(Socket clientSocket) {
|
||||
super("SmtpConnection", clientSocket);
|
||||
super("SmtpConnection", clientSocket, null);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
|
Loading…
Reference in New Issue
Block a user