commit 3aa69f3fecbfd9e4eb30b64790d8b85da2ce30c8
Author: Thomas Mittelstaedt <tmstaedt@t-mittelstaedt.de>
Date:   Wed May 18 00:23:56 2011 +0200

    Adopted a patch for evolution 2.32 to 2.28, https://bugzilla.gnome.org/attachment.cgi?id=187010

diff --git a/camel/providers/local/camel-mbox-summary.c b/camel/providers/local/camel-mbox-summary.c
index 7146067..81781f9 100644
--- a/camel/providers/local/camel-mbox-summary.c
+++ b/camel/providers/local/camel-mbox-summary.c
@@ -524,10 +524,12 @@ summary_update(CamelLocalSummary *cls, off_t offset, CamelFolderChangeInfo *chan
 	cls->index_force = FALSE;
 
 	camel_operation_start(NULL, _("Storing folder"));
+	camel_folder_summary_lock_summary (s);
 
 	fd = g_open(cls->folder_path, O_LARGEFILE | O_RDONLY | O_BINARY, 0);
 	if (fd == -1) {
 		d(printf("%s failed to open: %s\n", cls->folder_path, g_strerror (errno)));
+		camel_folder_summary_unlock_summary (s);
 		camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
 				      _("Could not open folder: %s: %s"),
 				      cls->folder_path, g_strerror (errno));
@@ -637,6 +639,7 @@ summary_update(CamelLocalSummary *cls, off_t offset, CamelFolderChangeInfo *chan
 	}
 
 	camel_operation_end(NULL);
+	camel_folder_summary_unlock_summary (s);
 
 	return ok;
 }
@@ -652,9 +655,12 @@ mbox_summary_check(CamelLocalSummary *cls, CamelFolderChangeInfo *changes, Camel
 
 	d(printf("Checking summary\n"));
 
+	camel_folder_summary_lock_summary (s);
+
 	/* check if the summary is up-to-date */
 	if (g_stat(cls->folder_path, &st) == -1) {
 		camel_folder_summary_clear(s);
+		camel_folder_summary_unlock_summary (s);
 		camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
 				      _("Cannot check folder: %s: %s"),
 				      cls->folder_path, g_strerror (errno));
@@ -705,6 +711,8 @@ mbox_summary_check(CamelLocalSummary *cls, CamelFolderChangeInfo *changes, Camel
 		}
 	}
 
+	camel_folder_summary_unlock_summary (s);
+	
 	return ret;
 }
 
