diff --git a/src/java/davmail/DavGateway.java b/src/java/davmail/DavGateway.java index b062c30d..19fba882 100644 --- a/src/java/davmail/DavGateway.java +++ b/src/java/davmail/DavGateway.java @@ -1,7 +1,7 @@ package davmail; import davmail.http.DavGatewaySSLProtocolSocketFactory; -import davmail.http.DavGatewayHttpClientFactory; +import davmail.http.DavGatewayHttpClientFacade; import davmail.pop.PopServer; import davmail.smtp.SmtpServer; import davmail.tray.DavGatewayTray; @@ -103,9 +103,9 @@ public class DavGateway { public static String getReleasedVersion() { String version = null; BufferedReader versionReader = null; + GetMethod getMethod = new GetMethod("http://davmail.sourceforge.net/version.txt"); try { - HttpClient httpClient = DavGatewayHttpClientFactory.getInstance(); - GetMethod getMethod = new GetMethod("http://davmail.sourceforge.net/version.txt"); + HttpClient httpClient = DavGatewayHttpClientFacade.getInstance(); int status = httpClient.executeMethod(getMethod); if (status == HttpStatus.SC_OK) { versionReader = new BufferedReader(new InputStreamReader(getMethod.getResponseBodyAsStream())); @@ -121,6 +121,7 @@ public class DavGateway { // ignore } } + getMethod.releaseConnection(); } return version; } diff --git a/src/java/davmail/exchange/ExchangeSession.java b/src/java/davmail/exchange/ExchangeSession.java index 7db1425d..43606a90 100644 --- a/src/java/davmail/exchange/ExchangeSession.java +++ b/src/java/davmail/exchange/ExchangeSession.java @@ -1,7 +1,7 @@ package davmail.exchange; import davmail.Settings; -import davmail.http.DavGatewayHttpClientFactory; +import davmail.http.DavGatewayHttpClientFacade; import org.apache.commons.httpclient.Header; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; @@ -63,6 +63,11 @@ public class ExchangeSession { */ private final SimpleDateFormat dateParser; + /** + * Base Exchange URL + */ + private String baseUrl; + /** * Various standard mail boxes Urls */ @@ -97,32 +102,150 @@ public class ExchangeSession { * @throws java.io.IOException unable to connect to exchange */ protected boolean isBasicAuthentication(String url) throws IOException { - // create an HttpClient instance - HttpClient httpClient = DavGatewayHttpClientFactory.getInstance(); - HttpMethod testMethod = new GetMethod(url); - int status = httpClient.executeMethod(testMethod); - testMethod.releaseConnection(); - return status == HttpStatus.SC_UNAUTHORIZED; + return DavGatewayHttpClientFacade.getHttpStatus(url) == HttpStatus.SC_UNAUTHORIZED; + } + + /** + * Try to find logon method path from logon form body. + * + * @param initmethod form body http method + * @return logon method path + */ + protected String getLogonMethodPathAndBaseUrl(HttpMethod initmethod) { + // default logon method path + String logonMethodPath = "/exchweb/bin/auth/owaauth.dll"; + + // try to parse login form to determine logon url and destination + BufferedReader loginFormReader = null; + try { + loginFormReader = new BufferedReader(new InputStreamReader(initmethod.getResponseBodyAsStream())); + String line; + // skip to form action + final String FORM_ACTION = "