mirror of
https://github.com/moparisthebest/davmail
synced 2025-01-08 04:08:12 -05:00
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:
parent
965142841a
commit
d8000b6497
@ -211,9 +211,15 @@ public class EwsExchangeSession extends ExchangeSession {
|
|||||||
} else {
|
} else {
|
||||||
// userName or domain\\username, rebuild email address
|
// userName or domain\\username, rebuild email address
|
||||||
alias = getAliasFromLogin();
|
alias = getAliasFromLogin();
|
||||||
|
|
||||||
|
// try to get email address with ResolveNames
|
||||||
|
email = resolveEmailAddress(userName);
|
||||||
|
// failover, build from host name
|
||||||
|
if (email == null) {
|
||||||
email = getAliasFromLogin() + getEmailSuffixFromHostname();
|
email = getAliasFromLogin() + getEmailSuffixFromHostname();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
currentMailboxPath = "/users/" + email.toLowerCase();
|
currentMailboxPath = "/users/" + email.toLowerCase();
|
||||||
|
|
||||||
@ -287,6 +293,29 @@ public class EwsExchangeSession extends ExchangeSession {
|
|||||||
LOGGER.debug("Current user email is " + email + ", alias is " + alias + " on " + serverVersion);
|
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 {
|
protected static class AutoDiscoverMethod extends PostMethod {
|
||||||
AutoDiscoverMethod(String autodiscoverHost, String userEmail) {
|
AutoDiscoverMethod(String autodiscoverHost, String userEmail) {
|
||||||
super("https://" + autodiscoverHost + "/autodiscover/autodiscover.xml");
|
super("https://" + autodiscoverHost + "/autodiscover/autodiscover.xml");
|
||||||
|
Loading…
Reference in New Issue
Block a user