diff --git a/davmail.jsmooth b/davmail.jsmooth
index 43118344..bc2fc2df 100644
--- a/davmail.jsmooth
+++ b/davmail.jsmooth
@@ -18,6 +18,7 @@
dist\lib\saxpath-1.0-FCS.jar
dist\lib\slide-webdavlib-2.1.jar
dist\lib\swt-3.3-win32-x86.jar
+dist\lib\htmlcleaner-2.1.jar
dist\davmail.jar
false
dist\davmail.exe
diff --git a/davmailconsole.jsmooth b/davmailconsole.jsmooth
index 2627683b..a747f260 100644
--- a/davmailconsole.jsmooth
+++ b/davmailconsole.jsmooth
@@ -18,6 +18,7 @@
dist\lib\saxpath-1.0-FCS.jar
dist\lib\slide-webdavlib-2.1.jar
dist\lib\swt-3.3-win32-x86.jar
+dist\lib\htmlcleaner-2.1.jar
dist\davmail.jar
false
dist\davmailconsole.exe
diff --git a/lib/htmlcleaner-2.1.jar b/lib/htmlcleaner-2.1.jar
new file mode 100644
index 00000000..ca14f056
Binary files /dev/null and b/lib/htmlcleaner-2.1.jar differ
diff --git a/pom.xml b/pom.xml
index ec9d00fe..d363d222 100644
--- a/pom.xml
+++ b/pom.xml
@@ -107,6 +107,11 @@
servlet-api
2.4
+
+ htmlcleaner
+ htmlcleaner
+ 2.1
+
src/java
diff --git a/src/java/davmail/exchange/ExchangeSession.java b/src/java/davmail/exchange/ExchangeSession.java
index 768594de..f28a0298 100644
--- a/src/java/davmail/exchange/ExchangeSession.java
+++ b/src/java/davmail/exchange/ExchangeSession.java
@@ -13,6 +13,8 @@ import org.apache.webdav.lib.Property;
import org.apache.webdav.lib.ResponseEntity;
import org.apache.webdav.lib.WebdavResource;
import org.apache.webdav.lib.methods.SearchMethod;
+import org.htmlcleaner.HtmlCleaner;
+import org.htmlcleaner.TagNode;
import javax.mail.internet.MimeUtility;
import javax.xml.stream.XMLInputFactory;
@@ -100,88 +102,73 @@ public class ExchangeSession {
* Try to find logon method path from logon form body.
*
* @param initmethod form body http method
- * @return logon method path
+ * @return logon method
*/
- protected String getLogonMethodPathAndBaseUrl(HttpMethod initmethod) {
- // default logon method path
- String logonMethodPath = "/exchweb/bin/auth/owaauth.dll";
+ protected PostMethod buildLogonMethod(HttpClient httpClient, HttpMethod initmethod) throws IOException {
+
+ PostMethod logonMethod = null;
+
+ // create an instance of HtmlCleaner
+ HtmlCleaner cleaner = new HtmlCleaner();
- // 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 = "