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:
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) {
|
||||
super(name+"-"+clientSocket.getPort());
|
||||
public AbstractConnection(String name, Socket clientSocket, String encoding) {
|
||||
super(name + "-" + clientSocket.getPort());
|
||||
this.client = clientSocket;
|
||||
try {
|
||||
//noinspection IOResourceOpenedButNotSafelyClosed
|
||||
in = new BufferedReader(new InputStreamReader(client.getInputStream(), "UTF-8"));
|
||||
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,7 +58,8 @@ public class AbstractConnection extends Thread {
|
||||
|
||||
/**
|
||||
* Send prefix and message to client followed by CRLF.
|
||||
* @param prefix prefix
|
||||
*
|
||||
* @param prefix prefix
|
||||
* @param message message
|
||||
* @throws IOException on error
|
||||
*/
|
||||
@ -66,13 +72,14 @@ public class AbstractConnection extends Thread {
|
||||
logBuffer.append(message);
|
||||
DavGatewayTray.debug(logBuffer.toString());
|
||||
os.write(message.getBytes());
|
||||
os.write((char)13);
|
||||
os.write((char)10);
|
||||
os.write((char) 13);
|
||||
os.write((char) 10);
|
||||
os.flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Send only bytes to client.
|
||||
*
|
||||
* @param messageBytes content
|
||||
* @throws IOException on error
|
||||
*/
|
||||
@ -97,9 +104,9 @@ public class AbstractConnection extends Thread {
|
||||
if (line != null) {
|
||||
if (line.startsWith("PASS")) {
|
||||
DavGatewayTray.debug("< PASS ********");
|
||||
} else if (state == SmtpConnection.PASSWORD){
|
||||
} else if (state == SmtpConnection.PASSWORD) {
|
||||
DavGatewayTray.debug("< ********");
|
||||
} else if (line.startsWith("Authorization:")){
|
||||
} else if (line.startsWith("Authorization:")) {
|
||||
DavGatewayTray.debug("< Authorization: ********");
|
||||
} else {
|
||||
DavGatewayTray.debug("< " + line);
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
@ -1038,7 +1043,7 @@ public class ExchangeSession {
|
||||
startDate = icalParser.parse(startDateValue);
|
||||
}
|
||||
if (endDateValue.length() == 8) {
|
||||
endDate = shortIcalParser.parse(endDateValue);
|
||||
endDate = shortIcalParser.parse(endDateValue);
|
||||
} else {
|
||||
endDate = icalParser.parse(endDateValue);
|
||||
}
|
||||
|
@ -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