1
0
mirror of https://github.com/moparisthebest/davmail synced 2024-11-10 11:25:00 -05:00

Caldav: implement main calendar folder rename

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1490 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2010-10-04 21:24:50 +00:00
parent 7798e535c9
commit 2616e823fa
4 changed files with 46 additions and 6 deletions

View File

@ -25,6 +25,7 @@ import davmail.Settings;
import davmail.exception.DavMailAuthenticationException;
import davmail.exception.DavMailException;
import davmail.exception.HttpNotFoundException;
import davmail.exception.HttpPreconditionFailedException;
import davmail.exchange.ExchangeSession;
import davmail.exchange.ExchangeSessionFactory;
import davmail.exchange.ICSBufferedReader;
@ -643,7 +644,7 @@ public class CaldavConnection extends AbstractConnection {
public void patchCalendar(CaldavRequest request) throws IOException {
String displayname = request.getProperty("displayname");
String folderPath = request.getFolderPath();
if (displayname != null && !folderPath.equalsIgnoreCase("/users/" + session.getEmail() + "/calendar")) {
if (displayname != null) {
String targetPath = request.getParentFolderPath() + '/' + displayname;
if (!targetPath.equals(folderPath)) {
session.moveFolder(folderPath, targetPath);
@ -1042,6 +1043,8 @@ public class CaldavConnection extends AbstractConnection {
}
if (e instanceof HttpNotFoundException) {
sendErr(HttpStatus.SC_NOT_FOUND, message);
} else if (e instanceof HttpPreconditionFailedException) {
sendErr(HttpStatus.SC_PRECONDITION_FAILED, message);
} else {
sendErr(HttpStatus.SC_SERVICE_UNAVAILABLE, message);
}

View File

@ -0,0 +1,35 @@
/*
* DavMail POP/IMAP/SMTP/CalDav/LDAP Exchange Gateway
* Copyright (C) 2009 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.exception;
import org.apache.commons.httpclient.HttpException;
/**
* HttpException with 412 precondition failed status.
*/
public class HttpPreconditionFailedException extends HttpException {
/**
* HttpException with 412 precondition failed status.
*
* @param message exception message
*/
public HttpPreconditionFailedException(String message) {
super(message);
}
}

View File

@ -20,10 +20,7 @@ package davmail.exchange.dav;
import davmail.BundleMessage;
import davmail.Settings;
import davmail.exception.DavMailAuthenticationException;
import davmail.exception.DavMailException;
import davmail.exception.HttpNotFoundException;
import davmail.exception.InsufficientStorageException;
import davmail.exception.*;
import davmail.exchange.*;
import davmail.http.DavGatewayHttpClientFacade;
import davmail.ui.tray.DavGatewayTray;
@ -1712,9 +1709,12 @@ public class DavExchangeSession extends ExchangeSession {
try {
int statusCode = httpClient.executeMethod(method);
if (statusCode == HttpStatus.SC_PRECONDITION_FAILED) {
throw new DavMailException("EXCEPTION_UNABLE_TO_MOVE_FOLDER");
throw new HttpPreconditionFailedException(BundleMessage.format("EXCEPTION_UNABLE_TO_MOVE_FOLDER"));
} else if (statusCode != HttpStatus.SC_CREATED) {
throw DavGatewayHttpClientFacade.buildHttpException(method);
} else if (folderPath.equalsIgnoreCase("/users/" + getEmail() + "/calendar")) {
// calendar renamed, need to reload well known folders
getWellKnownFolders();
}
} finally {
method.releaseConnection();

View File

@ -642,6 +642,8 @@ public final class DavGatewayHttpClientFacade {
return new HttpForbiddenException(message.toString());
} else if (status == HttpStatus.SC_NOT_FOUND) {
return new HttpNotFoundException(message.toString());
} else if (status == HttpStatus.SC_PRECONDITION_FAILED) {
return new HttpPreconditionFailedException(message.toString());
} else if (status == HttpStatus.SC_INTERNAL_SERVER_ERROR) {
return new HttpServerErrorException(message.toString());
} else {