diff --git a/src/java/davmail/exception/DavMailAuthenticationException.java b/src/java/davmail/exception/DavMailAuthenticationException.java index 259edc4b..c292ae77 100644 --- a/src/java/davmail/exception/DavMailAuthenticationException.java +++ b/src/java/davmail/exception/DavMailAuthenticationException.java @@ -18,6 +18,8 @@ */ package davmail.exception; +import davmail.BundleMessage; + /** * I18 AuthenticationException subclass. */ @@ -30,4 +32,14 @@ public class DavMailAuthenticationException extends DavMailException { public DavMailAuthenticationException(String key) { super(key); } + + /** + * Create a DavMail authentication exception with the given BundleMessage key and arguments. + * + * @param key message key + */ + public DavMailAuthenticationException(String key, Object... arguments) { + super(key, arguments); + } + } diff --git a/src/java/davmail/exchange/ExchangeSession.java b/src/java/davmail/exchange/ExchangeSession.java index c358f344..288434c4 100644 --- a/src/java/davmail/exchange/ExchangeSession.java +++ b/src/java/davmail/exchange/ExchangeSession.java @@ -366,10 +366,10 @@ public class ExchangeSession { logonMethod.addParameter(name, value); } // custom login form - if ("txtUserName".equals(name)) { - userNameInput = "txtUserName"; - } else if ("txtUserPass".equals(name)) { - passwordInput = "txtUserPass"; + if ("txtUserName".equals(name) || "userid".equals(name)) { + userNameInput = name; + } else if ("txtUserPass".equals(name) || "pw".equals(name)) { + passwordInput = name; } else if ("addr".equals(name)) { // this is not a logon form but a redirect form HttpMethod newInitMethod = DavGatewayHttpClientFacade.executeFollowRedirects(httpClient, logonMethod); @@ -450,6 +450,9 @@ public class ExchangeSession { throw new DavMailException("EXCEPTION_AUTHENTICATION_FORM_NOT_FOUND", initmethod.getURI()); } + // make sure username and password fields are empty + ((PostMethod) logonMethod).removeParameter(userNameInput); + ((PostMethod) logonMethod).removeParameter(passwordInput); ((PostMethod) logonMethod).addParameter(userNameInput, userName); ((PostMethod) logonMethod).addParameter(passwordInput, password); ((PostMethod) logonMethod).addParameter("trusted", "4"); @@ -628,7 +631,7 @@ public class ExchangeSession { ); } catch (IOException e) { LOGGER.error(e.getMessage()); - throw new DavMailException("EXCEPTION_UNABLE_TO_GET_MAIL_FOLDER", mailPath); + throw new DavMailAuthenticationException("EXCEPTION_UNABLE_TO_GET_MAIL_FOLDER", mailPath); } }