diff --git a/camel/camel-folder-summary.c b/camel/camel-folder-summary.c
index 7ccc7d5..7a9c3d5 100644
--- a/camel/camel-folder-summary.c
+++ b/camel/camel-folder-summary.c
@@ -2074,25 +2074,24 @@ camel_folder_summary_touch(CamelFolderSummary *s)
 void
 camel_folder_summary_clear(CamelFolderSummary *s)
 {
-#if 0
-	int i;
+	d(printf ("\ncamel_folder_summary_clearcalled \n"));
+	s->flags &= ~CAMEL_SUMMARY_DIRTY;
 
 	CAMEL_SUMMARY_LOCK(s, summary_lock);
 	if (camel_folder_summary_count(s) == 0) {
 		CAMEL_SUMMARY_UNLOCK(s, summary_lock);
 		return;
 	}
+	
+	g_ptr_array_foreach (s->uids, (GFunc) camel_pstring_free, NULL);
+	g_ptr_array_free (s->uids, TRUE);
+	s->uids = g_ptr_array_new ();
+	s->visible_count = s->deleted_count = s->unread_count = 0;
 
-	for (i=0;i<s->messages->len;i++)
-		camel_message_info_free(s->messages->pdata[i]);
+	g_hash_table_destroy(s->loaded_infos);
+	s->loaded_infos = g_hash_table_new(g_str_hash, g_str_equal);
 
-	g_ptr_array_set_size(s->messages, 0);
-	g_hash_table_destroy(s->messages_uid);
-	s->messages_uid = g_hash_table_new(g_str_hash, g_str_equal);
-	s->flags |= CAMEL_SUMMARY_DIRTY;
-	s->meta_summary->msg_expunged = TRUE;
 	CAMEL_SUMMARY_UNLOCK(s, summary_lock);
-#endif	
 }
 
 /* FIXME: This is non-sense. Neither an exception is passed,
diff --git a/camel/camel-vee-folder.c b/camel/camel-vee-folder.c
index 41c16d7..b26bbe2 100644
--- a/camel/camel-vee-folder.c
+++ b/camel/camel-vee-folder.c
@@ -2064,8 +2064,16 @@ vee_set_expression(CamelVeeFolder *vf, const char *query)
 	}
 
 	/* Recreate the table when the query changes, only if we are not setting it first */
-	if (vf->expression)
+	if (vf->expression) {
+		CamelFolderSummary *s = ((CamelFolder *)vf)->summary;
+		camel_folder_summary_clear (s);
 		camel_db_recreate_vfolder (((CamelFolder *) vf)->parent_store->cdb_w, ((CamelFolder *) vf)->full_name, NULL);
+		s->junk_count = 0;
+		s->deleted_count = 0; 
+		s->unread_count = 0;
+		s->visible_count = 0;
+		s->junk_not_deleted_count = 0;
+	}
 
 
 	g_free(vf->expression);
