Index: camel/camel-vee-folder.c
===================================================================
--- camel/camel-vee-folder.c	(revision 9778)
+++ camel/camel-vee-folder.c	(working copy)
@@ -460,30 +460,6 @@
 	}
 }
 
-static void vee_refresh_info(CamelFolder *folder, CamelException *ex)
-{
-	CamelVeeFolder *vf = (CamelVeeFolder *)folder;
-	struct _CamelVeeFolderPrivate *p = _PRIVATE(vf);
-	GList *node, *list;
-
-	CAMEL_VEE_FOLDER_LOCK(vf, changed_lock);
-	list = p->folders_changed;
-	p->folders_changed = NULL;
-	CAMEL_VEE_FOLDER_UNLOCK(vf, changed_lock);
-
-	node = list;
-	while (node) {
-		CamelFolder *f = node->data;
-
-		if (camel_vee_folder_rebuild_folder(vf, f, ex) == -1)
-			break;
-
-		node = node->next;
-	}
-
-	g_list_free(list);
-}
-
 static guint32
 count_folder (CamelFolder *f, char *expr, CamelException *ex)
 {
@@ -510,6 +486,43 @@
 	return count;
 }
 
+static void redo_counts(CamelFolderSummary *s, CamelException *ex)
+{
+	s->junk_count = count_result (s, "(match-all (system-flag  \"junk\"))", ex);
+	s->deleted_count = count_result (s, "(match-all (system-flag  \"deleted\"))", ex);
+	s->unread_count = count_result (s, "(match-all (not (system-flag  \"Seen\")))", ex);
+	s->visible_count = count_result (s, "(match-all (and (not (system-flag \"deleted\")) (not (system-flag \"junk\"))))", ex);
+	s->junk_not_deleted_count = count_result (s, "(match-all (and (not (system-flag \"deleted\")) (system-flag \"junk\")))", ex);
+}
+
+static void vee_refresh_info(CamelFolder *folder, CamelException *ex)
+{
+	CamelVeeFolder *vf = (CamelVeeFolder *)folder;
+	struct _CamelVeeFolderPrivate *p = _PRIVATE(vf);
+	GList *node, *list;
+
+	CAMEL_VEE_FOLDER_LOCK(vf, changed_lock);
+	list = p->folders_changed;
+	p->folders_changed = NULL;
+	CAMEL_VEE_FOLDER_UNLOCK(vf, changed_lock);
+
+	node = list;
+	while (node) {
+		CamelFolder *f = node->data;
+
+		if (camel_vee_folder_rebuild_folder(vf, f, ex) == -1)
+			break;
+
+		node = node->next;
+	}
+
+	/* Redo the counts if requested by folder_changed_change. */
+	if (((CamelVeeSummary *) folder->summary)->force_counts)
+		redo_counts(folder->summary, ex);
+
+	g_list_free(list);
+}
+
 static	CamelFIRecord *
 summary_header_to_db (CamelFolderSummary *s, CamelException *ex)
 {
@@ -545,11 +558,7 @@
 		record->jnd_count = s->junk_not_deleted_count;
 	} else {
 		/* Either first time, or by force we search the count */
-		s->junk_count = count_result (s, "(match-all (system-flag  \"junk\"))", ex);
-		s->deleted_count = count_result (s, "(match-all (system-flag  \"deleted\"))", ex);
-		s->unread_count = count_result (s, "(match-all (not (system-flag  \"Seen\")))", ex);
-		s->visible_count = count_result (s, "(match-all (and (not (system-flag \"deleted\")) (not (system-flag \"junk\"))))", ex);
-		s->junk_not_deleted_count = count_result (s, "(match-all (and (not (system-flag \"deleted\")) (system-flag \"junk\")))", ex);
+		redo_counts(s, ex);
 
 		record->junk_count = s->junk_count;
 		record->deleted_count = s->deleted_count;
@@ -1539,7 +1548,41 @@
 
 	camel_vee_folder_hash_folder(sub, hash);
 
+	if (strstr(vf->expression, "match-threads")) {
+		/* The incremental-updating code below doesn't handle cases
+		 * where a newly matching message pulls in the rest of its
+		 * thread.  Thus, we completely forget the old results from
+		 * this source folder and let vee_rebuild_folder redo the
+		 * search from scratch. */
 
+		CAMEL_VEE_FOLDER_LOCK(vf, changed_lock);
+		if (g_list_find(vf->priv->folders_changed, sub) != NULL) {
+			/* The source folder is already marked as changed;
+			 * nothing to do. */
+			CAMEL_VEE_FOLDER_UNLOCK(vf, changed_lock);
+			CAMEL_VEE_FOLDER_UNLOCK(vf, subfolder_lock);
+			return;
+		}
+
+		/* Mark the source folder as changed so the next
+		 * vee_refresh_info will call vee_rebuild_folder. */
+		vf->priv->folders_changed = g_list_prepend(vf->priv->folders_changed, sub);
+		CAMEL_VEE_FOLDER_UNLOCK(vf, changed_lock);
+
+		/* Delete the source folder's vuid contribution from the DB so
+		 * that vee_rebuild_folder will re-execute the search. */
+		camel_vee_summary_delete_ids((CamelVeeSummary *) folder->summary, hash);
+
+		/* Since we're not updating incrementally and don't have access
+		 * to the old state of the source folder, we have no way to
+		 * decrease the counts by the proper amount.  Instead, tell
+		 * vee_refresh_info to redo the counts. */
+		((CamelVeeSummary *) folder->summary)->force_counts = TRUE;
+
+		CAMEL_VEE_FOLDER_UNLOCK(vf, subfolder_lock);
+		return;
+	}
+
 	/* Lookup anything before we lock anything, to avoid deadlock with build_folder */
 
 	/* Find newly added that match */
Index: camel/camel-db.c
===================================================================
--- camel/camel-db.c	(revision 9778)
+++ camel/camel-db.c	(working copy)
@@ -682,7 +682,24 @@
 	 return array;
 }
 
