mirror of
https://github.com/moparisthebest/davmail
synced 2024-12-13 19:22:22 -05:00
IMAP: try to support public folders hosted on a separate server (302 redirect on PROPFIND)
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@878 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
f78a5ab913
commit
ce6906f666
@ -166,6 +166,7 @@ public class ExchangeSession {
|
|||||||
private String draftsUrl;
|
private String draftsUrl;
|
||||||
private String calendarUrl;
|
private String calendarUrl;
|
||||||
private String contactsUrl;
|
private String contactsUrl;
|
||||||
|
private String publicFolderUrl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base user mailboxes path (used to select folder)
|
* Base user mailboxes path (used to select folder)
|
||||||
@ -232,7 +233,7 @@ public class ExchangeSession {
|
|||||||
|
|
||||||
buildMailPath(method);
|
buildMailPath(method);
|
||||||
|
|
||||||
// got base http mailbox http url
|
// get base http mailbox http urls
|
||||||
getWellKnownFolders();
|
getWellKnownFolders();
|
||||||
|
|
||||||
} catch (DavMailAuthenticationException exc) {
|
} catch (DavMailAuthenticationException exc) {
|
||||||
@ -642,13 +643,24 @@ public class ExchangeSession {
|
|||||||
draftsUrl = getURIPropertyIfExists(properties, "drafts", URN_SCHEMAS_HTTPMAIL);
|
draftsUrl = getURIPropertyIfExists(properties, "drafts", URN_SCHEMAS_HTTPMAIL);
|
||||||
calendarUrl = getURIPropertyIfExists(properties, "calendar", URN_SCHEMAS_HTTPMAIL);
|
calendarUrl = getURIPropertyIfExists(properties, "calendar", URN_SCHEMAS_HTTPMAIL);
|
||||||
contactsUrl = getURIPropertyIfExists(properties, "contacts", URN_SCHEMAS_HTTPMAIL);
|
contactsUrl = getURIPropertyIfExists(properties, "contacts", URN_SCHEMAS_HTTPMAIL);
|
||||||
|
|
||||||
|
try {
|
||||||
|
PropFindMethod propFindMethod = new PropFindMethod("/public", CONTENT_TAG, 0);
|
||||||
|
DavGatewayHttpClientFacade.executeMethod(httpClient, propFindMethod);
|
||||||
|
publicFolderUrl = propFindMethod.getURI().getURI();
|
||||||
|
} catch (IOException e) {
|
||||||
|
LOGGER.warn("Public folders not available: " + (e.getMessage() == null ? e : e.getMessage()));
|
||||||
|
// default public folder path
|
||||||
|
publicFolderUrl = "/public";
|
||||||
|
}
|
||||||
LOGGER.debug("Inbox URL : " + inboxUrl +
|
LOGGER.debug("Inbox URL : " + inboxUrl +
|
||||||
" Trash URL : " + deleteditemsUrl +
|
" Trash URL : " + deleteditemsUrl +
|
||||||
" Sent URL : " + sentitemsUrl +
|
" Sent URL : " + sentitemsUrl +
|
||||||
" Send URL : " + sendmsgUrl +
|
" Send URL : " + sendmsgUrl +
|
||||||
" Drafts URL : " + draftsUrl +
|
" Drafts URL : " + draftsUrl +
|
||||||
" Calendar URL : " + calendarUrl +
|
" Calendar URL : " + calendarUrl +
|
||||||
" Contacts URL : " + contactsUrl
|
" Contacts URL : " + contactsUrl +
|
||||||
|
" Public folder URL : " + publicFolderUrl
|
||||||
);
|
);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOGGER.error(e.getMessage());
|
LOGGER.error(e.getMessage());
|
||||||
@ -737,7 +749,7 @@ public class ExchangeSession {
|
|||||||
message.messageId = message.messageId.substring(1, message.messageId.length() - 1);
|
message.messageId = message.messageId.substring(1, message.messageId.length() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGGER.debug("Found message IMAP uid: "+message.imapUid+" href: " + responseEntity.getHref()+" permanenturl:"+message.permanentUrl);
|
LOGGER.debug("Found message IMAP uid: " + message.imapUid + " href: " + responseEntity.getHref() + " permanenturl:" + message.permanentUrl);
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1086,7 +1098,7 @@ public class ExchangeSession {
|
|||||||
} else if (folderName.startsWith("calendar")) {
|
} else if (folderName.startsWith("calendar")) {
|
||||||
folderPath = folderName.replaceFirst("calendar", calendarUrl);
|
folderPath = folderName.replaceFirst("calendar", calendarUrl);
|
||||||
} else if (folderName.startsWith("public")) {
|
} else if (folderName.startsWith("public")) {
|
||||||
folderPath = '/' + folderName;
|
folderPath = publicFolderUrl + folderName.substring("public".length());
|
||||||
// absolute folder path
|
// absolute folder path
|
||||||
} else if (folderName.startsWith("/")) {
|
} else if (folderName.startsWith("/")) {
|
||||||
folderPath = folderName;
|
folderPath = folderName;
|
||||||
@ -1536,7 +1548,7 @@ public class ExchangeSession {
|
|||||||
}
|
}
|
||||||
isoWriter.flush();
|
isoWriter.flush();
|
||||||
} catch (HttpServerErrorException e) {
|
} catch (HttpServerErrorException e) {
|
||||||
LOGGER.warn("Unable to retrieve message at: "+messageUrl);
|
LOGGER.warn("Unable to retrieve message at: " + messageUrl);
|
||||||
throw e;
|
throw e;
|
||||||
} finally {
|
} finally {
|
||||||
if (reader != null) {
|
if (reader != null) {
|
||||||
@ -1770,7 +1782,7 @@ public class ExchangeSession {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected HttpException buildHttpException(Exception e) {
|
protected HttpException buildHttpException(Exception e) {
|
||||||
String message = "Unable to get event "+getName()+" at " + permanentUrl + ": " + e.getMessage();
|
String message = "Unable to get event " + getName() + " at " + permanentUrl + ": " + e.getMessage();
|
||||||
LOGGER.warn(message);
|
LOGGER.warn(message);
|
||||||
return new HttpException(message);
|
return new HttpException(message);
|
||||||
}
|
}
|
||||||
@ -2803,7 +2815,11 @@ public class ExchangeSession {
|
|||||||
*/
|
*/
|
||||||
public String getCmdBasePath() {
|
public String getCmdBasePath() {
|
||||||
if (mailPath == null) {
|
if (mailPath == null) {
|
||||||
return "/public/";
|
if (publicFolderUrl == null) {
|
||||||
|
return "/public/";
|
||||||
|
} else {
|
||||||
|
return publicFolderUrl + '/';
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return mailPath;
|
return mailPath;
|
||||||
}
|
}
|
||||||
@ -3216,7 +3232,7 @@ public class ExchangeSession {
|
|||||||
} else {
|
} else {
|
||||||
endDate = icalDateFormat.parse(endDateValue);
|
endDate = icalDateFormat.parse(endDateValue);
|
||||||
}
|
}
|
||||||
freebusyUrl = "/public/?cmd=freebusy" +
|
freebusyUrl = publicFolderUrl + "/?cmd=freebusy" +
|
||||||
"&start=" + exchangeZuluDateFormat.format(startDate) +
|
"&start=" + exchangeZuluDateFormat.format(startDate) +
|
||||||
"&end=" + exchangeZuluDateFormat.format(endDate) +
|
"&end=" + exchangeZuluDateFormat.format(endDate) +
|
||||||
"&interval=" + FREE_BUSY_INTERVAL +
|
"&interval=" + FREE_BUSY_INTERVAL +
|
||||||
|
@ -20,10 +20,7 @@ package davmail.http;
|
|||||||
|
|
||||||
import davmail.BundleMessage;
|
import davmail.BundleMessage;
|
||||||
import davmail.Settings;
|
import davmail.Settings;
|
||||||
import davmail.exception.DavMailException;
|
import davmail.exception.*;
|
||||||
import davmail.exception.HttpForbiddenException;
|
|
||||||
import davmail.exception.HttpNotFoundException;
|
|
||||||
import davmail.exception.HttpServerErrorException;
|
|
||||||
import davmail.ui.tray.DavGatewayTray;
|
import davmail.ui.tray.DavGatewayTray;
|
||||||
import org.apache.commons.httpclient.*;
|
import org.apache.commons.httpclient.*;
|
||||||
import org.apache.commons.httpclient.auth.AuthPolicy;
|
import org.apache.commons.httpclient.auth.AuthPolicy;
|
||||||
@ -326,6 +323,15 @@ public final class DavGatewayHttpClientFacade {
|
|||||||
try {
|
try {
|
||||||
int status = httpClient.executeMethod(method);
|
int status = httpClient.executeMethod(method);
|
||||||
|
|
||||||
|
// need to follow redirects (once) on public folders
|
||||||
|
if (isRedirect(status)) {
|
||||||
|
method.releaseConnection();
|
||||||
|
URI targetUri = new URI(method.getResponseHeader("Location").getValue(), true);
|
||||||
|
checkExpiredSession(targetUri.getQuery());
|
||||||
|
method.setURI(targetUri);
|
||||||
|
status = httpClient.executeMethod(method);
|
||||||
|
}
|
||||||
|
|
||||||
if (status != HttpStatus.SC_MULTI_STATUS) {
|
if (status != HttpStatus.SC_MULTI_STATUS) {
|
||||||
throw buildHttpException(method);
|
throw buildHttpException(method);
|
||||||
}
|
}
|
||||||
@ -382,9 +388,9 @@ public final class DavGatewayHttpClientFacade {
|
|||||||
// do not follow redirects in expired sessions
|
// do not follow redirects in expired sessions
|
||||||
method.setFollowRedirects(followRedirects);
|
method.setFollowRedirects(followRedirects);
|
||||||
int status = httpClient.executeMethod(method);
|
int status = httpClient.executeMethod(method);
|
||||||
if (status == HttpStatus.SC_UNAUTHORIZED & !hasNTLM(httpClient)) {
|
if (status == HttpStatus.SC_UNAUTHORIZED & !hasNTLM(httpClient)) {
|
||||||
method.releaseConnection();
|
method.releaseConnection();
|
||||||
LOGGER.debug("Received unauthorized at "+method.getURI()+", retrying with NTLM");
|
LOGGER.debug("Received unauthorized at " + method.getURI() + ", retrying with NTLM");
|
||||||
addNTLM(httpClient);
|
addNTLM(httpClient);
|
||||||
status = httpClient.executeMethod(method);
|
status = httpClient.executeMethod(method);
|
||||||
}
|
}
|
||||||
@ -395,6 +401,7 @@ public final class DavGatewayHttpClientFacade {
|
|||||||
// check for expired session
|
// check for expired session
|
||||||
if (followRedirects) {
|
if (followRedirects) {
|
||||||
String queryString = method.getQueryString();
|
String queryString = method.getQueryString();
|
||||||
|
checkExpiredSession(queryString);
|
||||||
if (queryString != null && queryString.contains("reason=2")) {
|
if (queryString != null && queryString.contains("reason=2")) {
|
||||||
LOGGER.warn("GET failed, session expired at " + method.getURI() + ": " + method.getResponseBodyAsString());
|
LOGGER.warn("GET failed, session expired at " + method.getURI() + ": " + method.getResponseBodyAsString());
|
||||||
throw DavGatewayHttpClientFacade.buildHttpException(method);
|
throw DavGatewayHttpClientFacade.buildHttpException(method);
|
||||||
@ -402,6 +409,13 @@ public final class DavGatewayHttpClientFacade {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void checkExpiredSession(String queryString) throws DavMailAuthenticationException {
|
||||||
|
if (queryString != null && queryString.contains("reason=2")) {
|
||||||
|
LOGGER.warn("Request failed, session expired (reason=2) ");
|
||||||
|
throw new DavMailAuthenticationException("EXCEPTION_SESSION_EXPIRED");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build Http Exception from methode status
|
* Build Http Exception from methode status
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user