From 2616e823faee7897269d6132995f2a065816d8c6 Mon Sep 17 00:00:00 2001 From: mguessan Date: Mon, 4 Oct 2010 21:24:50 +0000 Subject: [PATCH] Caldav: implement main calendar folder rename git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1490 3d1905a2-6b24-0410-a738-b14d5a86fcbd --- src/java/davmail/caldav/CaldavConnection.java | 5 ++- .../HttpPreconditionFailedException.java | 35 +++++++++++++++++++ .../exchange/dav/DavExchangeSession.java | 10 +++--- .../http/DavGatewayHttpClientFacade.java | 2 ++ 4 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 src/java/davmail/exception/HttpPreconditionFailedException.java diff --git a/src/java/davmail/caldav/CaldavConnection.java b/src/java/davmail/caldav/CaldavConnection.java index 8aabb2e8..386ca209 100644 --- a/src/java/davmail/caldav/CaldavConnection.java +++ b/src/java/davmail/caldav/CaldavConnection.java @@ -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); } diff --git a/src/java/davmail/exception/HttpPreconditionFailedException.java b/src/java/davmail/exception/HttpPreconditionFailedException.java new file mode 100644 index 00000000..458452c4 --- /dev/null +++ b/src/java/davmail/exception/HttpPreconditionFailedException.java @@ -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); + } +} diff --git a/src/java/davmail/exchange/dav/DavExchangeSession.java b/src/java/davmail/exchange/dav/DavExchangeSession.java index dd0f4e94..a03eb0ee 100644 --- a/src/java/davmail/exchange/dav/DavExchangeSession.java +++ b/src/java/davmail/exchange/dav/DavExchangeSession.java @@ -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(); diff --git a/src/java/davmail/http/DavGatewayHttpClientFacade.java b/src/java/davmail/http/DavGatewayHttpClientFacade.java index 6bfebaf6..8a7a66f4 100644 --- a/src/java/davmail/http/DavGatewayHttpClientFacade.java +++ b/src/java/davmail/http/DavGatewayHttpClientFacade.java @@ -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 {