From 2b56464ad9c183f772e7351edf9ae609b642f31f Mon Sep 17 00:00:00 2001 From: Kris Wong Date: Tue, 14 Dec 2010 18:02:39 +0000 Subject: [PATCH] Fix form based re-authentication when logon cookies had expired. --- src/com/fsck/k9/mail/store/WebDavStore.java | 34 ++++++++++++++------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/src/com/fsck/k9/mail/store/WebDavStore.java b/src/com/fsck/k9/mail/store/WebDavStore.java index 8689b0fd7..6bf7d951e 100644 --- a/src/com/fsck/k9/mail/store/WebDavStore.java +++ b/src/com/fsck/k9/mail/store/WebDavStore.java @@ -56,9 +56,7 @@ import java.util.zip.GZIPInputStream; /** *
  * Uses WebDAV formatted HTTP calls to an MS Exchange server to fetch email
- * and email information.  This has only been tested on an MS Exchange
- * Server 2003.  It uses Form-Based authentication and requires that
- * Outlook Web Access be enabled on the server.
+ * and email information.
  * 
*/ public class WebDavStore extends Store @@ -102,9 +100,8 @@ public class WebDavStore extends Store private HttpContext mContext = null; private CookieStore mAuthCookies = null; private short mAuthentication = AUTH_TYPE_NONE; - private long mLastAuth = -1; - private long mAuthTimeout = 5 * 60; - + private String mCachedLoginUrl; + private HashMap mFolderList = new HashMap(); /** @@ -573,7 +570,6 @@ public class WebDavStore extends Store if (statusCode >= 200 && statusCode < 300) { mAuthentication = AUTH_TYPE_BASIC; - mLastAuth = System.currentTimeMillis() / 1000; } else if (statusCode == 401) { @@ -653,7 +649,7 @@ public class WebDavStore extends Store // We will handle all 3 situations the same. First we take an educated // guess at where the authorization DLL is located. If this is this // doesn't work, then we'll use the redirection URL for OWA login given - // to use by exchange. We can use this to scrape the location of the + // to us by exchange. We can use this to scrape the location of the // authorization URL. info.requiredAuthType = AUTH_TYPE_FORM_BASED; @@ -696,9 +692,26 @@ public class WebDavStore extends Store */ public void doFBA(ConnectionInfo info) throws IOException, MessagingException { + // Clear out cookies from any previous authentication. + mAuthCookies.clear(); + WebDavHttpClient httpClient = getHttpClient(); + + String loginUrl = ""; + if (info != null) + { + loginUrl = info.guessedAuthUrl; + } + else if (mCachedLoginUrl != null && !mCachedLoginUrl.equals("")) + { + loginUrl = mCachedLoginUrl; + } + else + { + throw new MessagingException("No valid login URL available for form-based authentication."); + } - HttpGeneric request = new HttpGeneric(info.guessedAuthUrl); + HttpGeneric request = new HttpGeneric(loginUrl); request.setMethod("POST"); // Build the POST data. @@ -738,7 +751,6 @@ public class WebDavStore extends Store } }); - String loginUrl = ""; if (info != null) { loginUrl = info.redirectUrl; @@ -803,7 +815,7 @@ public class WebDavStore extends Store if (mAuthCookies != null && !mAuthCookies.getCookies().isEmpty()) { mAuthentication = AUTH_TYPE_FORM_BASED; - mLastAuth = System.currentTimeMillis() / 1000; + mCachedLoginUrl = loginUrl; } }