EWS: in direct EWS mode, try to use ResolveNames to get current user email address

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@2212 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2014-01-19 23:04:07 +00:00
parent 965142841a
commit d8000b6497
1 changed files with 30 additions and 1 deletions

View File

@ -211,7 +211,13 @@ public class EwsExchangeSession extends ExchangeSession {
} else {
// userName or domain\\username, rebuild email address
alias = getAliasFromLogin();
email = getAliasFromLogin() + getEmailSuffixFromHostname();
// try to get email address with ResolveNames
email = resolveEmailAddress(userName);
// failover, build from host name
if (email == null) {
email = getAliasFromLogin() + getEmailSuffixFromHostname();
}
}
}
@ -287,6 +293,29 @@ public class EwsExchangeSession extends ExchangeSession {
LOGGER.debug("Current user email is " + email + ", alias is " + alias + " on " + serverVersion);
}
public String resolveEmailAddress(String userName) {
String email = null;
String searchValue = userName;
int index = searchValue.indexOf('\\');
if (index >= 0) {
searchValue = searchValue.substring(index+1);
}
ResolveNamesMethod resolveNamesMethod = new ResolveNamesMethod(searchValue);
try {
// send a fake request to get server version
internalGetFolder("");
executeMethod(resolveNamesMethod);
List<EWSMethod.Item> responses = resolveNamesMethod.getResponseItems();
if (responses.size() == 1) {
email = responses.get(0).get("EmailAddress");
}
} catch (IOException e) {
// ignore
}
return email;
}
protected static class AutoDiscoverMethod extends PostMethod {
AutoDiscoverMethod(String autodiscoverHost, String userEmail) {
super("https://" + autodiscoverHost + "/autodiscover/autodiscover.xml");