Index: camel/providers/local/camel-local-summary.c
===================================================================
--- camel/providers/local/camel-local-summary.c	(revision 10220)
+++ camel/providers/local/camel-local-summary.c	(working copy)
@@ -65,7 +65,7 @@ static int local_summary_load(CamelLocal
 static int local_summary_check(CamelLocalSummary *cls, CamelFolderChangeInfo *changeinfo, CamelException *ex);
 static int local_summary_sync(CamelLocalSummary *cls, gboolean expunge, CamelFolderChangeInfo *changeinfo, CamelException *ex);
 static CamelMessageInfo *local_summary_add(CamelLocalSummary *cls, CamelMimeMessage *msg, const CamelMessageInfo *info, CamelFolderChangeInfo *, CamelException *ex);
-static int local_summary_need_index();
+static int local_summary_need_index(void);
 
 static void camel_local_summary_class_init (CamelLocalSummaryClass *klass);
 static void camel_local_summary_init       (CamelLocalSummary *obj);
@@ -425,7 +425,7 @@ local_summary_sync(CamelLocalSummary *cl
 }
 
 static int
-local_summary_need_index() {
+local_summary_need_index(void) {
 	return 1;
 }
 
Index: camel/providers/local/camel-spool-summary.c
===================================================================
--- camel/providers/local/camel-spool-summary.c	(revision 10220)
+++ camel/providers/local/camel-spool-summary.c	(working copy)
@@ -52,7 +52,7 @@ static int spool_summary_load(CamelLocal
 static int spool_summary_check(CamelLocalSummary *cls, CamelFolderChangeInfo *changeinfo, CamelException *ex);
 
 static int spool_summary_sync_full(CamelMboxSummary *cls, gboolean expunge, CamelFolderChangeInfo *changeinfo, CamelException *ex);
-static int spool_summary_need_index();
+static int spool_summary_need_index(void);
 
 static void camel_spool_summary_class_init (CamelSpoolSummaryClass *klass);
 static void camel_spool_summary_init       (CamelSpoolSummary *obj);
@@ -346,6 +346,6 @@ spool_summary_check(CamelLocalSummary *c
 }
 
 static int
-spool_summary_need_index() {
+spool_summary_need_index(void) {
 	return 0;
 }
Index: camel/providers/local/camel-local-summary.h
===================================================================
--- camel/providers/local/camel-local-summary.h	(revision 10220)
+++ camel/providers/local/camel-local-summary.h	(working copy)
@@ -70,7 +70,7 @@ struct _CamelLocalSummaryClass {
 
 	char *(*encode_x_evolution)(CamelLocalSummary *cls, const CamelLocalMessageInfo *info);
 	int (*decode_x_evolution)(CamelLocalSummary *cls, const char *xev, CamelLocalMessageInfo *info);
-	int (*need_index)();
+	int (*need_index)(void);
 };
 
 CamelType	camel_local_summary_get_type	(void);
Index: camel/providers/local/camel-maildir-summary.c
===================================================================
--- camel/providers/local/camel-maildir-summary.c	(revision 10220)
+++ camel/providers/local/camel-maildir-summary.c	(working copy)
@@ -294,7 +294,7 @@ static CamelMessageInfo *message_info_ne
 			mdi->info.info.uid = camel_pstring_add (camel_folder_summary_next_uid_string(s), TRUE);
 
 		/* handle 'duplicates' */
-		info = camel_folder_summary_uid(s, uid);
+		info = camel_folder_summary_peek_info (s, uid);
 		if (info) {
 			d(printf("already seen uid '%s', just summarising instead\n", uid));
 			camel_message_info_free(mi);
@@ -566,7 +566,11 @@ maildir_summary_check(CamelLocalSummary 
 
 	/* keeps track of all uid's that have not been processed */
 	left = g_hash_table_new(g_str_hash, g_str_equal);
-	count = camel_folder_summary_count((CamelFolderSummary *)cls);
+	count = camel_folder_summary_count (s);
+	if (count != camel_folder_summary_cache_size (s)) {
+		camel_folder_summary_reload_from_db (s, ex);
+		count = camel_folder_summary_count (s);
+	}
 	forceindex = count == 0;
 	for (i=0;i<count;i++) {
 		info = camel_folder_summary_index((CamelFolderSummary *)cls, i);
Index: camel/providers/local/ChangeLog
===================================================================
--- camel/providers/local/ChangeLog	(revision 10220)
+++ camel/providers/local/ChangeLog	(working copy)
@@ -1,3 +1,20 @@
+2009-04-17  Milan Crha  <mcrha@redhat.com>
+
+	** Fix for bug #571206
+
+	* camel-maildir-summary.c: (message_info_new_from_header):
+	Peek info from summary.
+	* camel-maildir-summary.c: (maildir_summary_check),
+	Reload summary from db if necessary.
+	* camel-maildir-store.c: (fill_fi):
+	* camel-mh-store.c: (fill_fi):
+	Use 'camel_folder_summary_header_load_from_db'.
+
+	* camel-local-summary.h: (struct _CamelLocalSummaryClass):
+	* camel-local-summary.c: (local_summary_need_index):
+	* camel-spool-summary.c: (spool_summary_need_index):
+	Declare function prototype properly.
+
 2009-03-01  Srinivasa Ragavan  <sragavan@novell.com>
 
 	* camel/providers/local/camel-local-folder.c: Fix for a deadlock,
Index: camel/providers/local/camel-mh-store.c
===================================================================
--- camel/providers/local/camel-mh-store.c	(revision 10220)
+++ camel/providers/local/camel-mh-store.c	(working copy)
@@ -336,7 +336,7 @@ fill_fi(CamelStore *store, CamelFolderIn
 		path = g_strdup_printf("%s/%s.ev-summary", root, fi->full_name);
 		folderpath = g_strdup_printf("%s/%s", root, fi->full_name);
 		s = (CamelFolderSummary *)camel_mh_summary_new(NULL, path, folderpath, NULL);
-		if (camel_folder_summary_header_load(s) != -1) {
+		if (camel_folder_summary_header_load_from_db (s, store, fi->full_name, NULL) != -1) {
 			fi->unread = s->unread_count;
 			fi->total = s->saved_count;
 		}
Index: camel/providers/local/camel-maildir-store.c
===================================================================
--- camel/providers/local/camel-maildir-store.c	(revision 10220)
+++ camel/providers/local/camel-maildir-store.c	(working copy)
@@ -322,7 +322,7 @@ fill_fi(CamelStore *store, CamelFolderIn
 		path = g_strdup_printf("%s/%s.ev-summary", root, fi->full_name);
 		folderpath = g_strdup_printf("%s/%s", root, fi->full_name);
 		s = (CamelFolderSummary *)camel_maildir_summary_new(NULL, path, folderpath, NULL);
-		if (camel_folder_summary_header_load(s) != -1) {
+		if (camel_folder_summary_header_load_from_db (s, store, fi->full_name, NULL) != -1) {
 			fi->unread = s->unread_count;
 			fi->total = s->saved_count;
 		}
Index: camel/camel-vee-folder.c
===================================================================
--- camel/camel-vee-folder.c	(revision 10220)
+++ camel/camel-vee-folder.c	(working copy)
@@ -177,7 +177,7 @@ void
 camel_vee_folder_add_folder(CamelVeeFolder *vf, CamelFolder *sub)
 {
 	struct _CamelVeeFolderPrivate *p = _PRIVATE(vf);
-	int i, cache;
+	int i;
 	CamelVeeFolder *folder_unmatched = vf->parent_vee_store ? vf->parent_vee_store->folder_unmatched : NULL;
 	
 	if (vf == (CamelVeeFolder *)sub) {
@@ -618,7 +618,7 @@ vee_sync(CamelFolder *folder, gboolean e
 		GSList *del = NULL;
 
 		for (i=0; i < count; i++) {
-			CamelVeeMessageInfo *mi = camel_folder_summary_index (folder->summary, i);
+			CamelVeeMessageInfo *mi = (CamelVeeMessageInfo *)camel_folder_summary_index (folder->summary, i);
 			if (mi->old_flags & CAMEL_MESSAGE_DELETED) {
 				del = g_slist_prepend (del, (gpointer) camel_pstring_strdup(((CamelMessageInfo *)mi)->uid));
 				camel_folder_summary_remove_index_fast (folder->summary, i);
Index: camel/camel-vee-summary.c
===================================================================
--- camel/camel-vee-summary.c	(revision 10220)
+++ camel/camel-vee-summary.c	(working copy)
@@ -178,7 +178,11 @@ camel_vee_summary_load_check_unread_vfol
 	static char *exp = NULL;
 	char *meta;
 	gboolean hacked_unread_folder = FALSE;
-	CamelVeeFolder *vf = (CamelVeeFolder *) ((CamelFolderSummary *)vs)->folder;
+	CamelVeeFolder *vf;
+
+	g_return_if_fail (vs != NULL);
+
+	vf = (CamelVeeFolder *) ((CamelFolderSummary *)vs)->folder;
 
 	/* HACK: Ugliest of all hacks. Its virtually not possible now
 	 * to maintain counts and the non matching uids of unread vfolder here.
@@ -216,7 +220,7 @@ vee_info_set_flags(CamelMessageInfo *mi,
 		printf("Expression for vfolder '%s' is '%s'\n", mi->summary->folder->full_name, g_strescape(vf->expression, ""));
 
 	if (vf->priv->unread_vfolder == -1)
-		camel_vee_summary_load_check_unread_vfolder (mi->summary);
+		camel_vee_summary_load_check_unread_vfolder (CAMEL_VEE_SUMMARY (mi->summary));
 
 	if (vf->priv->unread_vfolder == 1)
 		hacked_unread_folder = TRUE;
Index: camel/ChangeLog
===================================================================
--- camel/ChangeLog	(revision 10220)
+++ camel/ChangeLog	(working copy)
@@ -1,3 +1,16 @@
+2009-04-17  Milan Crha  <mcrha@redhat.com>
+
+	** Part of fix for bug #571206
+
+	* camel-vee-folder.c: (camel_vee_folder_add_folder), (vee_sync):
+	* camel-vee-summary.c: (camel_vee_summary_load_check_unread_vfolder),
+	(vee_info_set_flags):
+	* camel-folder-summary.c: (camel_folder_summary_class_init):
+	Various compiler warning cleanup.
+
+	* camel-folder-summary.h: (camel_folder_summary_reload_from_db):
+	Function prototype double-declared.
+
 2009-04-15  Sergio Villar Senin  <svillar@igalia.com>
 
 	** Fix for bug #578823 – invalid condition
Index: camel/camel-folder-summary.c
===================================================================
--- camel/camel-folder-summary.c	(revision 10220)
+++ camel/camel-folder-summary.c	(working copy)
@@ -4866,7 +4866,6 @@ camel_message_info_dump (CamelMessageInf
 static void
 camel_folder_summary_class_init (CamelFolderSummaryClass *klass)
 {
-	CamelObjectClass *camel_object_class = CAMEL_OBJECT_CLASS (klass);
 	camel_folder_summary_parent = camel_type_get_global_classfuncs (camel_object_get_type ());
 
 	klass->summary_header_load = summary_header_load;
Index: camel/camel-folder-summary.h
===================================================================
--- camel/camel-folder-summary.h	(revision 10220)
+++ camel/camel-folder-summary.h	(working copy)
@@ -394,7 +394,6 @@ void camel_folder_summary_remove_range(C
 void camel_folder_summary_clear(CamelFolderSummary *summary);
 void camel_folder_summary_clear_db (CamelFolderSummary *s);
 
-int camel_folder_summary_reload_from_db (CamelFolderSummary *s, CamelException *ex);
 int camel_folder_summary_cache_size (CamelFolderSummary *s);
 
 /* lookup functions */
