diff --git a/camel/camel-folder-summary.c b/camel/camel-folder-summary.c
index 7513bf9..3b01493 100644
--- a/camel/camel-folder-summary.c
+++ b/camel/camel-folder-summary.c
@@ -4495,6 +4495,8 @@ camel_system_flag_get (guint32 flags, const gchar *name)
 	return flags & camel_system_flag (name);
 }
 
+gboolean maindir_in_sync = FALSE;
+
 /**
  * camel_message_info_new:
  * @summary: a #CamelFolderSummary object or %NULL
@@ -4537,6 +4539,10 @@ camel_message_info_new (CamelFolderSummary *s)
 	/* We assume that mi is always dirty unless freshly read or just saved*/
 	((CamelMessageInfoBase *)info)->dirty = TRUE;
 
+	if (maindir_in_sync) {
+		printf ("   %s: created mi %p for %p\n", __FUNCTION__, info, s);
+	}
+
 	return info;
 }
 
diff --git a/camel/providers/local/camel-maildir-summary.c b/camel/providers/local/camel-maildir-summary.c
index 0b3535e..c138a16 100644
--- a/camel/providers/local/camel-maildir-summary.c
+++ b/camel/providers/local/camel-maildir-summary.c
@@ -334,12 +334,17 @@ static CamelMessageInfo *message_info_new_from_header(CamelFolderSummary * s, st
 	return mi;
 }
 
+extern gboolean maindir_in_sync;
+
 static void
 message_info_free(CamelFolderSummary *s, CamelMessageInfo *mi)
 {
 	CamelMaildirMessageInfo *mdi = (CamelMaildirMessageInfo *)mi;
 
 	g_free(mdi->filename);
+	if (maindir_in_sync) {
+		printf ("   %s: %p freeing maildir mi (%s)\n", __FUNCTION__, mi, camel_message_info_uid (mi));
+	}
 
 	((CamelFolderSummaryClass *) parent_class)->message_info_free(s, mi);
 }
@@ -722,12 +727,25 @@ maildir_summary_sync(CamelLocalSummary *cls, gboolean expunge, CamelFolderChange
 
 	camel_operation_start(NULL, _("Storing folder"));
 
+	maindir_in_sync = TRUE;
+	printf ("%s: starts for %p (%s)\n", __FUNCTION__, cls, cls->folder_path);
+
 	count = camel_folder_summary_count((CamelFolderSummary *)cls);
 	for (i=count-1;i>=0;i--) {
 		camel_operation_progress(NULL, (count-i)*100/count);
 
 		info = camel_folder_summary_index((CamelFolderSummary *)cls, i);
 		mdi = (CamelMaildirMessageInfo *)info;
+
+		if (!info) {
+			printf ("      %s: no info at %d for %s\n", __FUNCTION__, i, cls->folder_path);
+			continue;
+		}
+
+		if (!camel_maildir_info_filename (mdi)) {
+			printf ("      %s: %p without filename set (%s) for %p (%s)\n", __FUNCTION__, info, camel_message_info_uid (info), cls, cls->folder_path);
+		}
+
 		if (mdi && (mdi->info.info.flags & CAMEL_MESSAGE_DELETED) && expunge) {
 			name = g_strdup_printf("%s/cur/%s", cls->folder_path, camel_maildir_info_filename(mdi));
 			d(printf("deleting %s\n", name));
@@ -775,6 +793,8 @@ maildir_summary_sync(CamelLocalSummary *cls, gboolean expunge, CamelFolderChange
 		camel_message_info_free(info);
 	}
 
+	printf ("%s: ends for %p (%s)\n", __FUNCTION__, cls, cls->folder_path);
+	maindir_in_sync = FALSE;
 	camel_operation_end(NULL);
 
 	return ((CamelLocalSummaryClass *)parent_class)->sync(cls, expunge, changes, ex);
