Caldav: failover for Exchange 2007 plus encoding issue, search event by displayname to get permanent Url

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@843 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2009-11-17 23:11:08 +00:00
parent 3044ffc9e5
commit ea9c8239b4
2 changed files with 31 additions and 10 deletions

View File

@ -20,15 +20,16 @@ package davmail.caldav;
import davmail.AbstractConnection;
import davmail.BundleMessage;
import davmail.Settings;
import davmail.DavGateway;
import davmail.util.StringUtil;
import davmail.Settings;
import davmail.exception.DavMailAuthenticationException;
import davmail.exception.DavMailException;
import davmail.exception.HttpNotFoundException;
import davmail.exchange.ExchangeSession;
import davmail.exchange.ExchangeSessionFactory;
import davmail.exchange.ICSBufferedReader;
import davmail.ui.tray.DavGatewayTray;
import davmail.util.StringUtil;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.util.URIUtil;
@ -612,7 +613,20 @@ public class CaldavConnection extends AbstractConnection {
// ignore cases for Sunbird
if (eventName != null && eventName.length() > 0
&& !"inbox".equals(eventName) && !"calendar".equals(eventName)) {
appendEventResponse(response, request, session.getEvent(folderPath, eventName));
ExchangeSession.Event event;
try {
event = session.getEvent(folderPath, eventName);
} catch (HttpNotFoundException hnfe) {
// failover for Exchange 2007 plus encoding issue
String decodedEventName = eventName.replaceAll("_xF8FF_", "/").replaceAll("_x003F_", "?").replaceAll("'", "''");
ExchangeSession.MessageList messages = session.searchMessages(folderPath, " AND \"DAV:displayname\"='"+decodedEventName+ '\'');
if (!messages.isEmpty()) {
event = session.getEvent(messages.get(0).getPermanentUrl());
} else {
throw hnfe;
}
}
appendEventResponse(response, request, event);
}
} catch (HttpException e) {
DavGatewayTray.warn(new BundleMessage("LOG_EVENT_NOT_FOUND", href));

View File

@ -1392,12 +1392,12 @@ public class ExchangeSession {
}
/**
* Return encoded message url.
* @return encoded message url
* Return permanent message url.
* @return permanent message url
* @throws URIException on error
*/
public String getEncodedMessageUrl() throws URIException {
return URIUtil.encodePath(messageUrl);
public String getPermanentUrl() throws URIException {
return permanentUrl;
}
/**
@ -1768,12 +1768,19 @@ public class ExchangeSession {
* @throws IOException on error
*/
public Event getEvent(String folderPath, String eventName) throws IOException {
String eventPath = URIUtil.encodePath(folderPath + '/' + eventName);
String eventPath = folderPath + '/' + eventName;
return getEvent(eventPath);
}
protected Event getEvent(String eventPath) throws IOException {
MultiStatusResponse[] responses = DavGatewayHttpClientFacade.executePropFindMethod(httpClient, eventPath, 0, EVENT_REQUEST_PROPERTIES);
/**
* Get event by url
*
* @param eventPath Event path
* @return event object
* @throws IOException on error
*/
public Event getEvent(String eventPath) throws IOException {
MultiStatusResponse[] responses = DavGatewayHttpClientFacade.executePropFindMethod(httpClient, URIUtil.encodePath(eventPath), 0, EVENT_REQUEST_PROPERTIES);
if (responses.length == 0) {
throw new DavMailException("EXCEPTION_EVENT_NOT_FOUND");
}