[evolution-mapi] Bug #668820 - Subscribed public calendar/task are shown in mail view



commit b86391f38209420b69c67896006b247eb399d8c4
Author: Milan Crha <mcrha redhat com>
Date:   Tue Jan 31 17:55:05 2012 +0100

    Bug #668820 - Subscribed public calendar/task are shown in mail view

 src/camel/camel-mapi-store.c        |   46 +++++++++++----
 src/libexchangemapi/e-mapi-folder.c |  109 ++++++++++++++++++++++++++--------
 src/libexchangemapi/e-mapi-folder.h |    6 ++
 3 files changed, 123 insertions(+), 38 deletions(-)
---
diff --git a/src/camel/camel-mapi-store.c b/src/camel/camel-mapi-store.c
index 53fc8d8..826ddbe 100644
--- a/src/camel/camel-mapi-store.c
+++ b/src/camel/camel-mapi-store.c
@@ -489,7 +489,8 @@ mapi_folders_sync (CamelMapiStore *store, guint32 flags, GCancellable *cancellab
 		   them from an automatic removal */
 		if (((msi->mapi_folder_flags & CAMEL_MAPI_STORE_FOLDER_FLAG_PUBLIC) == 0 &&
 		    (msi->mapi_folder_flags & CAMEL_MAPI_STORE_FOLDER_FLAG_FOREIGN) == 0) ||
-		    (msi->mapi_folder_flags & CAMEL_MAPI_STORE_FOLDER_FLAG_PUBLIC_REAL) != 0)
+		    ((msi->mapi_folder_flags & CAMEL_MAPI_STORE_FOLDER_FLAG_PUBLIC_REAL) != 0 &&
+		    (msi->mapi_folder_flags & CAMEL_STORE_INFO_FOLDER_SUBSCRIBED) == 0))
 			g_hash_table_insert (old_cache_folders, g_strdup (camel_store_info_path (store->summary, msi)), GINT_TO_POINTER (1));
 
 		camel_store_summary_info_free (store->summary, (CamelStoreInfo *) msi);
