Caldav: fixed path encoding issues on outlook created notifications delete

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@441 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2009-03-13 21:18:11 +00:00
parent 1ba82c82de
commit 60714ef44d
2 changed files with 31 additions and 13 deletions

View File

@ -147,7 +147,11 @@ public class CaldavConnection extends AbstractConnection {
} catch (SocketException e) {
DavGatewayTray.debug("Connection closed");
} catch (IOException e) {
DavGatewayTray.error(e);
if (e instanceof HttpException) {
DavGatewayTray.error(((HttpException)e).getReasonCode()+" "+((HttpException)e).getReason(), e);
} else {
DavGatewayTray.error(e);
}
try {
sendErr(HttpStatus.SC_SERVICE_UNAVAILABLE, e);
} catch (IOException e2) {
@ -254,7 +258,7 @@ public class CaldavConnection extends AbstractConnection {
if ("inbox".equals(paths[3])) {
paths[3] = "INBOX";
}
int status = session.deleteEvent(paths[3] + "/" + paths[4]);
int status = session.deleteEvent(paths[3], paths[4].replaceAll("&", "&"));
sendHttpResponse(status, true);
} else if ("GET".equals(command) && "users".equals(paths[1]) && paths.length == 5 && "calendar".equals(paths[3])
// only current user for now

View File

@ -19,9 +19,9 @@ import org.htmlcleaner.HtmlCleaner;
import org.htmlcleaner.TagNode;
import javax.mail.MessagingException;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimePart;
import java.io.*;
import java.net.HttpURLConnection;
@ -919,16 +919,17 @@ public class ExchangeSession {
}
}
public void moveToTrash(String messageUrl) throws IOException {
String destination = deleteditemsUrl + messageUrl.substring(messageUrl.lastIndexOf("/"));
LOGGER.debug("Deleting : " + messageUrl + " to " + destination);
MoveMethod method = new MoveMethod(URIUtil.encodePath(messageUrl),
URIUtil.encodePath(destination));
public void moveToTrash(String encodedPath, String encodedMessageName) throws IOException {
String source = encodedPath+"/"+encodedMessageName;
String destination = URIUtil.encodePath(deleteditemsUrl) + encodedMessageName;
LOGGER.debug("Deleting : " + source + " to " + destination);
MoveMethod method = new MoveMethod(source, destination);
method.addRequestHeader("Overwrite", "f");
method.addRequestHeader("Allow-rename", "t");
int status = wdr.retrieveSessionInstance().executeMethod(method);
if (status != HttpStatus.SC_CREATED) {
// do not throw error if already deleted
if (status != HttpStatus.SC_CREATED && status != HttpStatus.SC_NOT_FOUND) {
HttpException ex = new HttpException();
ex.setReasonCode(status);
ex.setReason(method.getStatusText());
@ -1090,7 +1091,13 @@ public class ExchangeSession {
properties.put("read", "1");
updateMessage(this, properties);
ExchangeSession.this.moveToTrash(messageUrl);
int index = messageUrl.lastIndexOf('/');
if (index < 0) {
throw new IOException("Invalid message url: "+messageUrl);
}
String encodedPath = URIUtil.encodePath(messageUrl.substring(0, index));
String encodedMessageName = URIUtil.encodePath(messageUrl.substring(index+1));
ExchangeSession.this.moveToTrash(encodedPath, encodedMessageName);
}
public int compareTo(Object message) {
@ -1604,12 +1611,19 @@ public class ExchangeSession {
return wdr.getStatusCode();
}
public int deleteEvent(String path) throws IOException {
public int deleteEvent(String path, String eventName) throws IOException {
if (path.startsWith("INBOX")) {
// do not delete calendar messages, move to trash
moveToTrash(getFolderPath(URIUtil.decode(path)));
moveToTrash(URIUtil.encodePath(getFolderPath(URIUtil.decode(path))), eventName);
} else {
wdr.deleteMethod(getFolderPath(URIUtil.decode(path)));
DeleteMethod method = new DeleteMethod(URIUtil.encodePath(getFolderPath(URIUtil.decode(path)))+"/"+eventName);
int status = wdr.retrieveSessionInstance().executeMethod(method);
if (status != HttpStatus.SC_OK) {
HttpException ex = new HttpException();
ex.setReasonCode(status);
ex.setReason(wdr.getStatusMessage());
throw ex;
}
}
return wdr.getStatusCode();
}