[geary/geary-0.11] Do not reset password unconditionally in case of login failure, but check for the reason. Bug 772808



commit a24a2bbfc0b5e5e0e9a49a09c1c443f59e83ed24
Author: Gautier Pelloux-Prayer <gautier+git damsy net>
Date:   Wed Oct 26 10:27:02 2016 +0200

    Do not reset password unconditionally in case of login failure, but check for the reason. Bug 772808

 src/client/application/geary-controller.vala       |    7 ++++
 src/engine/api/geary-account.vala                  |    1 +
 .../imap-engine/imap-engine-generic-account.vala   |   35 +++++++++++++------
 src/engine/imap/api/imap-account.vala              |    6 ++--
 .../transport/imap-client-session-manager.vala     |    6 ++--
 src/engine/imap/transport/imap-client-session.vala |    6 ++--
 6 files changed, 41 insertions(+), 20 deletions(-)
---
diff --git a/src/client/application/geary-controller.vala b/src/client/application/geary-controller.vala
index 8d7f806..4b084a3 100644
--- a/src/client/application/geary-controller.vala
+++ b/src/client/application/geary-controller.vala
@@ -1025,6 +1025,13 @@ public class GearyController : Geary.BaseObject {
                 handle_outbox_failure(StatusBar.Message.OUTBOX_SAVE_SENT_MAIL_FAILED);
             break;
             
+            case Geary.Account.Problem.CONNECTION_FAILURE:
+                ErrorDialog dialog = new ErrorDialog(main_window,
+                    _("Error connecting to the server"),
+                    _("Geary encountered an error while connecting to the server.  Please try again in a few 
moments."));
+                dialog.run();
+            break;
+
             default:
                 assert_not_reached();
         }
diff --git a/src/engine/api/geary-account.vala b/src/engine/api/geary-account.vala
index 33effd3..693aaf4 100644
--- a/src/engine/api/geary-account.vala
+++ b/src/engine/api/geary-account.vala
@@ -29,6 +29,7 @@ public abstract class Geary.Account : BaseObject {
         DATABASE_FAILURE,
         EMAIL_DELIVERY_FAILURE,
         SAVE_SENT_MAIL_FAILED,
+        CONNECTION_FAILURE,
     }
     
     public Geary.AccountInformation information { get; protected set; }
diff --git a/src/engine/imap-engine/imap-engine-generic-account.vala 
b/src/engine/imap-engine/imap-engine-generic-account.vala
index 974c3c8..de844b8 100644
--- a/src/engine/imap-engine/imap-engine-generic-account.vala
+++ b/src/engine/imap-engine/imap-engine-generic-account.vala
@@ -953,24 +953,37 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.Account {
         Gee.Collection<Geary.EmailIdentifier> ids, Cancellable? cancellable) throws Error {
         return yield local.get_containing_folders_async(ids, cancellable);
     }
-    
-    private void on_login_failed(Geary.Credentials? credentials) {
+
+    private void on_login_failed(Geary.Credentials? credentials, Geary.Imap.StatusResponse? response) {
         if (awaiting_credentials)
             return; // We're already asking for the password.
         
         awaiting_credentials = true;
-        do_login_failed_async.begin(credentials, () => { awaiting_credentials = false; });
+        do_login_failed_async.begin(credentials, response, () => { awaiting_credentials = false; });
     }
-    
-    private async void do_login_failed_async(Geary.Credentials? credentials) {
+
+    private async void do_login_failed_async(Geary.Credentials? credentials, Geary.Imap.StatusResponse? 
response) {
+        bool reask_password = true;
         try {
-            if (yield information.fetch_passwords_async(ServiceFlag.IMAP, true))
-                return;
-        } catch (Error e) {
-            debug("Error prompting for IMAP password: %s", e.message);
+            reask_password = (response == null || response.response_code.get_response_code_type().value != 
Geary.Imap.ResponseCodeType.UNAVAILABLE);
+        } catch (ImapError ierr) {
+            debug("Unable to parse ResponseCode %s: %s", response.response_code.to_string(),
+                ierr.message);
+        }
+        // login can fail due to an invalid password hence we should re-ask it
+        // but it can also fail due to server inaccessibility, for instance "[UNAVAILABLE] /
+        // Maximum number of connections from user+IP exceeded". In that case, resetting password seems 
unneeded.
+        if (reask_password) {
+            try {
+                if (yield information.fetch_passwords_async(ServiceFlag.IMAP, true))
+                    return;
+            } catch (Error e) {
+                debug("Error prompting for IMAP password: %s", e.message);
+            }
+            notify_report_problem(Geary.Account.Problem.RECV_EMAIL_LOGIN_FAILED, null);
+        } else {
+            notify_report_problem(Geary.Account.Problem.CONNECTION_FAILURE, null);
         }
-        
-        notify_report_problem(Geary.Account.Problem.RECV_EMAIL_LOGIN_FAILED, null);
     }
 }
 
diff --git a/src/engine/imap/api/imap-account.vala b/src/engine/imap/api/imap-account.vala
index eeb3dd0..6f44c23 100644
--- a/src/engine/imap/api/imap-account.vala
+++ b/src/engine/imap/api/imap-account.vala
@@ -37,7 +37,7 @@ private class Geary.Imap.Account : BaseObject {
     private string hierarchy_delimiter = null;
 
     
-    public signal void login_failed(Geary.Credentials cred);
+    public signal void login_failed(Geary.Credentials? cred, StatusResponse? response);
     
     public Account(Geary.AccountInformation account_information) {
         name = "IMAP Account for %s".printf(account_information.imap_credentials.to_string());
@@ -603,8 +603,8 @@ private class Geary.Imap.Account : BaseObject {
             (path != null) ? path.to_string() : "root", session_mgr.to_string());
     }
     
-    private void on_login_failed() {
-        login_failed(account_information.imap_credentials);
+    private void on_login_failed(StatusResponse? response) {
+        login_failed(account_information.imap_credentials, response);
     }
     
     public string to_string() {
diff --git a/src/engine/imap/transport/imap-client-session-manager.vala 
b/src/engine/imap/transport/imap-client-session-manager.vala
index 34405ba..45b9338 100644
--- a/src/engine/imap/transport/imap-client-session-manager.vala
+++ b/src/engine/imap/transport/imap-client-session-manager.vala
@@ -67,7 +67,7 @@ public class Geary.Imap.ClientSessionManager : BaseObject {
     private int authorized_session_retry_sec = AUTHORIZED_SESSION_ERROR_MIN_RETRY_TIMEOUT_SEC;
     private bool checking_reachable = false;
     
-    public signal void login_failed();
+    public signal void login_failed(StatusResponse? response);
     
     public ClientSessionManager(AccountInformation account_information) {
         this.account_information = account_information;
@@ -442,10 +442,10 @@ public class Geary.Imap.ClientSessionManager : BaseObject {
         force_disconnect_async.begin(session, false);
     }
     
-    private void on_login_failed(ClientSession session) {
+    private void on_login_failed(ClientSession session, StatusResponse? response) {
         authentication_failed = true;
         
-        login_failed();
+        login_failed(response);
         
         session.disconnect_async.begin();
     }
diff --git a/src/engine/imap/transport/imap-client-session.vala 
b/src/engine/imap/transport/imap-client-session.vala
index 9c7d58d..268d512 100644
--- a/src/engine/imap/transport/imap-client-session.vala
+++ b/src/engine/imap/transport/imap-client-session.vala
@@ -209,7 +209,7 @@ public class Geary.Imap.ClientSession : BaseObject {
     
     public signal void logged_out();
     
-    public signal void login_failed();
+    public signal void login_failed(StatusResponse? response);
     
     public signal void disconnected(DisconnectReason reason);
     
@@ -681,7 +681,7 @@ public class Geary.Imap.ClientSession : BaseObject {
     public async StatusResponse login_async(Geary.Credentials credentials, Cancellable? cancellable = null)
         throws Error {
         if (!credentials.is_complete()) {
-            login_failed();
+            login_failed(null);
             throw new ImapError.UNAUTHENTICATED("No credentials provided for account: %s", 
credentials.to_string());
         }
         
@@ -816,7 +816,7 @@ public class Geary.Imap.ClientSession : BaseObject {
             
             default:
                 debug("[%s] Unable to LOGIN: %s", to_string(), completion_response.to_string());
-                fsm.do_post_transition(() => { login_failed(); });
+                fsm.do_post_transition((resp) => { login_failed((StatusResponse)resp); }, 
completion_response);
                 
                 return State.NOAUTH;
         }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]