@@ -590,16 +591,6 @@ mapi_folders_sync (CamelMapiStore *store, guint32 flags, GCancellable *cancellab
 			msi->info.unread = info->unread;
 			msi->mapi_folder_flags |= CAMEL_MAPI_STORE_FOLDER_FLAG_MAIL;
 
-			if (folder->category == E_MAPI_FOLDER_CATEGORY_PUBLIC) {
-				CamelStoreInfo *si = camel_mapi_store_summary_get_folder_id (store->summary, msi->folder_id);
-
-				if (si) {
-					if ((si->flags & CAMEL_FOLDER_SUBSCRIBED) != 0)
-						msi->info.flags |= CAMEL_FOLDER_SUBSCRIBED;
-					camel_store_summary_info_free (store->summary, si);
-				}
-			}
-
 			camel_store_summary_info_free (store->summary, (CamelStoreInfo *) msi);
 			camel_folder_info_free (info);
 		} else if (folder->category == E_MAPI_FOLDER_CATEGORY_PUBLIC) {
@@ -623,7 +614,6 @@ mapi_folders_sync (CamelMapiStore *store, guint32 flags, GCancellable *cancellab
 				continue;
 
 			msi->info.flags = info->flags;
-			msi->mapi_folder_flags |= CAMEL_MAPI_STORE_FOLDER_FLAG_MAIL;
 
 			camel_store_summary_info_free (store->summary, (CamelStoreInfo *) msi);
 			camel_folder_info_free (info);
@@ -707,6 +697,7 @@ mapi_get_folder_info_offline (CamelStore *store, const gchar *top,
 			 guint32 flags, GError **error)
 {
 	CamelMapiStore *mapi_store = CAMEL_MAPI_STORE (store);
+	CamelNetworkSettings *network_settings;
 	CamelFolderInfo *fi;
 	GPtrArray *folders;
 	gchar *path;
@@ -717,6 +708,7 @@ mapi_get_folder_info_offline (CamelStore *store, const gchar *top,
 	subscription_list = (flags & CAMEL_STORE_FOLDER_INFO_SUBSCRIPTION_LIST);
 	subscribed = (flags & CAMEL_STORE_FOLDER_INFO_SUBSCRIBED);
 
+	network_settings = CAMEL_NETWORK_SETTINGS (camel_service_get_settings (CAMEL_SERVICE (store)));
 	folders = g_ptr_array_new ();
 
 	if (!top || !*top)
@@ -772,6 +764,32 @@ mapi_get_folder_info_offline (CamelStore *store, const gchar *top,
 			fi->total = si->total;
 			fi->flags = si->flags;
 
+			if (subscription_list) {
+				guint folder_type;
+				CamelStoreInfo *si2;
+
+				si2 = camel_mapi_store_summary_get_folder_id (mapi_store->summary, msi->folder_id);
+				if (si2) {
+					if (si != si2)
+						fi->flags = si2->flags;
+
+					camel_store_summary_info_free (mapi_store->summary, si2);
+				}
+
+				folder_type = mapi_folders_hash_table_type_lookup (mapi_store, camel_store_info_path (mapi_store->summary, si));
+				if (folder_type != E_MAPI_FOLDER_TYPE_UNKNOWN && folder_type != E_MAPI_FOLDER_TYPE_MAIL) {
+					gchar *fid = e_mapi_util_mapi_id_to_string (msi->folder_id);
+
+					if (e_mapi_folder_is_subscribed_as_esource (folder_type,
+						camel_network_settings_get_host (network_settings),
+						camel_network_settings_get_user (network_settings),
+						fid))
+						fi->flags |= CAMEL_FOLDER_SUBSCRIBED;
+
+					g_free (fid);
+				}
+			}
+
 			g_ptr_array_add (folders, fi);
 		}
 		camel_store_summary_info_free (mapi_store->summary, si);
@@ -1744,6 +1762,10 @@ mapi_store_subscribe_folder_sync (CamelSubscribable *subscribable,
 		gchar *folder_id;
 		guint folder_type = mapi_folders_hash_table_type_lookup (mapi_store, folder_name);
 
+		/* remember the folder, thus it can be removed and checked in Subscriptions dialog */
+		msi->camel_folder_flags = msi->camel_folder_flags | CAMEL_FOLDER_SUBSCRIBED | CAMEL_STORE_INFO_FOLDER_SUBSCRIBED | CAMEL_FOLDER_NOCHILDREN;
+		camel_store_summary_touch (mapi_store->summary);
+
 		settings = camel_service_get_settings (CAMEL_SERVICE (mapi_store));
 		mapi_settings = CAMEL_MAPI_SETTINGS (settings);
 		network_settings = CAMEL_NETWORK_SETTINGS (settings);
diff --git a/src/libexchangemapi/e-mapi-folder.c b/src/libexchangemapi/e-mapi-folder.c
index d99e3dd..cb81763 100644
--- a/src/libexchangemapi/e-mapi-folder.c
+++ b/src/libexchangemapi/e-mapi-folder.c
@@ -254,6 +254,23 @@ e_mapi_folder_pick_color_spec (gint move_by,
 
 #define MAPI_URI_PREFIX   "mapi://" 
 
+static const gchar *
+get_gconf_key_for_folder_type (EMapiFolderType folder_type)
+{
+	if (folder_type == E_MAPI_FOLDER_TYPE_APPOINTMENT)
+		return CALENDAR_SOURCES;
+	else if (folder_type == E_MAPI_FOLDER_TYPE_TASK)
+		return TASK_SOURCES;
+	else if (folder_type == E_MAPI_FOLDER_TYPE_MEMO)
+		return JOURNAL_SOURCES;
+	else if (folder_type == E_MAPI_FOLDER_TYPE_JOURNAL)
+		return JOURNAL_SOURCES;
+	else if (folder_type == E_MAPI_FOLDER_TYPE_CONTACT)
+		return ADDRESSBOOK_SOURCES;
+
+	return NULL;
+}
+
 gboolean
 e_mapi_folder_add_as_esource (EMapiFolderType folder_type,
 			      const gchar *login_profile,
@@ -287,17 +304,8 @@ e_mapi_folder_add_as_esource (EMapiFolderType folder_type,
 	if (folder_category == E_MAPI_FOLDER_CATEGORY_FOREIGN)
 		g_return_val_if_fail (foreign_username != NULL, FALSE);
 
-	if (folder_type == E_MAPI_FOLDER_TYPE_APPOINTMENT)
-		conf_key = CALENDAR_SOURCES;
-	else if (folder_type == E_MAPI_FOLDER_TYPE_TASK)
-		conf_key = TASK_SOURCES;
-	else if (folder_type == E_MAPI_FOLDER_TYPE_MEMO)
-		conf_key = JOURNAL_SOURCES;
-	else if (folder_type == E_MAPI_FOLDER_TYPE_JOURNAL)
-		conf_key = JOURNAL_SOURCES;
-	else if (folder_type == E_MAPI_FOLDER_TYPE_CONTACT)
-		conf_key = ADDRESSBOOK_SOURCES;
-	else {
+	conf_key = get_gconf_key_for_folder_type (folder_type);
+	if (!conf_key) {
 		g_propagate_error (perror, g_error_new_literal (E_MAPI_ERROR, MAPI_E_INVALID_PARAMETER, _("Cannot add folder, unsupported folder type")));
 		return FALSE;
 	}
@@ -321,14 +329,15 @@ e_mapi_folder_add_as_esource (EMapiFolderType folder_type,
 		gchar *folder_id = e_source_get_duped_property (source, "folder-id");
 		if (folder_id) {
 			if (g_str_equal (fid, folder_id)) {
+				g_propagate_error (perror,
+					g_error_new (E_MAPI_ERROR, MAPI_E_INVALID_PARAMETER,
+						_("Cannot add folder, folder already exists as '%s'"), e_source_peek_name (source)));
+
 				g_object_unref (source_list);
 				g_object_unref (client);
 				g_free (folder_id);
 				g_free (base_uri);
-				
-				g_propagate_error (perror,
-					g_error_new (E_MAPI_ERROR, MAPI_E_INVALID_PARAMETER,
-						_("Cannot add folder, folder already exists as '%s'"), e_source_peek_name (source)));
+
 				return FALSE;
 			}
 
@@ -401,17 +410,8 @@ e_mapi_folder_remove_as_esource (EMapiFolderType folder_type,
 	g_return_val_if_fail (login_user != NULL, FALSE);
 	g_return_val_if_fail (fid != NULL, FALSE);
 
-	if (folder_type == E_MAPI_FOLDER_TYPE_APPOINTMENT)
-		conf_key = CALENDAR_SOURCES;
-	else if (folder_type == E_MAPI_FOLDER_TYPE_TASK)
-		conf_key = TASK_SOURCES;
-	else if (folder_type == E_MAPI_FOLDER_TYPE_MEMO)
-		conf_key = JOURNAL_SOURCES;
-	else if (folder_type == E_MAPI_FOLDER_TYPE_JOURNAL)
-		conf_key = JOURNAL_SOURCES;
-	else if (folder_type == E_MAPI_FOLDER_TYPE_CONTACT)
-		conf_key = ADDRESSBOOK_SOURCES;
-	else {
+	conf_key = get_gconf_key_for_folder_type (folder_type);
+	if (!conf_key) {
 		g_propagate_error (perror, g_error_new_literal (E_MAPI_ERROR, MAPI_E_INVALID_PARAMETER, _("Cannot remove folder, unsupported folder type")));
 		return FALSE;
 	}
@@ -450,3 +450,60 @@ e_mapi_folder_remove_as_esource (EMapiFolderType folder_type,
 
 	return TRUE;
 }
+
+gboolean
+e_mapi_folder_is_subscribed_as_esource (EMapiFolderType folder_type,
+					const gchar *login_host,
+					const gchar *login_user,
+					const gchar *fid)
+{
+	ESourceList *source_list = NULL;
+	ESourceGroup *group = NULL;
+	const gchar *conf_key = NULL;
+	GConfClient* client;
+	GSList *sources = NULL;
+	gchar *base_uri = NULL;
+	gboolean found = FALSE;
+
+	g_return_val_if_fail (login_host != NULL, FALSE);
+	g_return_val_if_fail (login_user != NULL, FALSE);
+	g_return_val_if_fail (fid != NULL, FALSE);
+
+	conf_key = get_gconf_key_for_folder_type (folder_type);
+	if (!conf_key)
+		return FALSE;
+
+	client = gconf_client_get_default ();
+	source_list = e_source_list_new_for_gconf (client, conf_key);
+	base_uri = g_strdup_printf ("%s%s %s/", MAPI_URI_PREFIX, login_user, login_host);
+	group = e_source_list_peek_group_by_base_uri (source_list, base_uri);
+	if (!group) {
+		g_free (base_uri);
+		g_object_unref (source_list);
+		g_object_unref (client);
+
+		return FALSE;
+	}
+
+	sources = e_source_group_peek_sources (group);
+	for (; sources != NULL; sources = g_slist_next (sources)) {
+		ESource *source = E_SOURCE (sources->data);
+		gchar *folder_id = e_source_get_duped_property (source, "folder-id");
+		if (folder_id) {
+			if (g_str_equal (fid, folder_id)) {
+				g_free (folder_id);
+
+				found = TRUE;
+				break;
+			}
+
+			g_free (folder_id);
+		}
+	}
+
+	g_free (base_uri);
+	g_object_unref (source_list);
+	g_object_unref (client);
+
+	return found;
+}
diff --git a/src/libexchangemapi/e-mapi-folder.h b/src/libexchangemapi/e-mapi-folder.h
index 3212fb6..e65a087 100644
--- a/src/libexchangemapi/e-mapi-folder.h
+++ b/src/libexchangemapi/e-mapi-folder.h
@@ -128,4 +128,10 @@ gboolean		e_mapi_folder_remove_as_esource	(EMapiFolderType folder_type,
 							 const gchar *login_user,
 							 const gchar *fid,
 							 GError **perror);
+
+gboolean		e_mapi_folder_is_subscribed_as_esource
+							(EMapiFolderType folder_type,
+							 const gchar *login_host,
+							 const gchar *login_user,
+							 const gchar *fid);
 #endif



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