Index: camel/providers/local/camel-local-summary.h
===================================================================
--- camel/providers/local/camel-local-summary.h	(revision 10121)
+++ camel/providers/local/camel-local-summary.h	(working copy)
@@ -70,7 +70,7 @@
 
 	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 10121)
+++ camel/providers/local/camel-maildir-summary.c	(working copy)
@@ -294,7 +294,7 @@
 			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 @@
 
 	/* 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/camel-mh-store.c
===================================================================
--- camel/providers/local/camel-mh-store.c	(revision 10121)
+++ camel/providers/local/camel-mh-store.c	(working copy)
@@ -336,7 +336,7 @@
 		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 10121)
+++ camel/providers/local/camel-maildir-store.c	(working copy)
@@ -322,7 +322,7 @@
 		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 10121)
+++ camel/camel-vee-folder.c	(working copy)
@@ -177,7 +177,7 @@
 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 @@
 		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 10121)
+++ camel/camel-vee-summary.c	(working copy)
@@ -178,8 +178,12 @@
 	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.
 	 * So, I hardcode unread vfolder expression and hack it. */
@@ -216,7 +220,7 @@
 		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/camel-folder-summary.c
===================================================================
--- camel/camel-folder-summary.c	(revision 10121)
+++ camel/camel-folder-summary.c	(working copy)
@@ -4831,7 +4831,6 @@
 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 10121)
+++ camel/camel-folder-summary.h	(working copy)
@@ -394,7 +394,6 @@
 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 */
