1
0
mirror of https://github.com/moparisthebest/davmail synced 2024-12-13 11:12:22 -05:00

Caldav: more general fix for misconfigured Exchange server, replace host name in url also over Caldav

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1774 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2011-08-13 20:39:53 +00:00
parent e74f9bbdb2
commit ed14e65e82

View File

@ -1292,9 +1292,18 @@ public class DavExchangeSession extends ExchangeSession {
// PropFind PR_INTERNET_CONTENT // PropFind PR_INTERNET_CONTENT
DavPropertyNameSet davPropertyNameSet = new DavPropertyNameSet(); DavPropertyNameSet davPropertyNameSet = new DavPropertyNameSet();
davPropertyNameSet.add(Field.getPropertyName("internetContent")); davPropertyNameSet.add(Field.getPropertyName("internetContent"));
PropFindMethod propFindMethod = new PropFindMethod(URIUtil.encodePath(permanentUrl), davPropertyNameSet, 0); PropFindMethod propFindMethod = new PropFindMethod(encodeAndFixUrl(permanentUrl), davPropertyNameSet, 0);
try { try {
DavGatewayHttpClientFacade.executeHttpMethod(httpClient, propFindMethod); try {
DavGatewayHttpClientFacade.executeHttpMethod(httpClient, propFindMethod);
} catch (UnknownHostException e) {
propFindMethod.releaseConnection();
// failover for misconfigured Exchange server, replace host name in url
restoreHostName = true;
propFindMethod = new PropFindMethod(encodeAndFixUrl(permanentUrl), davPropertyNameSet, 0);
DavGatewayHttpClientFacade.executeHttpMethod(httpClient, propFindMethod);
}
MultiStatus responses = propFindMethod.getResponseBodyAsMultiStatus(); MultiStatus responses = propFindMethod.getResponseBodyAsMultiStatus();
if (responses.getResponses().length > 0) { if (responses.getResponses().length > 0) {
DavPropertySet properties = responses.getResponses()[0].getProperties(HttpStatus.SC_OK); DavPropertySet properties = responses.getResponses()[0].getProperties(HttpStatus.SC_OK);
@ -1325,7 +1334,7 @@ public class DavExchangeSession extends ExchangeSession {
try { try {
result = getICSFromInternetContentProperty(); result = getICSFromInternetContentProperty();
if (result == null) { if (result == null) {
GetMethod method = new GetMethod(permanentUrl); GetMethod method = new GetMethod(encodeAndFixUrl(permanentUrl));
method.setRequestHeader("Content-Type", "text/xml; charset=utf-8"); method.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
method.setRequestHeader("Translate", "f"); method.setRequestHeader("Translate", "f");
try { try {
@ -2069,7 +2078,7 @@ public class DavExchangeSession extends ExchangeSession {
} }
DavGatewayTray.debug(new BundleMessage("LOG_SEARCH_QUERY", searchRequest)); DavGatewayTray.debug(new BundleMessage("LOG_SEARCH_QUERY", searchRequest));
MultiStatusResponse[] responses = DavGatewayHttpClientFacade.executeSearchMethod( MultiStatusResponse[] responses = DavGatewayHttpClientFacade.executeSearchMethod(
httpClient, URIUtil.encodePath(folderUrl), searchRequest.toString(), maxCount); httpClient, encodeAndFixUrl(folderUrl), searchRequest.toString(), maxCount);
DavGatewayTray.debug(new BundleMessage("LOG_SEARCH_RESULT", responses.length)); DavGatewayTray.debug(new BundleMessage("LOG_SEARCH_RESULT", responses.length));
return responses; return responses;
} }
@ -2632,15 +2641,15 @@ public class DavExchangeSession extends ExchangeSession {
try { try {
try { try {
try { try {
contentInputStream = getContentInputStream(message.messageUrl, restoreHostName); contentInputStream = getContentInputStream(message.messageUrl);
} catch (UnknownHostException e) { } catch (UnknownHostException e) {
// failover for misconfigured Exchange server, replace host name in url // failover for misconfigured Exchange server, replace host name in url
restoreHostName = true; restoreHostName = true;
contentInputStream = getContentInputStream(message.messageUrl, restoreHostName); contentInputStream = getContentInputStream(message.messageUrl);
} }
} catch (HttpNotFoundException e) { } catch (HttpNotFoundException e) {
LOGGER.debug("Message not found at: " + message.messageUrl + ", retrying with permanenturl"); LOGGER.debug("Message not found at: " + message.messageUrl + ", retrying with permanenturl");
contentInputStream = getContentInputStream(message.permanentUrl, restoreHostName); contentInputStream = getContentInputStream(message.permanentUrl);
} }
try { try {
@ -2735,14 +2744,19 @@ public class DavExchangeSession extends ExchangeSession {
return uri.getEscapedURI(); return uri.getEscapedURI();
} }
protected InputStream getContentInputStream(String url, boolean fixHostName) throws IOException { public String encodeAndFixUrl(String url) throws URIException {
String actualUrl = URIUtil.encodePath(url); String originalUrl = URIUtil.encodePath(url);
if (fixHostName) { if (restoreHostName && originalUrl.startsWith("http")) {
String targetPath = new URI(actualUrl, true).getEscapedPath(); String targetPath = new URI(originalUrl, true).getEscapedPath();
actualUrl = getEscapedUrlFromPath(targetPath); originalUrl = getEscapedUrlFromPath(targetPath);
} }
return originalUrl;
}
final GetMethod method = new GetMethod(actualUrl); protected InputStream getContentInputStream(String url) throws IOException {
String encodedUrl = encodeAndFixUrl(url);
final GetMethod method = new GetMethod(encodedUrl);
method.setRequestHeader("Content-Type", "text/xml; charset=utf-8"); method.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
method.setRequestHeader("Translate", "f"); method.setRequestHeader("Translate", "f");
method.setRequestHeader("Accept-Encoding", "gzip"); method.setRequestHeader("Accept-Encoding", "gzip");