[evolution-ews] I#118 - Camel: Claim required credentials when authentication fails
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-ews] I#118 - Camel: Claim required credentials when authentication fails
- Date: Thu, 3 Sep 2020 07:45:46 +0000 (UTC)
commit 0c1ca58516d7173a8d51755b3ed98d729d0c4878
Author: Milan Crha <mcrha redhat com>
Date: Thu Sep 3 09:45:04 2020 +0200
I#118 - Camel: Claim required credentials when authentication fails
Closes https://gitlab.gnome.org/GNOME/evolution-ews/-/issues/118
src/EWS/camel/camel-ews-store.c | 39 ++++++++++++++++++++++++++++---
src/EWS/camel/camel-ews-store.h | 2 +-
src/Microsoft365/camel/camel-m365-store.c | 38 ++++++++++++++++++++++++++----
src/Microsoft365/camel/camel-m365-store.h | 2 +-
4 files changed, 71 insertions(+), 10 deletions(-)
---
diff --git a/src/EWS/camel/camel-ews-store.c b/src/EWS/camel/camel-ews-store.c
index b46e8b99..f97eedd2 100644
--- a/src/EWS/camel/camel-ews-store.c
+++ b/src/EWS/camel/camel-ews-store.c
@@ -3895,9 +3895,10 @@ camel_ews_store_connected (CamelEwsStore *ews_store,
void
camel_ews_store_maybe_disconnect (CamelEwsStore *store,
- const GError *error)
+ GError *error)
{
CamelService *service;
+ gboolean is_auth_failed;
g_return_if_fail (store != NULL);
@@ -3909,9 +3910,41 @@ camel_ews_store_maybe_disconnect (CamelEwsStore *store,
if (camel_service_get_connection_status (service) != CAMEL_SERVICE_CONNECTED)
return;
- if (g_error_matches (error, EWS_CONNECTION_ERROR, EWS_CONNECTION_ERROR_NORESPONSE) ||
- g_error_matches (error, EWS_CONNECTION_ERROR, EWS_CONNECTION_ERROR_AUTHENTICATION_FAILED))
+ is_auth_failed = g_error_matches (error, EWS_CONNECTION_ERROR,
EWS_CONNECTION_ERROR_AUTHENTICATION_FAILED);
+
+ if (is_auth_failed || g_error_matches (error, EWS_CONNECTION_ERROR, EWS_CONNECTION_ERROR_NORESPONSE))
camel_service_disconnect_sync (service, FALSE, NULL, NULL);
+
+ if (is_auth_failed) {
+ CamelSession *session;
+ ESourceRegistry *registry = NULL;
+
+ error->domain = CAMEL_SERVICE_ERROR;
+ error->code = CAMEL_SERVICE_ERROR_CANT_AUTHENTICATE;
+
+ session = camel_service_ref_session (service);
+
+ if (E_IS_MAIL_SESSION (session))
+ registry = e_mail_session_get_registry (E_MAIL_SESSION (session));
+
+ if (registry) {
+ ESource *source, *collection = NULL;
+
+ source = e_source_registry_ref_source (registry, camel_service_get_uid (service));
+
+ if (source) {
+ collection = e_source_registry_find_extension (registry, source,
E_SOURCE_EXTENSION_COLLECTION);
+
+ if (collection)
+ e_source_emit_credentials_required (collection,
E_SOURCE_CREDENTIALS_REASON_REJECTED, NULL, 0, error);
+ }
+
+ g_clear_object (&collection);
+ g_clear_object (&source);
+ }
+
+ g_clear_object (&session);
+ }
}
static void
diff --git a/src/EWS/camel/camel-ews-store.h b/src/EWS/camel/camel-ews-store.h
index 614c8ac2..80584cfa 100644
--- a/src/EWS/camel/camel-ews-store.h
+++ b/src/EWS/camel/camel-ews-store.h
@@ -69,7 +69,7 @@ gboolean camel_ews_store_connected (CamelEwsStore *store,
GError **error);
void camel_ews_store_maybe_disconnect
(CamelEwsStore *store,
- const GError *error);
+ GError *error);
void camel_ews_store_ensure_virtual_folders
(CamelEwsStore *ews_store);
void camel_ews_store_ensure_unique_path
diff --git a/src/Microsoft365/camel/camel-m365-store.c b/src/Microsoft365/camel/camel-m365-store.c
index 4bb2e1ec..a0f3f264 100644
--- a/src/Microsoft365/camel/camel-m365-store.c
+++ b/src/Microsoft365/camel/camel-m365-store.c
@@ -9,6 +9,7 @@
#include <glib/gi18n-lib.h>
#include <glib/gstdio.h>
+#include <libemail-engine/libemail-engine.h>
#include <e-util/e-util.h>
#include "common/camel-m365-settings.h"
@@ -1794,7 +1795,7 @@ camel_m365_store_ensure_connected (CamelM365Store *m365_store,
void
camel_m365_store_maybe_disconnect (CamelM365Store *m365_store,
- const GError *error)
+ GError *error)
{
CamelService *service;
@@ -1808,11 +1809,38 @@ camel_m365_store_maybe_disconnect (CamelM365Store *m365_store,
if (camel_service_get_connection_status (service) != CAMEL_SERVICE_CONNECTED)
return;
-#if 0
- if (g_error_matches (error, M365_CONNECTION_ERROR, M365_CONNECTION_ERROR_NORESPONSE) ||
- g_error_matches (error, M365_CONNECTION_ERROR, M365_CONNECTION_ERROR_AUTHENTICATION_FAILED))
+ if (g_error_matches (error, SOUP_HTTP_ERROR, SOUP_STATUS_UNAUTHORIZED)) {
+ CamelSession *session;
+ ESourceRegistry *registry = NULL;
+
camel_service_disconnect_sync (service, FALSE, NULL, NULL);
-#endif
+
+ error->domain = CAMEL_SERVICE_ERROR;
+ error->code = CAMEL_SERVICE_ERROR_CANT_AUTHENTICATE;
+
+ session = camel_service_ref_session (service);
+
+ if (E_IS_MAIL_SESSION (session))
+ registry = e_mail_session_get_registry (E_MAIL_SESSION (session));
+
+ if (registry) {
+ ESource *source, *collection = NULL;
+
+ source = e_source_registry_ref_source (registry, camel_service_get_uid (service));
+
+ if (source) {
+ collection = e_source_registry_find_extension (registry, source,
E_SOURCE_EXTENSION_COLLECTION);
+
+ if (collection)
+ e_source_emit_credentials_required (collection,
E_SOURCE_CREDENTIALS_REASON_REJECTED, NULL, 0, error);
+ }
+
+ g_clear_object (&collection);
+ g_clear_object (&source);
+ }
+
+ g_clear_object (&session);
+ }
}
void
diff --git a/src/Microsoft365/camel/camel-m365-store.h b/src/Microsoft365/camel/camel-m365-store.h
index c20d207c..761c9197 100644
--- a/src/Microsoft365/camel/camel-m365-store.h
+++ b/src/Microsoft365/camel/camel-m365-store.h
@@ -60,7 +60,7 @@ gboolean camel_m365_store_ensure_connected
GError **error);
void camel_m365_store_maybe_disconnect
(CamelM365Store *m365_store,
- const GError *error);
+ GError *error);
void camel_m365_store_connect_folder_summary
(CamelM365Store *m365_store,
CamelFolderSummary *folder_summary);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]