+/* MATT - Based on camel_db_delete_uid_from_vfolder, camel_db_get_vuids_from_vfolder */
 int
+camel_db_delete_vuids_from_vfolder (CamelDB *db, char *folder_name, char *filter, CamelException *ex)
+{
+	 char *del_query;
+	 char *tmp = g_strdup_printf("%s%%", filter ? filter:"");
+	 int ret;
+	 del_query = sqlite3_mprintf ("DELETE FROM %Q WHERE vuid LIKE %Q", folder_name, tmp);
+	 g_free(tmp);
+
+	 ret = camel_db_command (db, del_query, ex);
+	 
+	 sqlite3_free (del_query);
+	 CAMEL_DB_RELEASE_SQLITE_MEMORY;
+	 return ret;
+}
+
+int
 camel_db_add_to_vfolder (CamelDB *db, char *folder_name, char *vuid, CamelException *ex)
 {
 	 char *ins_query;
Index: camel/camel-db.h
===================================================================
--- camel/camel-db.h	(revision 9778)
+++ camel/camel-db.h	(working copy)
@@ -152,6 +152,7 @@
 int camel_db_delete_uid_from_vfolder (CamelDB *db, char *folder_name, char *vuid, CamelException *ex);
 int camel_db_delete_uid_from_vfolder_transaction (CamelDB *db, char *folder_name, char *vuid, CamelException *ex);
 GPtrArray * camel_db_get_vuids_from_vfolder (CamelDB *db, char *folder_name, char *filter, CamelException *ex);
+int camel_db_delete_vuids_from_vfolder (CamelDB *db, char *folder_name, char *filter, CamelException *ex);
 int camel_db_add_to_vfolder (CamelDB *db, char *folder_name, char *vuid, CamelException *ex);
 int camel_db_add_to_vfolder_transaction (CamelDB *db, char *folder_name, char *vuid, CamelException *ex);
 
Index: camel/camel-vee-summary.c
===================================================================
--- camel/camel-vee-summary.c	(revision 9778)
+++ camel/camel-vee-summary.c	(working copy)
@@ -413,6 +413,21 @@
 	return array;
 }
 
+/* MATT - Based on camel_vee_summary_get_ids */
+int
+camel_vee_summary_delete_ids (CamelVeeSummary *summary, char hash[8])
+{
+	char *shash = g_strdup_printf("%c%c%c%c%c%c%c%c", hash[0], hash[1], hash[2], hash[3], hash[4], hash[5], hash[6], hash[7]);
+	CamelFolderSummary *cfs = (CamelFolderSummary *)summary;
+	int ret;
+
+	/* FIXME[disk-summary] fix exception passing */
+	ret = camel_db_delete_vuids_from_vfolder(cfs->folder->parent_store->cdb_w, cfs->folder->full_name, shash, NULL);
+	g_free(shash);
+
+	return ret;
+}
+
 CamelVeeMessageInfo *
 camel_vee_summary_add(CamelVeeSummary *s, CamelFolderSummary *summary, const char *uid, const char hash[8])
 {
Index: camel/camel-vee-summary.h
===================================================================
--- camel/camel-vee-summary.h	(revision 9778)
+++ camel/camel-vee-summary.h	(working copy)
@@ -62,6 +62,7 @@
 
 CamelVeeMessageInfo * camel_vee_summary_add(CamelVeeSummary *s, CamelFolderSummary *summary, const char *uid, const char hash[8]);
 GPtrArray * camel_vee_summary_get_ids (CamelVeeSummary *summary, char hash[8]);
+int camel_vee_summary_delete_ids (CamelVeeSummary *summary, char hash[8]);
 
 G_END_DECLS
 
