diff --git a/src/camel/camel-store.c b/src/camel/camel-store.c
index 2a29f6e..436fa61 100644
--- a/src/camel/camel-store.c
+++ b/src/camel/camel-store.c
@@ -326,6 +326,7 @@ store_finalize (GObject *object)
 {
 	CamelStore *store = CAMEL_STORE (object);
 
+	printf ("%s: store:%p folders:%p\n", __FUNCTION__, store, store->priv->folders);
 	if (store->priv->folders)
 		camel_object_bag_destroy (store->priv->folders);
 
@@ -340,6 +341,8 @@ store_dispose (GObject *object)
 {
 	CamelStore *store = CAMEL_STORE (object);
 
+	printf ("%s: store:%p (%s) folders:%p\n", __FUNCTION__, store, camel_service_get_display_name ((CamelService *) store), store->priv->folders);
+
 	if (store->priv->folders) {
 		camel_object_bag_destroy (store->priv->folders);
 		store->priv->folders = NULL;
@@ -1364,6 +1367,8 @@ camel_store_get_folder_sync (CamelStore *store,
 try_again:
 	/* Try cache first. */
 	folder = store->priv->folders ? camel_object_bag_reserve (store->priv->folders, folder_name) : NULL;
+	if (!store->priv->folders)
+		printf ("%s: store:%p doesn't have set the folders object bag!!!\n", __FUNCTION__, store);
 	if (folder != NULL) {
 		if ((flags & CAMEL_STORE_FOLDER_INFO_REFRESH) != 0)
 			camel_folder_prepare_content_refresh (folder);
@@ -1529,6 +1534,16 @@ try_again:
 	if (folder && (flags & CAMEL_STORE_FOLDER_INFO_REFRESH) != 0)
 		camel_folder_prepare_content_refresh (folder);
 
+	if (folder) {
+		CamelFolder *using_folder = camel_store_get_folder_sync (store, folder_name, 0, NULL, NULL);
+		if (using_folder != folder) {
+			printf ("%s: using in structure folder:%p, but going to return:%p for '%s : %s'\n",
+				__FUNCTION__, using_folder, folder, camel_service_get_display_name ((CamelService *) store), folder_name);
+		}
+
+		g_clear_object (&using_folder);
+	}
+
 	return folder;
 }
 
diff --git a/src/camel/providers/imapx/camel-imapx-folder.c b/src/camel/providers/imapx/camel-imapx-folder.c
index ff6022f..3c8b7ba 100644
--- a/src/camel/providers/imapx/camel-imapx-folder.c
+++ b/src/camel/providers/imapx/camel-imapx-folder.c
@@ -395,6 +395,58 @@ imapx_search_by_expression (CamelFolder *folder,
 
 	camel_imapx_search_set_cancellable_and_error (imapx_search, NULL, NULL);
 
+	{
+		CamelFolderSummary *summary = camel_folder_get_folder_summary (folder);
+		guint32 saved_count = 0;
+
+		if (camel_db_count_total_message_info (camel_store_get_db (camel_folder_get_parent_store (folder)), camel_folder_get_full_name (folder), &saved_count, NULL))
+			saved_count = 0;
+
+		if (saved_count != camel_folder_summary_count (summary)) {
+			GPtrArray *uids;
+			gint ii, not_loaded_from = 0;
+
+			printf ("%s: mismatch in on-disk:%d and in known:%d folder:%p (%s) summary:%p flags:%x saved:%d found:%d for expression:---%s---\n",
+				__FUNCTION__, saved_count, camel_folder_summary_count (summary), folder, camel_folder_get_full_name (folder), summary,
+				camel_folder_summary_get_flags (summary),
+				camel_folder_summary_get_saved_count (summary),
+				matches ? (int) matches->len : -1, expression);
+
+			uids = camel_folder_summary_get_array (summary);
+			if (uids)
+				camel_folder_sort_uids (folder, uids);
+			printf ("   %s: known are %d:\n", __FUNCTION__, uids ? uids->len : -1);
+			for (ii = 0; uids && ii < uids->len; ii++) {
+				CamelMessageInfo *nfo = camel_folder_summary_peek_loaded (summary, uids->pdata[ii]);
+
+				if (nfo) {
+					if (not_loaded_from) {
+						if (not_loaded_from == ii)
+							printf ("      [%d] not loaded\n", not_loaded_from - 1);
+						else
+							printf ("      [%d..%d] not loaded\n", not_loaded_from - 1, ii - 1);
+						not_loaded_from = 0;
+					}
+
+					printf ("      [%d] uid:%s dirty:%d flagged:%d subject:'%s'\n", ii,
+						camel_message_info_get_uid (nfo),
+						camel_message_info_get_dirty (nfo),
+						camel_message_info_get_folder_flagged (nfo),
+						camel_message_info_get_subject (nfo));
+				} else if (!not_loaded_from) {
+					not_loaded_from = ii + 1;
+				}
+			}
+
+			if (not_loaded_from) {
+				if (not_loaded_from == ii)
+					printf ("      [%d] not loaded\n", not_loaded_from - 1);
+				else
+					printf ("      [%d..%d] not loaded\n", not_loaded_from - 1, ii - 1);
+			}
+		}
+	}
+
 	g_mutex_unlock (&imapx_folder->search_lock);
 
 	return matches;
