diff --git a/camel/providers/local/camel-maildir-summary.c b/camel/providers/local/camel-maildir-summary.c
index 8cc0c9e..22eb6dc 100644
--- a/camel/providers/local/camel-maildir-summary.c
+++ b/camel/providers/local/camel-maildir-summary.c
@@ -335,12 +335,17 @@ static CamelMessageInfo *message_info_new_from_header(CamelFolderSummary * s, st
 	return mi;
 }
 
+static gboolean in_sync = FALSE;
+
 static void
 message_info_free(CamelFolderSummary *s, CamelMessageInfo *mi)
 {
 	CamelMaildirMessageInfo *mdi = (CamelMaildirMessageInfo *)mi;
 
 	g_free(mdi->filename);
+	if (in_sync) {
+		printf ("%s: %p freeing maildir mi\n", __FUNCTION__, mi);
+	}
 
 	((CamelFolderSummaryClass *) parent_class)->message_info_free(s, mi);
 }
@@ -723,12 +728,22 @@ maildir_summary_sync(CamelLocalSummary *cls, gboolean expunge, CamelFolderChange
 
 	camel_operation_start(NULL, _("Storing folder"));
 
+	in_sync = TRUE;
+
 	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)
+			continue;
+
+		if (!camel_maildir_info_filename (mdi)) {
+			printf ("%s: %p without filename set\n", __FUNCTION__, info);
+		}
+
 		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));
@@ -776,6 +791,7 @@ maildir_summary_sync(CamelLocalSummary *cls, gboolean expunge, CamelFolderChange
 		camel_message_info_free(info);
 	}
 
+	in_sync = FALSE;
 	camel_operation_end(NULL);
 
 	return ((CamelLocalSummaryClass *)parent_class)->sync(cls, expunge, changes, ex);
