Blob Blame History Raw
diff -up evolution-data-server-3.12.11/camel/providers/imapx/camel-imapx-store.c.camel-imapx-folder-removed-on-refresh evolution-data-server-3.12.11/camel/providers/imapx/camel-imapx-store.c
--- evolution-data-server-3.12.11/camel/providers/imapx/camel-imapx-store.c.camel-imapx-folder-removed-on-refresh	2015-07-24 13:52:20.253840769 +0200
+++ evolution-data-server-3.12.11/camel/providers/imapx/camel-imapx-store.c	2015-07-24 13:52:20.266840678 +0200
@@ -468,7 +468,7 @@ imapx_store_process_mailbox_attributes (
 	fi = imapx_store_build_folder_info (store, folder_path, flags);
 
 	/* Figure out which signals to emit, if any. */
-	if (use_subscriptions) {
+	if (use_subscriptions || camel_imapx_namespace_get_category (camel_imapx_mailbox_get_namespace (mailbox)) != CAMEL_IMAPX_NAMESPACE_PERSONAL) {
 		/* If we are honoring folder subscriptions, then
 		 * subscription changes are equivalent to folder
 		 * creation / deletion as far as we're concerned. */
@@ -1079,6 +1079,20 @@ get_folder_info_offline (CamelStore *sto
 		if (!si_is_match)
 			continue;
 
+		if (!use_subscriptions && !(si->flags & CAMEL_STORE_INFO_FOLDER_SUBSCRIBED) &&
+		    !(flags & CAMEL_STORE_FOLDER_INFO_SUBSCRIPTION_LIST)) {
+			CamelIMAPXMailbox *mailbox;
+
+			mailbox = camel_imapx_store_ref_mailbox (imapx_store, ((CamelIMAPXStoreInfo *) si)->mailbox_name);
+			if (!mailbox || camel_imapx_namespace_get_category (camel_imapx_mailbox_get_namespace (mailbox)) != CAMEL_IMAPX_NAMESPACE_PERSONAL) {
+				/* Skip unsubscribed mailboxes which are not in the Personal namespace */
+				g_clear_object (&mailbox);
+				continue;
+			}
+
+			g_clear_object (&mailbox);
+		}
+
 		fi = imapx_store_build_folder_info (
 			imapx_store, folder_path, 0);
 		fi->unread = si->unread;
@@ -1417,6 +1431,58 @@ imapx_store_remove_unknown_mailboxes_cb
 }
 
 static gboolean
+imapx_store_mailbox_is_unknown (CamelIMAPXStore *imapx_store,
+				GPtrArray *store_infos,
+				const CamelIMAPXStoreInfo *to_check)
+{
+	CamelIMAPXMailbox *mailbox;
+	gboolean is_unknown;
+
+	g_return_val_if_fail (CAMEL_IS_IMAPX_STORE (imapx_store), FALSE);
+	g_return_val_if_fail (store_infos != NULL, FALSE);
+
+	if (!to_check || !to_check->mailbox_name || !*to_check->mailbox_name)
+		return FALSE;
+
+	mailbox = camel_imapx_store_ref_mailbox (imapx_store, to_check->mailbox_name);
+
+	is_unknown = mailbox && camel_imapx_mailbox_get_state (mailbox) == CAMEL_IMAPX_MAILBOX_STATE_UNKNOWN;
+
+	if (!mailbox && to_check->separator) {
+		CamelSettings *settings;
+		gboolean use_subscriptions;
+		gchar *mailbox_with_separator;
+		gint ii;
+
+		settings = camel_service_ref_settings (CAMEL_SERVICE (imapx_store));
+		use_subscriptions = camel_imapx_settings_get_use_subscriptions (CAMEL_IMAPX_SETTINGS (settings));
+		g_object_unref (settings);
+
+		mailbox_with_separator = g_strdup_printf ("%s%c", to_check->mailbox_name, to_check->separator);
+
+		for (ii = 0; ii < store_infos->len; ii++) {
+			CamelIMAPXStoreInfo *si;
+
+			si = g_ptr_array_index (store_infos, ii);
+
+			if (si->mailbox_name && g_str_has_prefix (si->mailbox_name, mailbox_with_separator) && (
+			    !use_subscriptions || (((CamelStoreInfo *) si)->flags & CAMEL_STORE_INFO_FOLDER_SUBSCRIBED) != 0)) {
+				/* This can be a 'virtual' parent folder of some subscribed subfolder */
+				break;
+			}
+		}
+
+		is_unknown = ii == store_infos->len;
+
+		g_free (mailbox_with_separator);
+	}
+
+	g_clear_object (&mailbox);
+
+	return is_unknown;
+}
+
+static gboolean
 sync_folders (CamelIMAPXStore *imapx_store,
               const gchar *root_folder_path,
               CamelStoreGetFolderInfoFlags flags,
@@ -1426,8 +1492,7 @@ sync_folders (CamelIMAPXStore *imapx_sto
 {
 	CamelIMAPXServer *server;
 	GHashTable *folder_info_results;
-	GPtrArray *array;
-	guint ii;
+	gboolean update_folder_list;
 	gboolean success;
 
 	server = camel_imapx_store_ref_server (imapx_store, NULL, FALSE, cancellable, error);
@@ -1445,7 +1510,9 @@ sync_folders (CamelIMAPXStore *imapx_sto
 	 * in imapx_store_process_mailbox_attributes(). */
 	g_atomic_int_inc (&imapx_store->priv->syncing_folders);
 
-	if (!initial_setup && (!root_folder_path || !*root_folder_path)) {
+	update_folder_list = !initial_setup && (!root_folder_path || !*root_folder_path);
+
+	if (update_folder_list) {
 		g_mutex_lock (&imapx_store->priv->mailboxes_lock);
 		g_hash_table_foreach (imapx_store->priv->mailboxes, imapx_store_mark_mailbox_unknown_cb, imapx_store);
 		g_mutex_unlock (&imapx_store->priv->mailboxes_lock);
@@ -1458,9 +1525,9 @@ sync_folders (CamelIMAPXStore *imapx_sto
 	} else {
 		gboolean have_folder_info_for_inbox;
 
-		/* XXX We only fetch personal mailboxes at this time. */
 		success = fetch_folder_info_for_namespace_category (
-			imapx_store, server, CAMEL_IMAPX_NAMESPACE_PERSONAL, flags,
+			imapx_store, server, CAMEL_IMAPX_NAMESPACE_PERSONAL, flags |
+			(update_folder_list ? CAMEL_STORE_FOLDER_INFO_SUBSCRIBED : 0),
 			folder_info_results, cancellable, error);
 
 		have_folder_info_for_inbox =
@@ -1481,53 +1548,41 @@ sync_folders (CamelIMAPXStore *imapx_sto
 	if (!success)
 		goto exit;
 
-	if (!initial_setup && (!root_folder_path || !*root_folder_path)) {
+	if (update_folder_list) {
 		g_mutex_lock (&imapx_store->priv->mailboxes_lock);
 		g_hash_table_foreach_remove (imapx_store->priv->mailboxes, imapx_store_remove_unknown_mailboxes_cb, imapx_store);
 		g_mutex_unlock (&imapx_store->priv->mailboxes_lock);
 	}
 
-	array = camel_store_summary_array (imapx_store->summary);
-
-	for (ii = 0; ii < array->len; ii++) {
-		CamelStoreInfo *si;
-		CamelFolderInfo *fi;
-		const gchar *mailbox_name;
-		const gchar *si_path;
-		gboolean pattern_match;
-
-		si = g_ptr_array_index (array, ii);
-		si_path = camel_store_info_path (imapx_store->summary, si);
-
-		mailbox_name = ((CamelIMAPXStoreInfo *) si)->mailbox_name;
-		if (mailbox_name == NULL || *mailbox_name == '\0')
-			continue;
-
-		pattern_match =
-			(root_folder_path == NULL) ||
-			(*root_folder_path == '\0') ||
-			(g_str_has_prefix (si_path, root_folder_path));
-		if (!pattern_match)
-			continue;
-
-		fi = g_hash_table_lookup (folder_info_results, mailbox_name);
-
-		if (fi == NULL) {
-			gchar *dup_folder_path = g_strdup (si_path);
-
-			if (dup_folder_path != NULL) {
-				/* Do not unsubscribe from it, it influences UI for non-subscribable folders */
-				imapx_delete_folder_from_cache (
-					imapx_store, dup_folder_path, FALSE);
-				g_free (dup_folder_path);
-			} else {
-				camel_store_summary_remove (
-					imapx_store->summary, si);
+	if (!root_folder_path || !*root_folder_path) {
+		GPtrArray *array;
+		guint ii;
+
+		/* Finally update store's summary */
+		array = camel_store_summary_array (imapx_store->summary);
+		for (ii = 0; array && ii < array->len; ii++) {
+			CamelStoreInfo *si;
+			const gchar *si_path;
+
+			si = g_ptr_array_index (array, ii);
+			si_path = camel_store_info_path (imapx_store->summary, si);
+
+			if (imapx_store_mailbox_is_unknown (imapx_store, array, (CamelIMAPXStoreInfo *) si)) {
+				gchar *dup_folder_path = g_strdup (si_path);
+
+				if (dup_folder_path != NULL) {
+					/* Do not unsubscribe from it, it influences UI for non-subscribable folders */
+					imapx_delete_folder_from_cache (imapx_store, dup_folder_path, FALSE);
+					g_free (dup_folder_path);
+				} else {
+					camel_store_summary_remove (imapx_store->summary, si);
+				}
 			}
 		}
+
+		camel_store_summary_array_free (imapx_store->summary, array);
 	}
 
-	camel_store_summary_array_free (imapx_store->summary, array);
 	camel_store_summary_save (imapx_store->summary);
 
 exit: