GData plugin: Request interactive auth only in case of auth issues
authorHolger Berndt <hb@claws-mail.org>
Mon, 25 Jun 2018 21:22:26 +0000 (23:22 +0200)
committerAndrej Kacian <ticho@claws-mail.org>
Sun, 8 Jul 2018 14:04:10 +0000 (16:04 +0200)
At the same time, make (now potentially ignored) errors more visible
in the status bar in the same way as background mail fetching errors
are reported.

Fixes bug #3754
Modified version of the patch by Viacheslav Gagara on that bug report.

src/plugins/gdata/cm_gdata_contacts.c

index e8d103428516dca2252d86bfe0c54913f76db813..1c6ba7dc90240fc15da55dac6f5c0134ac64abfb 100644 (file)
@@ -501,6 +501,7 @@ static void cm_gdata_interactive_auth()
 static void cm_gdata_refresh_ready(GDataOAuth2Authorizer *auth, GAsyncResult *res, gpointer data)
 {
   GError *error = NULL;
+  gboolean start_interactive_auth = FALSE;
 
   if(gdata_authorizer_refresh_authorization_finish(GDATA_AUTHORIZER(auth), res, &error) == FALSE)
   {
@@ -508,10 +509,25 @@ static void cm_gdata_refresh_ready(GDataOAuth2Authorizer *auth, GAsyncResult *re
     if(!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
     {
       log_error(LOG_PROTOCOL, _("GData plugin: Authorization refresh error: %s\n"), error->message);
+
+      if(mainwindow_get_mainwindow())
+      {
+        mainwindow_show_error();
+      }
     }
+
+    /* Only start an interactive auth session in case of authorization issues, but not
+     * for e.g. sporadic network issues or other non-authorization-related problems. */
+    start_interactive_auth =
+        g_error_matches(error, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_AUTHENTICATION_REQUIRED) ||
+        g_error_matches(error, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_FORBIDDEN);
+
     g_error_free(error);
 
-    cm_gdata_interactive_auth();
+    if(start_interactive_auth)
+    {
+      cm_gdata_interactive_auth();
+    }
 
     return;
   }