[evolution-data-server] online-accounts: Refresh mail account settings on startup.



commit 8099d1e3002a83298651a326ee6cd8dc63c4c6d3
Author: Matthew Barnes <mbarnes redhat com>
Date:   Thu Oct 11 19:41:14 2012 -0400

    online-accounts: Refresh mail account settings on startup.
    
    When matching GOA accounts to existing EDS accounts on startup, refresh
    both the collection and mail account settings.  This is primarily to aid
    the transition from XOAUTH to XOAUTH2, but can serve as a means of other
    types of migration in the future.

 modules/online-accounts/module-online-accounts.c |   73 +++++++++++++++++++++-
 1 files changed, 72 insertions(+), 1 deletions(-)
---
diff --git a/modules/online-accounts/module-online-accounts.c b/modules/online-accounts/module-online-accounts.c
index b150c5b..4b1497a 100644
--- a/modules/online-accounts/module-online-accounts.c
+++ b/modules/online-accounts/module-online-accounts.c
@@ -35,6 +35,7 @@
 	((obj), E_TYPE_ONLINE_ACCOUNTS, EOnlineAccounts))
 
 #define CAMEL_OAUTH_MECHANISM_NAME  "XOAUTH"
+#define CAMEL_OAUTH2_MECHANISM_NAME "XOAUTH2"
 
 typedef struct _EOnlineAccounts EOnlineAccounts;
 typedef struct _EOnlineAccountsClass EOnlineAccountsClass;
@@ -269,6 +270,25 @@ online_accounts_config_oauth (EOnlineAccounts *extension,
 }
 
 static void
+online_accounts_config_oauth2 (EOnlineAccounts *extension,
+                               ESource *source,
+                               GoaObject *goa_object)
+{
+	ESourceExtension *source_extension;
+	const gchar *extension_name;
+
+	if (goa_object_peek_oauth2_based (goa_object) == NULL)
+		return;
+
+	extension_name = E_SOURCE_EXTENSION_AUTHENTICATION;
+	source_extension = e_source_get_extension (source, extension_name);
+
+	e_source_authentication_set_method (
+		E_SOURCE_AUTHENTICATION (source_extension),
+		CAMEL_OAUTH2_MECHANISM_NAME);
+}
+
+static void
 online_accounts_config_password (EOnlineAccounts *extension,
                                  ESource *source,
                                  GoaObject *goa_object)
@@ -433,7 +453,9 @@ online_accounts_config_mail_account (EOnlineAccounts *extension,
 {
 	EServerSideSource *server_side_source;
 
+	/* Only one or the other should be present, not both. */
 	online_accounts_config_oauth (extension, source, goa_object);
+	online_accounts_config_oauth2 (extension, source, goa_object);
 
 	/* XXX Need to defer the network security settings to the
 	 *     provider-specific module since "imap-use-tls" tells
@@ -482,7 +504,9 @@ online_accounts_config_mail_transport (EOnlineAccounts *extension,
 {
 	EServerSideSource *server_side_source;
 
+	/* Only one or the other should be present, not both. */
 	online_accounts_config_oauth (extension, source, goa_object);
+	online_accounts_config_oauth2 (extension, source, goa_object);
 
 	/* XXX Need to defer the network security settings to the
 	 *     provider-specific module since "smtp-use-tls" tells
@@ -496,6 +520,53 @@ online_accounts_config_mail_transport (EOnlineAccounts *extension,
 }
 
 static void
+online_accounts_config_sources (EOnlineAccounts *extension,
+                                ESource *source,
+                                GoaObject *goa_object)
+{
+	ESourceRegistryServer *server;
+	ECollectionBackend *backend;
+	GList *list, *link;
+
+	/* XXX This function was primarily intended to smooth the
+	 *     transition of mail accounts from XOAUTH to XOAUTH2,
+	 *     but it may be useful for other types of migration. */
+
+	online_accounts_config_collection (extension, source, goa_object);
+
+	server = online_accounts_get_server (extension);
+	backend = e_source_registry_server_ref_backend (server, source);
+	g_return_if_fail (backend != NULL);
+
+	list = e_collection_backend_list_mail_sources (backend);
+
+	for (link = list; link != NULL; link = g_list_next (link)) {
+		const gchar *extension_name;
+
+		source = E_SOURCE (link->data);
+
+		extension_name = E_SOURCE_EXTENSION_MAIL_ACCOUNT;
+		if (e_source_has_extension (source, extension_name))
+			online_accounts_config_mail_account (
+				extension, source, goa_object);
+
+		extension_name = E_SOURCE_EXTENSION_MAIL_IDENTITY;
+		if (e_source_has_extension (source, extension_name))
+			online_accounts_config_mail_identity (
+				extension, source, goa_object);
+
+		extension_name = E_SOURCE_EXTENSION_MAIL_TRANSPORT;
+		if (e_source_has_extension (source, extension_name))
+			online_accounts_config_mail_transport (
+				extension, source, goa_object);
+	}
+
+	g_list_free_full (list, (GDestroyNotify) g_object_unref);
+
+	g_object_unref (backend);
+}
+
+static void
 online_accounts_create_collection (EOnlineAccounts *extension,
                                    EBackendFactory *backend_factory,
                                    GoaObject *goa_object)
@@ -713,7 +784,7 @@ online_accounts_populate_accounts_table (EOnlineAccounts *extension,
 				g_strdup (source_uid));
 
 			goa_object = GOA_OBJECT (match->data);
-			online_accounts_config_collection (
+			online_accounts_config_sources (
 				extension, source, goa_object);
 		} else {
 			g_queue_push_tail (&trash, source);



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