[evolution-ews/gnome-3-6] Bug #693306 - Folder types not set when any standard folder is missing



commit 60dcfcf97d782c7c828dafe24129176c97a9a2e3
Author: Milan Crha <mcrha redhat com>
Date:   Thu Feb 7 18:32:18 2013 +0100

    Bug #693306 - Folder types not set when any standard folder is missing

 src/camel/camel-ews-store.c   |   46 +++++++++++++++++++++++++++++-----------
 src/camel/camel-ews-utils.c   |   15 +++++++++---
 src/camel/camel-ews-utils.h   |    3 +-
 src/server/e-ews-connection.c |   13 +++++++----
 src/server/e-ews-folder.c     |   33 +++++++++++++++++++++++++++++
 src/server/e-ews-folder.h     |    3 ++
 6 files changed, 90 insertions(+), 23 deletions(-)
---
diff --git a/src/camel/camel-ews-store.c b/src/camel/camel-ews-store.c
index 655b100..fce99a4 100644
--- a/src/camel/camel-ews-store.c
+++ b/src/camel/camel-ews-store.c
@@ -360,9 +360,10 @@ ews_update_folder_hierarchy (CamelEwsStore *ews_store,
                              gboolean includes_last_folder,
                              GSList *folders_created,
                              GSList *folders_deleted,
-                             GSList *folders_updated)
+                             GSList *folders_updated,
+			     GSList **created_folder_ids)
 {
-	ews_utils_sync_folders (ews_store, folders_created, folders_deleted, folders_updated);
+	ews_utils_sync_folders (ews_store, folders_created, folders_deleted, folders_updated, created_folder_ids);
 	camel_ews_store_ensure_virtual_folders (ews_store);
 
 	camel_ews_store_summary_store_string_val (ews_store->summary, "sync_state", sync_state);
@@ -483,10 +484,13 @@ ews_store_set_flags (CamelEwsStore *ews_store,
 	temp = folders;
 	while (temp != NULL) {
 		folder = (EEwsFolder *) temp->data;
-		fid = e_ews_folder_get_id (folder);
 
-		if (camel_ews_store_summary_has_folder (ews_store->summary, fid->id))
-			camel_ews_store_summary_set_folder_flags (ews_store->summary, fid->id, system_folder[n].info_flags);
+		if (folder && !e_ews_folder_is_error (folder)) {
+			fid = e_ews_folder_get_id (folder);
+
+			if (camel_ews_store_summary_has_folder (ews_store->summary, fid->id))
+				camel_ews_store_summary_set_folder_flags (ews_store->summary, fid->id, system_folder[n].info_flags);
+		}
 
 		temp = temp->next;
 		n++;
@@ -581,11 +585,13 @@ ews_store_maybe_update_sent_and_drafts (CamelEwsStore *ews_store,
 
 					if (ii < G_N_ELEMENTS (system_folder)) {
 						EEwsFolder *drafts = g_slist_nth (ews_folders, ii)->data;
-						const EwsFolderId *fid = drafts ? e_ews_folder_get_id (drafts) : NULL;
+						if (drafts && !e_ews_folder_is_error (drafts)) {
+							const EwsFolderId *fid = e_ews_folder_get_id (drafts);
 
-						if (fid && fid->id) {
-							changed = TRUE;
-							ews_store_update_source_extension_folder (ews_store, fid->id, coms_extension, "drafts-folder");
+							if (fid && fid->id) {
+								changed = TRUE;
+								ews_store_update_source_extension_folder (ews_store, fid->id, coms_extension, "drafts-folder");
+							}
 						}
 					}
 				}
@@ -618,6 +624,7 @@ ews_authenticate_sync (CamelService *service,
 	GSList *folders_updated = NULL;
 	GSList *folders_deleted = NULL;
 	GSList *folder_ids = NULL, *folders = NULL;
+	GSList *created_folder_ids = NULL;
 	gboolean includes_last_folder = FALSE;
 	gboolean initial_setup = FALSE;
 	const gchar *password;
@@ -676,7 +683,7 @@ ews_authenticate_sync (CamelService *service,
 		/* This consumes all allocated result data. */
 		ews_update_folder_hierarchy (
 			ews_store, sync_state, includes_last_folder,
-			folders_created, folders_deleted, folders_updated);
+			folders_created, folders_deleted, folders_updated, &created_folder_ids);
 	} else {
 		g_mutex_lock (ews_store->priv->connection_lock);
 		if (ews_store->priv->connection != NULL) {
@@ -713,7 +720,7 @@ ews_authenticate_sync (CamelService *service,
 			NULL, folder_ids, &folders,
 			cancellable, &folder_err);
 
-		if (g_slist_length (folders) && (g_slist_length (folders) != G_N_ELEMENTS (system_folder)))
+		if (folders && (g_slist_length (folders) != G_N_ELEMENTS (system_folder)))
 			d (printf ("Error : not all folders are returned by getfolder operation"));
 		else if (folder_err == NULL && folders != NULL)
 			ews_store_set_flags (ews_store, folders);
@@ -736,6 +743,19 @@ ews_authenticate_sync (CamelService *service,
 		g_clear_error (&folder_err);
 	}
 
+	/* postpone notification of new folders to time when also folder flags are known,
+	   thus the view in evolution sows Inbox with an Inbox icon. */
+	for (folder_ids = created_folder_ids; folder_ids; folder_ids = folder_ids->next) {
+		CamelFolderInfo *fi;
+
+		fi = camel_ews_utils_build_folder_info (ews_store, folder_ids->data);
+		camel_store_folder_created (CAMEL_STORE (ews_store), fi);
+		camel_subscribable_folder_subscribed (CAMEL_SUBSCRIBABLE (ews_store), fi);
+		camel_folder_info_free (fi);
+	}
+
+	g_slist_free_full (created_folder_ids, g_free);
+
 	if (local_error == NULL) {
 		result = CAMEL_AUTHENTICATION_ACCEPTED;
 	} else if (g_error_matches (local_error, EWS_CONNECTION_ERROR, EWS_CONNECTION_ERROR_AUTHENTICATION_FAILED)) {
@@ -895,7 +915,7 @@ ews_folder_hierarchy_ready_cb (GObject *obj,
 	g_mutex_lock (priv->get_finfo_lock);
 	ews_update_folder_hierarchy (
 		ews_store, sync_state, includes_last_folder,
-		folders_created, folders_deleted, folders_updated);
+		folders_created, folders_deleted, folders_updated, NULL);
 
 	ews_store->priv->last_refresh_time = time (NULL);
 	g_mutex_unlock (priv->get_finfo_lock);
@@ -1013,7 +1033,7 @@ ews_get_folder_info_sync (CamelStore *store,
 	}
 	ews_update_folder_hierarchy (
 		ews_store, sync_state, includes_last_folder,
-		folders_created, folders_deleted, folders_updated);
+		folders_created, folders_deleted, folders_updated, NULL);
 	g_mutex_unlock (priv->get_finfo_lock);
 
 offline:
diff --git a/src/camel/camel-ews-utils.c b/src/camel/camel-ews-utils.c
index 89c9664..3016665 100644
--- a/src/camel/camel-ews-utils.c
+++ b/src/camel/camel-ews-utils.c
@@ -236,7 +236,8 @@ add_folder_to_summary (CamelEwsStore *store,
 
 static void
 sync_created_folders (CamelEwsStore *ews_store,
-                      GSList *created_folders)
+                      GSList *created_folders,
+		      GSList **created_folder_ids)
 {
 	GSList *l;
 
@@ -259,7 +260,12 @@ sync_created_folders (CamelEwsStore *ews_store,
 		 * let's worry about that in a later commit. */
 		add_folder_to_summary (ews_store, folder);
 
-		if (ftype == E_EWS_FOLDER_TYPE_MAILBOX) {
+		if (ftype != E_EWS_FOLDER_TYPE_MAILBOX)
+			continue;
+
+		if (created_folder_ids) {
+			*created_folder_ids = g_slist_append (*created_folder_ids, g_strdup (fid->id));
+		} else {
 			fi = camel_ews_utils_build_folder_info (
 				ews_store, fid->id);
 			camel_store_folder_created (
@@ -275,13 +281,14 @@ void
 ews_utils_sync_folders (CamelEwsStore *ews_store,
                         GSList *created_folders,
                         GSList *deleted_folders,
-                        GSList *updated_folders)
+                        GSList *updated_folders,
+			GSList **created_folder_ids)
 {
 	GError *error = NULL;
 
 	sync_deleted_folders (ews_store, deleted_folders);
 	sync_updated_folders (ews_store, updated_folders);
-	sync_created_folders (ews_store, created_folders);
+	sync_created_folders (ews_store, created_folders, created_folder_ids);
 
 	camel_ews_store_summary_save (ews_store->summary, &error);
 	if (error != NULL) {
diff --git a/src/camel/camel-ews-utils.h b/src/camel/camel-ews-utils.h
index 09689e2..80d9977 100644
--- a/src/camel/camel-ews-utils.h
+++ b/src/camel/camel-ews-utils.h
@@ -54,7 +54,8 @@ G_BEGIN_DECLS
 void		ews_utils_sync_folders		(CamelEwsStore *ews_store,
 						 GSList *created_folders,
 						 GSList *deleted_folders,
-						 GSList *updated_folders);
+						 GSList *updated_folders,
+						 GSList **created_folder_ids);
 CamelFolderInfo *
 		camel_ews_utils_build_folder_info
 						(CamelEwsStore *store,
diff --git a/src/server/e-ews-connection.c b/src/server/e-ews-connection.c
index 28df5f7..22bcff1 100644
--- a/src/server/e-ews-connection.c
+++ b/src/server/e-ews-connection.c
@@ -791,11 +791,14 @@ get_folder_response_cb (ESoapResponse *response,
 		const gchar *name = (const gchar *) subparam->name;
 
 		if (!ews_get_response_status (subparam, &error)) {
-			g_simple_async_result_take_error (simple, error);
-			return;
-		}
-
-		if (CHECK_ELEMENT (name, "GetFolderResponseMessage"))
+			if (g_strcmp0 (name, "GetFolderResponseMessage") == 0) {
+				async_data->items = g_slist_append (async_data->items, e_ews_folder_new_from_error (error));
+				g_clear_error (&error);
+			} else {
+				g_simple_async_result_take_error (simple, error);
+				return;
+			}
+		} else if (CHECK_ELEMENT (name, "GetFolderResponseMessage"))
 			ews_handle_folders_param (subparam, async_data);
 
 		subparam = e_soap_parameter_get_next_child (subparam);
diff --git a/src/server/e-ews-folder.c b/src/server/e-ews-folder.c
index e5cfcba..ade9f2a 100644
--- a/src/server/e-ews-folder.c
+++ b/src/server/e-ews-folder.c
@@ -35,6 +35,7 @@
 G_DEFINE_TYPE (EEwsFolder, e_ews_folder, G_TYPE_OBJECT)
 
 struct _EEwsFolderPrivate {
+	GError *error;
 	gchar *name;
 	EwsFolderId *fid;
 	EwsFolderId *parent_fid;
@@ -69,6 +70,8 @@ e_ews_folder_finalize (GObject *object)
 
 	priv = folder->priv;
 
+	g_clear_error (&priv->error);
+
 	if (priv->name) {
 		g_free (priv->name);
 		priv->name = NULL;
@@ -115,6 +118,7 @@ e_ews_folder_init (EEwsFolder *folder)
 	priv = g_new0 (EEwsFolderPrivate, 1);
 	folder->priv = priv;
 
+	priv->error = NULL;
 	priv->folder_type = E_EWS_FOLDER_TYPE_MAILBOX;
 	priv->foreign = FALSE;
 }
@@ -263,6 +267,35 @@ e_ews_folder_new_from_soap_parameter (ESoapParameter *param)
 	return folder;
 }
 
+EEwsFolder *
+e_ews_folder_new_from_error (const GError *error)
+{
+	EEwsFolder *folder;
+
+	g_return_val_if_fail (error != NULL, NULL);
+
+	folder = g_object_new (E_TYPE_EWS_FOLDER, NULL);
+	folder->priv->error = g_error_copy (error);
+
+	return folder;
+}
+
+gboolean
+e_ews_folder_is_error (EEwsFolder *folder)
+{
+	g_return_val_if_fail (E_IS_EWS_FOLDER (folder), TRUE);
+
+	return folder->priv->error != NULL;
+}
+
+const GError *
+e_ews_folder_get_error (EEwsFolder *folder)
+{
+	g_return_val_if_fail (E_IS_EWS_FOLDER (folder), NULL);
+
+	return folder->priv->error;
+}
+
 EwsFolderId *
 e_ews_folder_id_new (const gchar *id,
                      const gchar *change_key,
diff --git a/src/server/e-ews-folder.h b/src/server/e-ews-folder.h
index 2cec0c4..81f689f 100644
--- a/src/server/e-ews-folder.h
+++ b/src/server/e-ews-folder.h
@@ -58,6 +58,9 @@ GType		e_ews_folder_get_type (void);
 const gchar *	e_ews_folder_type_to_nick (EEwsFolderType folder_type);
 EEwsFolderType	e_ews_folder_type_from_nick (const gchar *folder_type_nick);
 EEwsFolder *	e_ews_folder_new_from_soap_parameter (ESoapParameter *param);
+EEwsFolder *	e_ews_folder_new_from_error (const GError *error);
+gboolean	e_ews_folder_is_error (EEwsFolder *folder);
+const GError *	e_ews_folder_get_error (EEwsFolder *folder);
 const gchar *	e_ews_folder_get_name (EEwsFolder *folder);
 void		e_ews_folder_set_name (EEwsFolder *folder, const gchar *new_name);
 void		e_ews_folder_set_parent_id (EEwsFolder *folder, EwsFolderId *fid);


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