[evolution-ews/gnome-2-28] Bug #654822 set system folder flags using getfolder operation



commit eb520d96ab28f5f45867daf6de9c037b473c781f
Author: Punit Jain <jpunit novell com>
Date:   Mon Apr 2 17:23:16 2012 +0530

    Bug #654822 set system folder flags using getfolder operation

 src/camel/camel-ews-store.c |   80 +++++++++++++++++++++++++++++++++++++++++++
 src/camel/camel-ews-utils.c |   17 +--------
 2 files changed, 81 insertions(+), 16 deletions(-)
---
diff --git a/src/camel/camel-ews-store.c b/src/camel/camel-ews-store.c
index 203d587..0e82e0f 100644
--- a/src/camel/camel-ews-store.c
+++ b/src/camel/camel-ews-store.c
@@ -500,6 +500,49 @@ ews_refresh_finfo (CamelEwsStore *ews_store)
 	return TRUE;
 }
 
+typedef struct {
+	const gchar *dist_folder_id;
+	gint info_flags;
+} SystemFolder;
+
+static SystemFolder system_folder [] = {
+	{"calendar", CAMEL_FOLDER_SYSTEM},
+	{"contacts", CAMEL_FOLDER_SYSTEM},
+	{"deleteditems", CAMEL_FOLDER_SYSTEM | CAMEL_FOLDER_TYPE_TRASH},
+	{"drafts", CAMEL_FOLDER_SYSTEM},
+	{"inbox", CAMEL_FOLDER_SYSTEM | CAMEL_FOLDER_TYPE_INBOX},
+	{"journal", CAMEL_FOLDER_SYSTEM},
+	{"notes", CAMEL_FOLDER_SYSTEM},
+	{"outbox", CAMEL_FOLDER_SYSTEM | CAMEL_FOLDER_TYPE_OUTBOX},
+	{"sentitems", CAMEL_FOLDER_SYSTEM | CAMEL_FOLDER_TYPE_SENT},
+	{"tasks", CAMEL_FOLDER_SYSTEM},
+	{"msgfolderroot", CAMEL_FOLDER_SYSTEM},
+	{"root", CAMEL_FOLDER_SYSTEM},
+	{"junkemail", CAMEL_FOLDER_SYSTEM | CAMEL_FOLDER_TYPE_JUNK},
+	{"searchfolders", CAMEL_FOLDER_SYSTEM},
+};
+
+static void
+ews_store_set_flags (CamelEwsStore *ews_store, GSList *folders)
+{
+	GSList *temp=NULL;
+	EEwsFolder *folder = NULL;
+	const EwsFolderId *fid = NULL;
+	gint n = 0;
+
+	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);
+		
+		temp = temp->next;
+		n++;
+	}
+}
+
 static CamelFolderInfo *
 ews_get_folder_info_sync (CamelStore *store, const gchar *top, guint32 flags, EVO3(GCancellable *cancellable,) GError **error)
 {
@@ -511,7 +554,10 @@ ews_get_folder_info_sync (CamelStore *store, const gchar *top, guint32 flags, EV
 	gboolean initial_setup = FALSE;
 	GSList *folders_created = NULL, *folders_updated = NULL;
 	GSList *folders_deleted = NULL;
+	GSList *folder_ids = NULL, *folders = NULL;
 	gboolean includes_last_folder;
+	GError *folder_err = NULL;
+	gint n = 0;
 
 	ews_store = (CamelEwsStore *) store;
 	priv = ews_store->priv;
@@ -553,6 +599,40 @@ ews_get_folder_info_sync (CamelStore *store, const gchar *top, guint32 flags, EV
 	}
 	ews_update_folder_hierarchy (ews_store, sync_state, includes_last_folder,
 				     folders_created, folders_deleted, folders_updated);
+
+	/*get folders using distinguished id by GetFolder operation and set system flags to folders, only for first time*/
+	if (initial_setup) {
+		while (n < G_N_ELEMENTS (system_folder)) {
+			EwsFolderId *fid = NULL;
+
+			fid = g_new0 (EwsFolderId, 1);
+			fid->id = g_strdup (system_folder[n].dist_folder_id);
+			fid->is_distinguished_id = TRUE;
+			folder_ids = g_slist_append (folder_ids, fid);
+			n++;
+		}
+
+		/* fetch system folders first using getfolder operation*/
+		e_ews_connection_get_folder (ews_store->priv->cnc, EWS_PRIORITY_MEDIUM, "IdOnly",
+						     NULL, folder_ids, &folders,
+						     cancellable, &folder_err);
+
+		if (g_slist_length (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);
+		else if (folder_err) {
+			/*report error and make sure we are not leaking anything*/
+			g_warn_if_fail (folders == NULL);
+		} else
+			d(printf ("folders for respective distinguished ids don't exist"));
+
+		g_slist_foreach (folders, (GFunc) g_object_unref, NULL);
+		g_slist_foreach (folder_ids, (GFunc) e_ews_folder_free_fid, NULL);
+		g_slist_free (folders);
+		g_slist_free (folder_ids);
+		g_clear_error (&folder_err);
+	}
 	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 87d0d08..c382de1 100644
--- a/src/camel/camel-ews-utils.c
+++ b/src/camel/camel-ews-utils.c
@@ -504,8 +504,7 @@ add_folder_to_summary (CamelEwsStore *store, EEwsFolder *folder)
 	CamelEwsStoreSummary *ews_summary = store->summary;
 	const EwsFolderId *pfid, *fid;
 	const gchar *dname;
-	gchar *fname;
-	gint64 flags = 0, unread, total, ftype;
+	gint64 unread, total, ftype;
 
 	fid = e_ews_folder_get_id (folder);
 	pfid = e_ews_folder_get_parent_id (folder);
@@ -518,20 +517,6 @@ add_folder_to_summary (CamelEwsStore *store, EEwsFolder *folder)
 					    pfid->id, fid->change_key,
 					    dname, ftype, 0, total);
 	camel_ews_store_summary_set_folder_unread (ews_summary, fid->id, unread);
-
-	fname = camel_ews_store_summary_get_folder_full_name (ews_summary, fid->id, NULL);
-	if (!g_ascii_strcasecmp (fname, "Inbox")) {
-		flags |= CAMEL_FOLDER_SYSTEM | CAMEL_FOLDER_TYPE_INBOX;
-	} else if (!g_ascii_strcasecmp (fname, "Drafts")) {
-		flags |= CAMEL_FOLDER_SYSTEM;
-	} else if (!g_ascii_strcasecmp (fname, "Deleted items")) {
-		flags |= CAMEL_FOLDER_SYSTEM |CAMEL_FOLDER_TYPE_TRASH;
-	} else if (!g_ascii_strcasecmp (fname, "Outbox")) {
-		flags |= CAMEL_FOLDER_SYSTEM | CAMEL_FOLDER_TYPE_OUTBOX;
-	}
-	g_free (fname);
-
-	camel_ews_store_summary_set_folder_flags (ews_summary, fid->id, flags);
 }
 
 struct add_esrc_data {



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