diff --git a/src/camel/camel-folder-summary.c b/src/camel/camel-folder-summary.c
index 694a7c3..9dea215 100644
--- a/src/camel/camel-folder-summary.c
+++ b/src/camel/camel-folder-summary.c
@@ -464,6 +464,10 @@ summary_header_load (CamelFolderSummary *summary,
 		io (printf ("loading new-format summary\n"));
 #endif
 
+	if ((summary->priv->flags & CAMEL_FOLDER_SUMMARY_DIRTY) != 0 &&
+	    !(record->flags & CAMEL_FOLDER_SUMMARY_DIRTY)) {
+		printf ("%s: summ:%p unsetting dirty flag, when in memory:%d\n", __FUNCTION__, summary, camel_folder_summary_count (summary));
+	}
 	summary->priv->flags = record->flags;
 	summary->priv->nextuid = record->nextuid;
 	summary->priv->timestamp = record->timestamp;
@@ -847,6 +851,11 @@ camel_folder_summary_set_flags (CamelFolderSummary *summary,
 {
 	g_return_if_fail (CAMEL_IS_FOLDER_SUMMARY (summary));
 
+	if (summary->priv->flags != flags && (
+	    summary->priv->flags != 0 || flags != 2)) {
+		printf ("%s: summ:%p (%s) changing flags: %x~>%x\n", __FUNCTION__, summary, G_OBJECT_TYPE_NAME (summary), summary->priv->flags, flags);
+	}
+
 	summary->priv->flags = flags;
 }
 
@@ -2111,12 +2120,27 @@ camel_folder_summary_save (CamelFolderSummary *summary,
 	g_return_val_if_fail (summary != NULL, FALSE);
 
 	if (!(summary->priv->flags & CAMEL_FOLDER_SUMMARY_DIRTY) ||
-	    is_in_memory_summary (summary))
+	    is_in_memory_summary (summary)) {
+		if (!is_in_memory_summary (summary) && summary->priv->folder &&
+		    camel_folder_summary_count (summary) > 0 &&
+		    camel_folder_get_parent_store (summary->priv->folder)) {
+			guint32 saved_count = 0;
+
+			if (camel_db_count_total_message_info (camel_store_get_db (camel_folder_get_parent_store (summary->priv->folder)), camel_folder_get_full_name (summary->priv->folder), &saved_count, NULL))
+				saved_count = 0;
+
+			if (saved_count != camel_folder_summary_count (summary)) {
+				printf ("%s: summ:%p tried to save changes, when not set dirty with on-disk:%d in-memory:%d\n", __FUNCTION__, summary, saved_count, camel_folder_summary_count (summary));
+			}
+		}
 		return TRUE;
+	}
 
 	parent_store = camel_folder_get_parent_store (summary->priv->folder);
-	if (!parent_store)
+	if (!parent_store) {
+		printf ("%s: summ:%p would save, but no parent store for folder %p; in-mem:%d\n", __FUNCTION__, summary, summary->priv->folder, camel_folder_summary_count (summary));
 		return FALSE;
+	}
 
 	cdb = camel_store_get_db (parent_store);
 
@@ -2129,12 +2153,14 @@ camel_folder_summary_save (CamelFolderSummary *summary,
 	count = cfs_count_dirty (summary);
 	if (!count) {
 		gboolean res = camel_folder_summary_header_save (summary, error);
+		printf ("%s: summ:%p no dirty found\n", __FUNCTION__, summary);
 		camel_folder_summary_unlock (summary);
 		return res;
 	}
 
 	ret = save_message_infos_to_db (summary, error);
 	if (ret != 0) {
+		printf ("%s: summ:%p failed to save %d infos\n", __FUNCTION__, summary, count);
 		/* Failed, so lets reset the flag */
 		summary->priv->flags |= CAMEL_FOLDER_SUMMARY_DIRTY;
 		camel_folder_summary_unlock (summary);
@@ -2158,6 +2184,7 @@ camel_folder_summary_save (CamelFolderSummary *summary,
 
 		ret = save_message_infos_to_db (summary, error);
 		if (ret != 0) {
+			printf ("%s: summ:%p failed to save %d infos - retry\n", __FUNCTION__, summary, count);
 			summary->priv->flags |= CAMEL_FOLDER_SUMMARY_DIRTY;
 			camel_folder_summary_unlock (summary);
 			return FALSE;
@@ -2167,6 +2194,7 @@ camel_folder_summary_save (CamelFolderSummary *summary,
 	record = CAMEL_FOLDER_SUMMARY_GET_CLASS (summary)->summary_header_save (summary, error);
 	if (!record) {
 		summary->priv->flags |= CAMEL_FOLDER_SUMMARY_DIRTY;
+		printf ("%s: summ:%p failed to save header with %d changed\n", __FUNCTION__, summary, count);
 		camel_folder_summary_unlock (summary);
 		return FALSE;
 	}
@@ -2178,6 +2206,7 @@ camel_folder_summary_save (CamelFolderSummary *summary,
 	g_free (record);
 
 	if (ret != 0) {
+		printf ("%s: summ:%p transaction to save folder info aborted\n", __FUNCTION__, summary);
 		camel_db_abort_transaction (cdb, NULL);
 		summary->priv->flags |= CAMEL_FOLDER_SUMMARY_DIRTY;
 		camel_folder_summary_unlock (summary);
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..a21a8c5 100644
--- a/src/camel/providers/imapx/camel-imapx-folder.c
+++ b/src/camel/providers/imapx/camel-imapx-folder.c
@@ -395,6 +395,69 @@ 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);
+			}
+
+			if (!camel_folder_summary_get_flags (summary)) {
+				GError *local_error = NULL;
+				gboolean succ;
+				printf ("   %s: summ:%p going to save it, try to select other folder and back\n", __FUNCTION__, summary);
+				camel_folder_summary_touch (summary);
+				succ = camel_folder_summary_save (summary, &local_error);
+				if (!succ || local_error)
+					printf ("      %s: summ:%p failed to save, succ:%d err:%s\n", __FUNCTION__, summary, succ, local_error ? local_error->message : "[no-error]");
+				g_clear_error (&local_error);
+			}
+		}
+	}
+
 	g_mutex_unlock (&imapx_folder->search_lock);
 
 	return matches;
