diff --git a/src/camel/camel-folder-search.c b/src/camel/camel-folder-search.c index e240caa..f6f908c 100644 --- a/src/camel/camel-folder-search.c +++ b/src/camel/camel-folder-search.c @@ -1046,6 +1046,7 @@ folder_search_match_threads (CamelSExp *sexp, g_free (error_msg); } + /* no thread matching, the earlier result is already complete */ if (type == 0) return r; @@ -1065,11 +1066,14 @@ folder_search_match_threads (CamelSExp *sexp, } results = g_hash_table_new (g_str_hash, g_str_equal); + /* iterate every message matching the rest of the search terms */ for (i = 0; i < r->value.ptrarray->len && !g_cancellable_is_cancelled (search->priv->cancellable); i++) { CamelFolderThreadNode *node, *scan; - if (type != 4) + if (type != 4) { + /* the matched message itself will always be part of the returned result unless in "(match-thread single)" mode */ g_hash_table_insert (results, g_ptr_array_index (r->value.ptrarray, i), GINT_TO_POINTER (1)); + } node = g_hash_table_lookup (p->threads_hash, (gchar *) g_ptr_array_index (r->value.ptrarray, i)); if (node == NULL) /* this shouldn't happen but why cry over spilt milk */ @@ -1080,14 +1084,14 @@ folder_search_match_threads (CamelSExp *sexp, if (node->child == NULL && node->parent == NULL) g_hash_table_insert (results, (gchar *) camel_message_info_get_uid (node->message), GINT_TO_POINTER (1)); } else { - if (type == 3) { + if (type == 3) { /* add the parents of the matched message */ scan = node; /* coverity[check_after_deref] */ while (scan && scan->parent) { scan = scan->parent; g_hash_table_insert (results, (gchar *) camel_message_info_get_uid (scan->message), GINT_TO_POINTER (1)); } - } else if (type == 1) { + } else if (type == 1) { /* get the thread root message, we will add all the descendants below */ while (node != NULL && node->parent) node = node->parent; }