[evolution-ews] Bug #667849 - Unable to open Contacts address book



commit 857ba243b3295baeb110ca629561b25f0f428fdd
Author: Milan Crha <mcrha redhat com>
Date:   Wed Mar 7 08:45:06 2012 +0100

    Bug #667849 - Unable to open Contacts address book

 .../exchange-ews-account-listener.c                |   16 ++--
 src/camel/camel-ews-utils.c                        |    9 +-
 src/utils/ews-esource-utils.c                      |   96 +++++++++++++-------
 src/utils/ews-esource-utils.h                      |    9 +-
 4 files changed, 78 insertions(+), 52 deletions(-)
---
diff --git a/src/account-setup-eplugin/exchange-ews-account-listener.c b/src/account-setup-eplugin/exchange-ews-account-listener.c
index 2b5db6b..4bece1e 100644
--- a/src/account-setup-eplugin/exchange-ews-account-listener.c
+++ b/src/account-setup-eplugin/exchange-ews-account-listener.c
@@ -129,13 +129,14 @@ ews_account_removed (EAccountList *account_listener,
 	if (!info)
 		return;
 
-	ews_esource_utils_remove_groups (account->id->address);
+	url = camel_url_new (account->source->url, NULL);
+
+	ews_esource_utils_remove_groups (url);
 	ews_accounts = g_list_remove (ews_accounts, info);
 
 	shell = e_shell_get_default ();
 	shell_backend = e_shell_get_backend_by_name (shell, "mail");
 	session = (CamelSession *) e_mail_backend_get_session (E_MAIL_BACKEND (shell_backend));
-	url = camel_url_new (account->source->url, NULL);
 	service = camel_session_get_service_by_url (session, url, CAMEL_PROVIDER_STORE);
 	camel_url_free (url);
 
@@ -168,7 +169,7 @@ ews_is_str_equal (const gchar *str1,
 }
 
 static gboolean
-remove_gal_esource (const gchar *account_name)
+remove_gal_esource (CamelURL *account_url)
 {
 	ESourceList *source_list;
 	ESourceGroup *group;
@@ -183,7 +184,7 @@ remove_gal_esource (const gchar *account_name)
 	conf_key = CONTACT_SOURCES;
 	client = gconf_client_get_default ();
 	source_list = e_source_list_new_for_gconf (client, conf_key);
-	group = ews_esource_utils_ensure_group (source_list, account_name);
+	group = ews_esource_utils_ensure_group (source_list, account_url);
 
 	sources = e_source_group_peek_sources (group);
 	if (!(source = ews_find_source_by_matched_prop (sources, "gal", "1"))) {
@@ -251,7 +252,6 @@ add_gal_esource (CamelURL *url)
 	e_source_set_property (source, "gal", "1");
 	e_source_set_property (source, "hosturl", camel_url_get_param (url, "hosturl"));
 	e_source_set_property (source, "delete", "no");
-	e_source_set_color_spec (source, "#EEBC60");
 
 	/* If oal_id is present it means the GAL is marked for offline usage, we do not check for offline_sync property */
 	if (oal_sel) {
@@ -263,7 +263,7 @@ add_gal_esource (CamelURL *url)
 	e_source_set_property (source, "completion", "true");
 
 	/* add the source to group and sync */
-	group = ews_esource_utils_ensure_group (source_list, email_id);
+	group = ews_esource_utils_ensure_group (source_list, url);
 	e_source_group_add_source (group, source, -1);
 	e_source_list_sync (source_list, NULL);
 
@@ -309,10 +309,8 @@ ews_account_changed (EAccountList *account_listener,
 			n_oal_sel = camel_url_get_param (new_url, "oal-selected");
 
 			if (!ews_is_str_equal (o_oal_sel, n_oal_sel)) {
-				const gchar *account_name = camel_url_get_param (new_url, "email");
-
 				/* remove gal esource and cache associated with it */
-				remove_gal_esource (account_name);
+				remove_gal_esource (new_url);
 
 				/* add gal esource */
 				add_gal_esource (new_url);
diff --git a/src/camel/camel-ews-utils.c b/src/camel/camel-ews-utils.c
index 41026c4..376a8ee 100644
--- a/src/camel/camel-ews-utils.c
+++ b/src/camel/camel-ews-utils.c
@@ -320,7 +320,7 @@ camel_ews_utils_build_folder_info (CamelEwsStore *store,
 
 struct remove_esrc_data {
 	gchar *fid;
-	gchar *account_name;
+	CamelURL *account_url;
 	EwsFolderType ftype;
 };
 
@@ -329,10 +329,11 @@ static gboolean ews_do_remove_esource (gpointer user_data)
 	struct remove_esrc_data *remove_data = user_data;
 
 	ews_esource_utils_remove_esource (remove_data->fid,
-					  remove_data->account_name,
+					  remove_data->account_url,
 					  remove_data->ftype);
+
+	camel_url_free (remove_data->account_url);
 	g_free (remove_data->fid);
-	g_free (remove_data->account_name);
 	g_free (remove_data);
 
 	return FALSE;
@@ -376,7 +377,7 @@ sync_deleted_folders (CamelEwsStore *store,
 			struct remove_esrc_data *remove_data = g_new0 (struct remove_esrc_data, 1);
 
 			remove_data->fid = g_strdup (fid);
-			remove_data->account_name = g_strdup (email);
+			remove_data->account_url = camel_service_new_camel_url (service);
 			remove_data->ftype = ftype;
 
 			/* This uses GConf so has to be done in the main thread */
diff --git a/src/utils/ews-esource-utils.c b/src/utils/ews-esource-utils.c
index 457c2f2..ce582f4 100644
--- a/src/utils/ews-esource-utils.c
+++ b/src/utils/ews-esource-utils.c
@@ -45,43 +45,53 @@ ews_find_source_by_matched_prop (GSList *sources,
 	return NULL;
 }
 
-static ESourceGroup *
-ews_find_group (GSList *groups,
-                const gchar *account_name)
+static gchar *
+ews_construct_base_uri (CamelURL *account_url)
 {
-	GSList *p;
-	gint len;
+	gchar *base_uri;
+	CamelURL *base_curi;
 
-	len = strlen (EWS_BASE_URI);
+	g_return_val_if_fail (account_url != NULL, NULL);
 
-	for (p = groups; p != NULL; p = g_slist_next (p)) {
-		ESourceGroup *group = E_SOURCE_GROUP (p->data);
-		const gchar *buri = e_source_group_peek_base_uri (group);
-		const gchar *name = e_source_group_peek_name (group);
+	base_curi = camel_url_new ("ews://", NULL);
+	g_return_val_if_fail (base_curi != NULL, NULL);
 
-		if (buri && !g_ascii_strncasecmp (buri, EWS_BASE_URI, len) &&
-		    !g_ascii_strcasecmp (name, account_name))
-			return group;
-	}
+	camel_url_set_user (base_curi, account_url->user);
+	camel_url_set_host (base_curi, account_url->host);
 
-	return NULL;
+	base_uri = camel_url_to_string (base_curi, 0);
+
+	camel_url_free (base_curi);
+
+	return base_uri;
 }
 
 ESourceGroup *
 ews_esource_utils_ensure_group (ESourceList *source_list,
-                                const gchar *account_name)
+                                CamelURL *account_url)
 {
 	ESourceGroup *group = NULL;
-	GSList *groups;
+	gchar *base_uri;
 
-	groups = e_source_list_peek_groups (source_list);
-	group = ews_find_group (groups, account_name);
-	if (group)
-		return g_object_ref (group);
+	base_uri = ews_construct_base_uri (account_url);
+	g_return_val_if_fail (base_uri != NULL, NULL);
+
+	group = e_source_list_peek_group_by_base_uri (source_list, base_uri);
+	if (group) {
+		/* update group description, if base uri is "too short" */
+		if (g_strcmp0 (e_source_group_peek_base_uri (group), EWS_BASE_URI) == 0) {
+			e_source_list_remove_group (source_list, group);
+		} else {
+			g_free (base_uri);
+			return g_object_ref (group);
+		}
+	}
 
-	group = e_source_group_new (account_name, EWS_BASE_URI);
+	group = e_source_group_new (camel_url_get_param (account_url, "email"), base_uri);
 	e_source_group_set_property (group, "create_source", "no");
 
+	g_free (base_uri);
+
 	if (!e_source_list_add_group (source_list, group, -1)) {
 		g_warning ("Unable to add the group to the source list \n");
 		g_object_unref (group);
@@ -111,6 +121,7 @@ ews_esource_utils_add_esource (EEwsFolder *folder,
 	const gchar *source_name;
 	gchar *source_uri;
 	GSList *sources;
+	CamelURL *account_url;
 	gboolean ret = TRUE;
 
 	ftype = e_ews_folder_get_folder_type (folder);
@@ -128,9 +139,16 @@ ews_esource_utils_add_esource (EEwsFolder *folder,
 	} else
 		return FALSE;
 
+	account_url = camel_url_new (account_uri, NULL);
+	g_return_val_if_fail (account_url != NULL, FALSE);
+
+	camel_url_set_param (account_url, "email", account_name);
+
 	client = gconf_client_get_default ();
 	source_list = e_source_list_new_for_gconf (client, conf_key);
-	group = ews_esource_utils_ensure_group (source_list, account_name);
+	group = ews_esource_utils_ensure_group (source_list, account_url);
+
+	camel_url_free (account_url);
 
 	sources = e_source_group_peek_sources (group);
 	if (ews_find_source_by_matched_prop (sources, "folder-id", fid->id)) {
@@ -144,7 +162,7 @@ ews_esource_utils_add_esource (EEwsFolder *folder,
 	 * play in the calendar back end to make the cache directory
 	 * unique again. */
 	if (ftype == EWS_FOLDER_TYPE_CONTACTS)
-		source_uri = g_strdup_printf ("%s;folderid=%s", account_uri + strlen (EWS_BASE_URI), fid->id);
+		source_uri = g_strdup_printf ("%s/;folderid=%s", account_uri + strlen (EWS_BASE_URI), fid->id);
 	else
 		source_uri = g_strdup (account_uri + strlen (EWS_BASE_URI));
 
@@ -157,7 +175,8 @@ ews_esource_utils_add_esource (EEwsFolder *folder,
 	e_source_set_property (source, "hosturl", hosturl);
 	e_source_set_property (source, "delete", "no");
 	e_source_set_property (source, "offline_sync", "1");
-	e_source_set_color_spec (source, "#EEBC60");
+	if (ftype != EWS_FOLDER_TYPE_CONTACTS)
+		e_source_set_color_spec (source, "#EEBC60");
 
 	g_free (source_uri);
 	/* set props required for contacts */
@@ -193,7 +212,7 @@ exit:
 /* FIXME remove cache */
 gboolean
 ews_esource_utils_remove_esource (const gchar *fid,
-                                  const gchar *account_name,
+                                  CamelURL *account_url,
                                   EwsFolderType ftype)
 {
 	ESourceList *source_list;
@@ -215,7 +234,7 @@ ews_esource_utils_remove_esource (const gchar *fid,
 
 	client = gconf_client_get_default ();
 	source_list = e_source_list_new_for_gconf (client, conf_key);
-	group = ews_esource_utils_ensure_group (source_list, account_name);
+	group = ews_esource_utils_ensure_group (source_list, account_url);
 
 	sources = e_source_group_peek_sources (group);
 	if (!(source = ews_find_source_by_matched_prop (sources, "folder-id", fid))) {
@@ -235,15 +254,15 @@ exit:
 }
 
 gboolean
-ews_source_utils_remove_group (const gchar *account_name,
+ews_source_utils_remove_group (CamelURL *account_url,
                                EwsFolderType ftype)
 {
 	ESourceList *source_list;
 	ESourceGroup *group;
-	GSList *groups;
 	GConfClient * client;
 	const gchar *conf_key;
 	gboolean ret = TRUE;
+	gchar *base_uri;
 
 	if (ftype == EWS_FOLDER_TYPE_CALENDAR) {
 		conf_key = CALENDAR_SOURCES;
@@ -254,10 +273,16 @@ ews_source_utils_remove_group (const gchar *account_name,
 	} else
 		return FALSE;
 
+	base_uri = ews_construct_base_uri (account_url);
+	g_return_val_if_fail (base_uri != NULL, FALSE);
+
 	client = gconf_client_get_default ();
 	source_list = e_source_list_new_for_gconf (client, conf_key);
-	groups = e_source_list_peek_groups (source_list);
-	group = ews_find_group (groups, account_name);
+	group = e_source_list_peek_group_by_base_uri (source_list, base_uri);
+
+	/* there were done a change in base_uri, thus remove the old group, if any */
+	if (!group)
+		group = e_source_list_peek_group_by_base_uri (source_list, EWS_BASE_URI);
 
 	if (group) {
 		e_source_list_remove_group (source_list, group);
@@ -267,15 +292,16 @@ ews_source_utils_remove_group (const gchar *account_name,
 
 	g_object_unref (source_list);
 	g_object_unref (client);
+	g_free (base_uri);
 
 	return ret;
 
 }
 
 void
-ews_esource_utils_remove_groups (const gchar *account_name)
+ews_esource_utils_remove_groups (CamelURL *account_url)
 {
-	ews_source_utils_remove_group (account_name, EWS_FOLDER_TYPE_CALENDAR);
-	ews_source_utils_remove_group (account_name, EWS_FOLDER_TYPE_CONTACTS);
-	ews_source_utils_remove_group (account_name, EWS_FOLDER_TYPE_TASKS);
+	ews_source_utils_remove_group (account_url, EWS_FOLDER_TYPE_CALENDAR);
+	ews_source_utils_remove_group (account_url, EWS_FOLDER_TYPE_CONTACTS);
+	ews_source_utils_remove_group (account_url, EWS_FOLDER_TYPE_TASKS);
 }
diff --git a/src/utils/ews-esource-utils.h b/src/utils/ews-esource-utils.h
index 37e1e90..9ebf5d5 100644
--- a/src/utils/ews-esource-utils.h
+++ b/src/utils/ews-esource-utils.h
@@ -21,6 +21,7 @@
 #define EWS_ESOURCE_UTILS_H
 
 #include <libedataserver/e-source-list.h>
+#include <camel/camel.h>
 #include <e-ews-folder.h>
 
 G_BEGIN_DECLS
@@ -43,20 +44,20 @@ ews_esource_utils_add_esource	(EEwsFolder *folder,
 gboolean
 ews_esource_utils_remove_esource
 				(const gchar *fid,
-				 const gchar *account_name,
+				 CamelURL *account_url,
 				 EwsFolderType ftype);
 
 void
-ews_esource_utils_remove_groups	(const gchar *account_name);
+ews_esource_utils_remove_groups	(CamelURL *account_url);
 
 gboolean
-ews_source_utils_remove_group (const gchar *account_name, EwsFolderType ftype);
+ews_source_utils_remove_group (CamelURL *account_url, EwsFolderType ftype);
 
 ESource *
 ews_find_source_by_matched_prop (GSList *sources, const gchar *prop, const gchar *val);
 
 ESourceGroup *
-ews_esource_utils_ensure_group (ESourceList *source_list, const gchar *account_name);
+ews_esource_utils_ensure_group (ESourceList *source_list, CamelURL *account_url);
 
 G_END_DECLS
 



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