1
0
mirror of https://github.com/moparisthebest/davmail synced 2024-12-14 03:32:22 -05:00

Refactor buildSessionInfo to use /public first and mailbox path as failover for galfind requests

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1726 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2011-07-04 21:49:36 +00:00
parent f5a4ed2935
commit c7b8da9c8d
2 changed files with 47 additions and 51 deletions

View File

@ -3032,24 +3032,6 @@ public abstract class ExchangeSession {
*/
public abstract boolean isSharedFolder(String folderPath);
/**
* Build base path for cmd commands (galfind, gallookup).
* This does not work with freebusy, which requires /public/
*
* @return cmd base path
*/
public String getCmdBasePath() {
if (mailPath == null) {
if (publicFolderUrl == null) {
return "/public/";
} else {
return publicFolderUrl + '/';
}
} else {
return mailPath;
}
}
static final String MAILBOX_BASE = "/cn=";
protected void getEmailAndAliasFromOptions() {

View File

@ -203,6 +203,22 @@ public class DavExchangeSession extends ExchangeSession {
return !getFolderPath(folderPath).toLowerCase().startsWith(mailPath.toLowerCase());
}
/**
* Build base path for cmd commands (galfind, gallookup).
*
* @return cmd base path
*/
public String getCmdBasePath() {
if (PUBLIC_ROOT.equals(publicFolderUrl)) {
// public folder is not available => try to use mailbox path
// Note: This does not work with freebusy, which requires /public/
return mailPath;
} else {
// use public folder url
return publicFolderUrl;
}
}
/**
* LDAP to Exchange Criteria Map
*/
@ -448,6 +464,8 @@ public class DavExchangeSession extends ExchangeSession {
@Override
protected void buildSessionInfo(HttpMethod method) throws DavMailException {
checkPublicFolder();
buildMailPath(method);
// get base http mailbox http urls
@ -677,6 +695,35 @@ public class DavExchangeSession extends ExchangeSession {
}
}
protected void checkPublicFolder() {
Cookie[] currentCookies = httpClient.getState().getCookies();
// check public folder access
try {
publicFolderUrl = httpClient.getHostConfiguration().getHostURL()+PUBLIC_ROOT;
DavPropertyNameSet davPropertyNameSet = new DavPropertyNameSet();
davPropertyNameSet.add(Field.getPropertyName("displayname"));
PropFindMethod propFindMethod = new PropFindMethod(publicFolderUrl, davPropertyNameSet, 0);
try {
DavGatewayHttpClientFacade.executeMethod(httpClient, propFindMethod);
} catch (IOException e) {
// workaround for NTLM authentication only on /public
if (!DavGatewayHttpClientFacade.hasNTLM(httpClient)) {
DavGatewayHttpClientFacade.addNTLM(httpClient);
DavGatewayHttpClientFacade.executeMethod(httpClient, propFindMethod);
}
}
// update public folder URI
publicFolderUrl = propFindMethod.getURI().getURI();
} catch (IOException e) {
// restore cookies on error
httpClient.getState().addCookies(currentCookies);
LOGGER.warn("Public folders not available: " + (e.getMessage() == null ? e : e.getMessage()));
// default public folder path
publicFolderUrl = PUBLIC_ROOT;
}
}
protected void getWellKnownFolders() throws DavMailException {
// Retrieve well known URLs
MultiStatusResponse[] responses;
@ -705,39 +752,6 @@ public class DavExchangeSession extends ExchangeSession {
outboxName = getFolderName(outboxUrl);
// junk folder not available over webdav
// default public folder path
publicFolderUrl = PUBLIC_ROOT;
Cookie[] currentCookies = httpClient.getState().getCookies();
// check public folder access
try {
if (inboxUrl != null) {
// try to build full public URI from inboxUrl
URI publicUri = new URI(inboxUrl, false);
publicUri.setPath(PUBLIC_ROOT);
publicFolderUrl = publicUri.getURI();
}
DavPropertyNameSet davPropertyNameSet = new DavPropertyNameSet();
davPropertyNameSet.add(Field.getPropertyName("displayname"));
PropFindMethod propFindMethod = new PropFindMethod(publicFolderUrl, davPropertyNameSet, 0);
try {
DavGatewayHttpClientFacade.executeMethod(httpClient, propFindMethod);
} catch (IOException e) {
// workaround for NTLM authentication only on /public
if (!DavGatewayHttpClientFacade.hasNTLM(httpClient)) {
DavGatewayHttpClientFacade.addNTLM(httpClient);
DavGatewayHttpClientFacade.executeMethod(httpClient, propFindMethod);
}
}
// update public folder URI
publicFolderUrl = propFindMethod.getURI().getURI();
} catch (IOException e) {
// restore cookies on error
httpClient.getState().addCookies(currentCookies);
LOGGER.warn("Public folders not available: " + (e.getMessage() == null ? e : e.getMessage()));
publicFolderUrl = "/public";
}
LOGGER.debug("Inbox URL: " + inboxUrl +
" Trash URL: " + deleteditemsUrl +
" Sent URL: " + sentitemsUrl +