From 3e9bca74e5b342453b84bab9e52709653981ec77 Mon Sep 17 00:00:00 2001 From: mguessan Date: Wed, 27 Oct 2010 08:52:27 +0000 Subject: [PATCH] IMAP: failover in message copyon 404 not found git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1518 3d1905a2-6b24-0410-a738-b14d5a86fcbd --- src/java/davmail/exchange/dav/DavExchangeSession.java | 11 ++++++++++- src/java/davmail/http/DavGatewayHttpClientFacade.java | 4 ++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/java/davmail/exchange/dav/DavExchangeSession.java b/src/java/davmail/exchange/dav/DavExchangeSession.java index 37d01f27..ef3d9259 100644 --- a/src/java/davmail/exchange/dav/DavExchangeSession.java +++ b/src/java/davmail/exchange/dav/DavExchangeSession.java @@ -2548,8 +2548,17 @@ public class DavExchangeSession extends ExchangeSession { */ @Override public void copyMessage(ExchangeSession.Message message, String targetFolder) throws IOException { + try { + copyMessage(message.permanentUrl, targetFolder); + } catch (HttpNotFoundException e) { + LOGGER.debug("404 not found at permanenturl: " + message.permanentUrl + ", retry with messageurl"); + copyMessage(message.messageUrl, targetFolder); + } + } + + protected void copyMessage(String sourceUrl, String targetFolder) throws IOException { String targetPath = URIUtil.encodePath(getFolderPath(targetFolder)) + '/' + UUID.randomUUID().toString(); - CopyMethod method = new CopyMethod(message.permanentUrl, targetPath, false); + CopyMethod method = new CopyMethod(sourceUrl, targetPath, false); // allow rename if a message with the same name exists method.addRequestHeader("Allow-Rename", "t"); try { diff --git a/src/java/davmail/http/DavGatewayHttpClientFacade.java b/src/java/davmail/http/DavGatewayHttpClientFacade.java index fc7081dc..cb26da8d 100644 --- a/src/java/davmail/http/DavGatewayHttpClientFacade.java +++ b/src/java/davmail/http/DavGatewayHttpClientFacade.java @@ -36,6 +36,7 @@ import org.apache.commons.httpclient.util.IdleConnectionTimeoutThread; import org.apache.commons.httpclient.util.URIUtil; import org.apache.jackrabbit.webdav.DavException; import org.apache.jackrabbit.webdav.MultiStatusResponse; +import org.apache.jackrabbit.webdav.client.methods.CopyMethod; import org.apache.jackrabbit.webdav.client.methods.DavMethodBase; import org.apache.jackrabbit.webdav.client.methods.PropFindMethod; import org.apache.jackrabbit.webdav.property.DavPropertyNameSet; @@ -638,6 +639,9 @@ public final class DavGatewayHttpClientFacade { message.append(status).append(' ').append(method.getStatusText()); try { message.append(" at ").append(method.getURI().getURI()); + if (method instanceof CopyMethod) { + message.append(" to ").append(method.getRequestHeader("Destination")); + } } catch (URIException e) { message.append(method.getPath()); }