@@ -713,6 +721,7 @@ static gint
 mbox_summary_sync_full(CamelMboxSummary *mbs, gboolean expunge, CamelFolderChangeInfo *changeinfo, CamelException *ex)
 {
 	CamelLocalSummary *cls = (CamelLocalSummary *)mbs;
+	CamelFolderSummary *s = (CamelFolderSummary *)mbs;
 	gint fd = -1, fdout = -1;
 	gchar *tmpname = NULL;
 	guint32 flags = (expunge?1:0);
@@ -720,9 +729,11 @@ mbox_summary_sync_full(CamelMboxSummary *mbs, gboolean expunge, CamelFolderChang
 	d(printf("performing full summary/sync\n"));
 
 	camel_operation_start(NULL, _("Storing folder"));
+	camel_folder_summary_lock_summary (s);
 
 	fd = g_open(cls->folder_path, O_LARGEFILE | O_RDONLY | O_BINARY, 0);
 	if (fd == -1) {
+		camel_folder_summary_unlock_summary (s);
 		camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
 				      _("Could not open file: %s: %s"),
 				      cls->folder_path, g_strerror (errno));
@@ -780,6 +791,7 @@ mbox_summary_sync_full(CamelMboxSummary *mbs, gboolean expunge, CamelFolderChang
 	tmpname = NULL;
 
 	camel_operation_end(NULL);
+	camel_folder_summary_unlock_summary (s);
 
 	return 0;
  error:
@@ -793,6 +805,7 @@ mbox_summary_sync_full(CamelMboxSummary *mbs, gboolean expunge, CamelFolderChang
 		g_unlink(tmpname);
 
 	camel_operation_end(NULL);
+	camel_folder_summary_unlock_summary (s);
 
 	return -1;
 }
@@ -840,9 +853,11 @@ mbox_summary_sync_quick(CamelMboxSummary *mbs, gboolean expunge, CamelFolderChan
 	d(printf("Performing quick summary sync\n"));
 
 	camel_operation_start(NULL, _("Storing folder"));
-
+	camel_folder_summary_lock_summary (s);
+	
 	fd = g_open(cls->folder_path, O_LARGEFILE|O_RDWR|O_BINARY, 0);
 	if (fd == -1) {
+		camel_folder_summary_unlock_summary (s);
 		camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
 				      _("Could not open file: %s: %s"),
 				      cls->folder_path, g_strerror (errno));
@@ -866,7 +881,6 @@ mbox_summary_sync_quick(CamelMboxSummary *mbs, gboolean expunge, CamelFolderChan
 	camel_mime_parser_scan_pre_from(mp, TRUE);
 	camel_mime_parser_init_with_fd(mp, pfd);
 
-	camel_folder_summary_lock_summary (s);
 	/* Sync only the changes */
 	summary = camel_folder_summary_get_changed ((CamelFolderSummary *)mbs);
 	if (summary->len)
@@ -995,9 +1009,13 @@ mbox_summary_sync(CamelLocalSummary *cls, gboolean expunge, CamelFolderChangeInf
 	gint ret;
 	GPtrArray *summary = NULL;
 
+	camel_folder_summary_lock_summary (s);
+	
 	/* first, sync ourselves up, just to make sure */
-	if (camel_local_summary_check(cls, changeinfo, ex) == -1)
+	if (camel_local_summary_check(cls, changeinfo, ex) == -1) {
+		camel_folder_summary_unlock_summary (s);
 		return -1;
+	}
 
 	/* Sync only the changes */
 
@@ -1019,8 +1037,10 @@ mbox_summary_sync(CamelLocalSummary *cls, gboolean expunge, CamelFolderChangeInf
 	if (quick && expunge) {
 		guint32 dcount =0;
 
-		if (camel_db_count_deleted_message_info (s->folder->parent_store->cdb_w, s->folder->full_name, &dcount, ex) == -1)
+		if (camel_db_count_deleted_message_info (s->folder->parent_store->cdb_w, s->folder->full_name, &dcount, ex) == -1) {
+			camel_folder_summary_unlock_summary (s);
 			return -1;
+		}
 		if (dcount)
 			quick = FALSE;
 	}
@@ -1041,10 +1061,13 @@ mbox_summary_sync(CamelLocalSummary *cls, gboolean expunge, CamelFolderChangeInf
 
 	if (ret == -1)
 		ret = ((CamelMboxSummaryClass *)((CamelObject *)cls)->klass)->sync_full(mbs, expunge, changeinfo, ex);
-	if (ret == -1)
+	if (ret == -1) {
+		camel_folder_summary_unlock_summary (s);
 		return -1;
+	}
 
 	if (g_stat(cls->folder_path, &st) == -1) {
+		camel_folder_summary_unlock_summary (s);
 		camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
 				      _("Unknown error: %s"), g_strerror (errno));
 		return -1;
@@ -1056,7 +1079,9 @@ mbox_summary_sync(CamelLocalSummary *cls, gboolean expunge, CamelFolderChangeInf
 		camel_folder_summary_touch(s);
 	}
 
-	return ((CamelLocalSummaryClass *)camel_mbox_summary_parent)->sync(cls, expunge, changeinfo, ex);
+	ret = ((CamelLocalSummaryClass *)camel_mbox_summary_parent)->sync(cls, expunge, changeinfo, ex);
+	camel_folder_summary_unlock_summary (s);
+	return ret;
 }
 
 gint
@@ -1079,9 +1104,12 @@ camel_mbox_summary_sync_mbox(CamelMboxSummary *cls, guint32 flags, CamelFolderCh
 
 	d(printf("performing full summary/sync\n"));
 
+	camel_folder_summary_lock_summary (s);
+
 	/* need to dup this because the mime-parser owns the fd after we give it to it */
 	fd = dup(fd);
 	if (fd == -1) {
+		camel_folder_summary_unlock_summary (s);
 		camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
 				      _("Could not store folder: %s"),
 				      g_strerror (errno));
@@ -1093,7 +1121,6 @@ camel_mbox_summary_sync_mbox(CamelMboxSummary *cls, guint32 flags, CamelFolderCh
 	camel_mime_parser_scan_pre_from(mp, TRUE);
 	camel_mime_parser_init_with_fd(mp, fd);
 
-	camel_folder_summary_lock_summary (s);
 	count = camel_folder_summary_count(s);
 	for (i = 0; i < count; i++) {
 		gint pc = (i + 1) * 100 / count;
