[evolution-mapi] Bug #620367 - Cannot subscribe to Public folders



commit abf8f435edd502eb82972c47f0ae5420279e5fd6
Author: Milan Crha <mcrha redhat com>
Date:   Thu Jun 3 16:12:38 2010 +0200

    Bug #620367 - Cannot subscribe to Public folders

 src/camel/camel-mapi-folder.c        |   31 ++++++++---------
 src/camel/camel-mapi-store-summary.c |   52 +++++++++++++++++------------
 src/camel/camel-mapi-store-summary.h |    6 ++--
 src/camel/camel-mapi-store.c         |   60 +++++++++++++++++++++------------
 src/camel/camel-mapi-store.h         |    3 ++
 5 files changed, 90 insertions(+), 62 deletions(-)
---
diff --git a/src/camel/camel-mapi-folder.c b/src/camel/camel-mapi-folder.c
index 800a280..18f5923 100644
--- a/src/camel/camel-mapi-folder.c
+++ b/src/camel/camel-mapi-folder.c
@@ -611,6 +611,9 @@ mapi_sync_deleted (CamelSession *session, CamelSessionThreadMsg *msg)
 
 	camel_service_lock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
 
+	if (mapi_folder->type & CAMEL_MAPI_FOLDER_PUBLIC)
+		options |= MAPI_OPTIONS_USE_PFSTORE;
+
 	/*Get the UID list from server.*/
 	exchange_mapi_connection_fetch_items  (camel_mapi_store_get_exchange_connection (mapi_store), m->folder_id, NULL, NULL,
 					       mapi_camel_get_last_modif_list, NULL,
@@ -1654,7 +1657,7 @@ camel_mapi_folder_new (CamelStore *store, const gchar *folder_name, const gchar
 
 	gchar *summary_file, *state_file;
 	const gchar *short_name;
-	guint32 i = 0;
+	CamelStoreInfo *si;
 
 	short_name = strrchr (folder_name, '/');
 	if (short_name)
@@ -1713,22 +1716,18 @@ camel_mapi_folder_new (CamelStore *store, const gchar *folder_name, const gchar
 		return NULL;
 	}
 
-	for (i=0;i<camel_store_summary_count((CamelStoreSummary *)mapi_store->summary);i++) {
-		CamelStoreInfo *si = camel_store_summary_index((CamelStoreSummary *)mapi_store->summary, i);
-		if (si == NULL)
-			continue;
-
-		if (!strcmp(folder_name, camel_mapi_store_info_full_name (mapi_store->summary, si))) {
-			mapi_folder->type = si->flags;
-			if ((si->flags & CAMEL_FOLDER_TYPE_MASK) == CAMEL_FOLDER_TYPE_TRASH)
-				folder->folder_flags |= CAMEL_FOLDER_IS_TRASH;
-			else if ((si->flags & CAMEL_FOLDER_TYPE_MASK) == CAMEL_FOLDER_TYPE_JUNK)
-				folder->folder_flags  |= CAMEL_FOLDER_IS_JUNK;
-			camel_store_summary_info_free((CamelStoreSummary *)mapi_store->summary, si);
-			break;
-		}
+	si = camel_mapi_store_summary_full_name (mapi_store->summary, folder_name);
+	if (si) {
+		mapi_folder->type = si->flags;
 
-		camel_store_summary_info_free((CamelStoreSummary *)mapi_store->summary, si);
+		if ((si->flags & CAMEL_FOLDER_TYPE_MASK) == CAMEL_FOLDER_TYPE_TRASH)
+			folder->folder_flags |= CAMEL_FOLDER_IS_TRASH;
+		else if ((si->flags & CAMEL_FOLDER_TYPE_MASK) == CAMEL_FOLDER_TYPE_JUNK)
+			folder->folder_flags  |= CAMEL_FOLDER_IS_JUNK;
+		camel_store_summary_info_free ((CamelStoreSummary *)mapi_store->summary, si);
+	} else {
+		g_warning ("%s: cannot find '%s' in known folders", G_STRFUNC, folder_name);
 	}
+
 	return folder;
 }
diff --git a/src/camel/camel-mapi-store-summary.c b/src/camel/camel-mapi-store-summary.c
index 933ec3e..f6e05a9 100644
--- a/src/camel/camel-mapi-store-summary.c
+++ b/src/camel/camel-mapi-store-summary.c
@@ -235,24 +235,34 @@ store_info_set_string(CamelStoreSummary *s, CamelStoreInfo *mi, gint type, const
 	}
 }
 
-CamelMapiStoreInfo *
-camel_mapi_store_summary_full_name(CamelMapiStoreSummary *s, const gchar *full_name)
+CamelStoreInfo *
+camel_mapi_store_summary_full_name(CamelMapiStoreSummary *ms, const gchar *full_name)
 {
 	gint count, i;
-	CamelMapiStoreInfo *info;
-
-	count = camel_store_summary_count((CamelStoreSummary *)s);
-	for (i=0;i<count;i++) {
-		info = (CamelMapiStoreInfo *)camel_store_summary_index((CamelStoreSummary *)s, i);
-		if (info) {
-			if (strcmp(info->full_name, full_name) == 0)
-				return info;
-			camel_store_summary_info_free((CamelStoreSummary *)s, (CamelStoreInfo *)info);
+	CamelStoreInfo *si;
+	CamelStoreSummary *s;
+	const gchar *favourite = NULL;
+
+	g_return_val_if_fail (full_name != NULL, NULL);
+
+	s = CAMEL_STORE_SUMMARY (ms);
+	g_return_val_if_fail (s != NULL, NULL);
+
+	if (g_str_has_prefix (full_name, DISPLAY_NAME_FAVOURITES))
+		favourite = full_name + strlen (DISPLAY_NAME_FAVOURITES) + 1;
+
+	count = camel_store_summary_count (s);
+	for (i = 0; i < count; i++) {
+		si = camel_store_summary_index (s, i);
+		if (si) {
+			if (g_str_equal (camel_mapi_store_info_full_name (s, si), full_name)
+			    || (favourite && g_str_equal (camel_store_info_name (s, si), favourite)))
+				return si;
+			camel_store_summary_info_free (s, si);
 		}
 	}
 
 	return NULL;
-
 }
 
 gchar *
@@ -283,9 +293,9 @@ camel_mapi_store_summary_full_to_path(CamelMapiStoreSummary *s, const gchar *ful
 
 CamelMapiStoreInfo *
 camel_mapi_store_summary_add_from_full(CamelMapiStoreSummary *s, const gchar *full,
-				       gchar dir_sep, gchar *folder_id, gchar *parent_id)
+				       gchar dir_sep, const gchar *folder_id, const gchar *parent_id)
 {
-	CamelMapiStoreInfo *info;
+	CamelStoreInfo *info;
 	gchar *pathu8;
 	gint len;
 	gchar *full_name;
@@ -300,20 +310,20 @@ camel_mapi_store_summary_add_from_full(CamelMapiStoreSummary *s, const gchar *fu
 
 	info = camel_mapi_store_summary_full_name(s, full_name);
 	if (info) {
-		camel_store_summary_info_free((CamelStoreSummary *)s, (CamelStoreInfo *)info);
+		camel_store_summary_info_free((CamelStoreSummary *)s, info);
 		d(printf("  already there\n"));
-		return info;
+		return (CamelMapiStoreInfo *) info;
 	}
 	pathu8 = camel_mapi_store_summary_full_to_path(s, full_name, '/');
-	info = (CamelMapiStoreInfo *)camel_store_summary_add_from_path((CamelStoreSummary *)s, pathu8);
+	info = camel_store_summary_add_from_path ((CamelStoreSummary *)s, pathu8);
 
 	if (info) {
-		camel_store_info_set_string((CamelStoreSummary *)s, (CamelStoreInfo *)info, CAMEL_MAPI_STORE_INFO_FULL_NAME, full_name);
-		camel_store_info_set_string((CamelStoreSummary *)s, (CamelStoreInfo *)info, CAMEL_MAPI_STORE_INFO_FOLDER_ID, folder_id);
-		camel_store_info_set_string((CamelStoreSummary *)s, (CamelStoreInfo *)info, CAMEL_MAPI_STORE_INFO_PARENT_ID, parent_id);
+		camel_store_info_set_string ((CamelStoreSummary *)s, info, CAMEL_MAPI_STORE_INFO_FULL_NAME, full_name);
+		camel_store_info_set_string ((CamelStoreSummary *)s, info, CAMEL_MAPI_STORE_INFO_FOLDER_ID, folder_id);
+		camel_store_info_set_string ((CamelStoreSummary *)s, info, CAMEL_MAPI_STORE_INFO_PARENT_ID, parent_id);
 	}
 
-	return info;
+	return (CamelMapiStoreInfo *) info;
 }
 
 gchar *
diff --git a/src/camel/camel-mapi-store-summary.h b/src/camel/camel-mapi-store-summary.h
index 7b8ad56..0094b78 100644
--- a/src/camel/camel-mapi-store-summary.h
+++ b/src/camel/camel-mapi-store-summary.h
@@ -59,7 +59,7 @@ enum {
 	CAMEL_MAPI_STORE_INFO_FULL_NAME = CAMEL_STORE_INFO_LAST,
 	CAMEL_MAPI_STORE_INFO_FOLDER_ID,
 	CAMEL_MAPI_STORE_INFO_PARENT_ID,
-	CAMEL_MAPI_STORE_INFO_LAST,
+	CAMEL_MAPI_STORE_INFO_LAST
 };
 
 struct _CamelMapiStoreInfo {
@@ -84,9 +84,9 @@ struct _CamelMapiStoreSummaryClass {
 
 GType                        camel_mapi_store_summary_get_type      (void);
 CamelMapiStoreSummary      *camel_mapi_store_summary_new        (void);
-CamelMapiStoreInfo *camel_mapi_store_summary_full_name(CamelMapiStoreSummary *s, const gchar *full_name);
+CamelStoreInfo *camel_mapi_store_summary_full_name(CamelMapiStoreSummary *s, const gchar *full_name);
 CamelMapiStoreInfo *camel_mapi_store_summary_add_from_full(CamelMapiStoreSummary *s, const gchar *full, gchar dir_sep,
-							   gchar *folder_id, gchar *parent_id);
+							   const gchar *folder_id, const gchar *parent_id);
 
 gchar *camel_mapi_store_summary_full_to_path(CamelMapiStoreSummary *s, const gchar *full_name, gchar dir_sep);
 gchar *camel_mapi_store_summary_path_to_full(CamelMapiStoreSummary *s, const gchar *path, gchar dir_sep);
diff --git a/src/camel/camel-mapi-store.c b/src/camel/camel-mapi-store.c
index 1bf49cd..a0c3b58 100644
--- a/src/camel/camel-mapi-store.c
+++ b/src/camel/camel-mapi-store.c
@@ -45,9 +45,6 @@
 /* This definition should be in-sync with those in exchange-mapi-account-setup.c and exchange-account-listener.c */
 #define E_PASSWORD_COMPONENT "ExchangeMAPI"
 
-#define DISPLAY_NAME_FAVOURITES _("Favorites")
-#define DISPLAY_NAME_ALL_PUBLIC_FOLDERS _("All Public Folders")
-
 #include <sys/types.h>
 #include <stdint.h>
 #include <stdbool.h>
@@ -501,7 +498,7 @@ mapi_get_folder(CamelStore *store, const gchar *folder_name, guint32 flags, Came
 {
 	CamelMapiStore *mapi_store = CAMEL_MAPI_STORE (store);
 	CamelMapiStorePrivate *priv = mapi_store->priv;
-	CamelMapiStoreInfo *si;
+	CamelStoreInfo *si;
 	CamelFolder *folder;
 	gchar *storage_path;
 
@@ -530,7 +527,7 @@ mapi_get_folder(CamelStore *store, const gchar *folder_name, guint32 flags, Came
 	}
 
 	if (si)
-		camel_store_summary_info_free ((CamelStoreSummary *)mapi_store->summary, (CamelStoreInfo *)si);
+		camel_store_summary_info_free ((CamelStoreSummary *)mapi_store->summary, si);
 
 	storage_path = g_strdup_printf ("%s/folders", priv->storage_path);
 	folder = camel_mapi_folder_new (store, folder_name, storage_path, flags, ex);
@@ -1399,7 +1396,12 @@ mapi_folders_sync (CamelMapiStore *store, guint32 flags, CamelException *ex)
 		if (si == NULL)
 			continue;
 
-		g_hash_table_insert (old_cache_folders, g_strdup (camel_store_info_path (store->summary, si)), GINT_TO_POINTER (1));
+		/* those whose left in old_cache_folders are removed at the end,
+		   which is not good for public folders, thus preserve them from
+		   an automatic removal */
+		if ((si->flags & CAMEL_MAPI_FOLDER_PUBLIC) == 0 || (si->flags & CAMEL_FOLDER_SUBSCRIBED) == 0)
+			g_hash_table_insert (old_cache_folders, g_strdup (camel_store_info_path (store->summary, si)), GINT_TO_POINTER (1));
+
 		camel_store_summary_info_free ((CamelStoreSummary *)store->summary, si);
 	}
 
@@ -1532,7 +1534,6 @@ mapi_get_folder_info(CamelStore *store, const gchar *top, guint32 flags, CamelEx
 {
 	CamelMapiStore *mapi_store = CAMEL_MAPI_STORE (store);
 	CamelFolderInfo *info = NULL;
-	gint s_count = 0;
 
 	/*
 	 * Thanks to Michael, for his cached folders implementation in IMAP
@@ -1568,7 +1569,6 @@ mapi_get_folder_info(CamelStore *store, const gchar *top, guint32 flags, CamelEx
 
 	camel_service_unlock (CAMEL_SERVICE (store), CAMEL_SERVICE_REC_CONNECT_LOCK);
 
-	s_count = camel_store_summary_count((CamelStoreSummary *)mapi_store->summary);
 	info = mapi_get_folder_info_offline (store, top, flags, ex);
 	return info;
 }
@@ -1627,13 +1627,29 @@ static gboolean
 mapi_subscribe_folder(CamelStore *store, const gchar *folder_name, CamelException *ex)
 {
 	CamelMapiStore *mapi_store = CAMEL_MAPI_STORE (store);
-
 	CamelFolderInfo *fi;
 	CamelStoreInfo *si = NULL;
-	gchar *parent_name = NULL;
-	gchar *f_name = NULL;
+	const gchar *parent_name = NULL, *use_folder_name = folder_name;
+	gboolean favourites = FALSE;
 	/* TODO : exchange_mapi_add_to_favorites (); */
 
+	if (g_str_has_prefix (folder_name, DISPLAY_NAME_ALL_PUBLIC_FOLDERS) ) {
+		const gchar *f_name = NULL;
+
+		parent_name = DISPLAY_NAME_FAVOURITES;
+
+		f_name = strrchr (folder_name,'/');
+		if (!f_name) {
+			/* Don't process All Public Folder. */
+			return TRUE;
+		}
+
+		use_folder_name = ++f_name;
+		favourites = TRUE;
+	}
+
+	fi = mapi_build_folder_info (mapi_store, parent_name, use_folder_name);
+
 	si = camel_store_summary_path((CamelStoreSummary *)mapi_store->summary, folder_name);
 	if (si != NULL) {
 		if ((si->flags & CAMEL_STORE_INFO_FOLDER_SUBSCRIBED) == 0) {
@@ -1641,20 +1657,20 @@ mapi_subscribe_folder(CamelStore *store, const gchar *folder_name, CamelExceptio
 			si->flags |= CAMEL_FOLDER_SUBSCRIBED;
 			camel_store_summary_touch((CamelStoreSummary *)mapi_store->summary);
 		}
-		camel_store_summary_info_free((CamelStoreSummary *)mapi_store->summary, si);
-	}
 
-	if (g_str_has_prefix (folder_name, DISPLAY_NAME_ALL_PUBLIC_FOLDERS) ) {
-		parent_name = DISPLAY_NAME_FAVOURITES;
+		if (favourites) {
+			CamelURL *url;
 
-		f_name = strrchr(folder_name,'/');
-		if (f_name != NULL)
-			folder_name = ++f_name;
-		else  //Don't process All Public Folder.
-			return TRUE;
-	}
+			url = camel_url_new (mapi_store->priv->base_url, NULL);
+			url->path = g_strdup_printf ("/%s", camel_store_info_path (mapi_store->summary, si));
+			g_free (fi->uri);
+			fi->uri = camel_url_to_string (url, CAMEL_URL_HIDE_ALL);
 
-	fi = mapi_build_folder_info (mapi_store, parent_name, folder_name);
+			camel_url_free (url);
+		}
+
+		camel_store_summary_info_free((CamelStoreSummary *)mapi_store->summary, si);
+	}
 
 	fi->flags |= CAMEL_FOLDER_SUBSCRIBED;
 	fi->flags |= CAMEL_FOLDER_NOCHILDREN;
diff --git a/src/camel/camel-mapi-store.h b/src/camel/camel-mapi-store.h
index c701c78..24d965d 100644
--- a/src/camel/camel-mapi-store.h
+++ b/src/camel/camel-mapi-store.h
@@ -57,6 +57,9 @@
 #define CAMEL_MAPI_FOLDER_PERSONAL (CAMEL_FOLDER_FLAGS_LAST << 2)
 #define CAMEL_MAPI_FOLDER_FORIEGN (CAMEL_FOLDER_FLAGS_LAST << 3)
 
+#define DISPLAY_NAME_FAVOURITES _("Favorites")
+#define DISPLAY_NAME_ALL_PUBLIC_FOLDERS _("All Public Folders")
+
 G_BEGIN_DECLS
 
 /**



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