> I would find this helpful too.
I just implemented this for tags (patch attached). Turns out it is not needed
for authors as notmuch already distinguishes between matched and unmatched
authors -- I never noticed!.
The implementation could of course be debated and improved, but I just wanted
to confirm if it is possible to do in theory.
Best regards,
-- Al
diff --git a/lib/notmuch.h b/lib/notmuch.h
index 76156178..af0df252 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -1498,7 +1498,7 @@ notmuch_thread_get_newest_date (notmuch_thread_t *thread);
* it if the message is about to be destroyed).
*/
notmuch_tags_t *
-notmuch_thread_get_tags (notmuch_thread_t *thread);
+notmuch_thread_get_tags (notmuch_thread_t *thread, notmuch_bool_t matched);
/**
* Destroy a notmuch_thread_t object.
diff --git a/lib/thread.cc b/lib/thread.cc
index 60e9a666..949a91e3 100644
--- a/lib/thread.cc
+++ b/lib/thread.cc
@@ -41,6 +41,7 @@ struct _notmuch_thread {
GPtrArray *matched_authors_array;
char *authors;
GHashTable *tags;
+ GHashTable *matched_tags;
/* All messages, oldest first. */
notmuch_message_list_t *message_list;
@@ -61,6 +62,7 @@ _notmuch_thread_destructor (notmuch_thread_t *thread)
g_hash_table_unref (thread->authors_hash);
g_hash_table_unref (thread->matched_authors_hash);
g_hash_table_unref (thread->tags);
+ g_hash_table_unref (thread->matched_tags);
g_hash_table_unref (thread->message_hash);
if (thread->authors_array) {
@@ -362,6 +364,8 @@ _thread_add_matched_message (notmuch_thread_t *thread,
time_t date;
notmuch_message_t *hashed_message;
notmuch_bool_t is_set;
+ notmuch_tags_t *tags;
+ const char *tag;
date = notmuch_message_get_date (message);
@@ -390,6 +394,13 @@ _thread_add_matched_message (notmuch_thread_t *thread,
NOTMUCH_MESSAGE_FLAG_MATCH, 1);
}
+ for (tags = notmuch_message_get_tags (message);
+ notmuch_tags_valid (tags);
+ notmuch_tags_move_to_next (tags)) {
+ tag = notmuch_tags_get (tags);
+ g_hash_table_insert (thread->matched_tags, xstrdup (tag), NULL);
+ }
+
_thread_add_matched_author (thread, _notmuch_message_get_author (hashed_message));
return 0;
}
@@ -590,6 +601,8 @@ _notmuch_thread_create (void *ctx,
thread->authors = NULL;
thread->tags = g_hash_table_new_full (g_str_hash, g_str_equal,
free, NULL);
+ thread->matched_tags = g_hash_table_new_full (g_str_hash, g_str_equal,
+ free, NULL);
thread->message_list = _notmuch_message_list_create (thread);
thread->toplevel_list = _notmuch_message_list_create (thread);
@@ -714,7 +727,7 @@ notmuch_thread_get_newest_date (notmuch_thread_t *thread)
}
notmuch_tags_t *
-notmuch_thread_get_tags (notmuch_thread_t *thread)
+notmuch_thread_get_tags (notmuch_thread_t *thread, notmuch_bool_t matched)
{
notmuch_string_list_t *tags;
GList *keys, *l;
@@ -723,7 +736,7 @@ notmuch_thread_get_tags (notmuch_thread_t *thread)
if (unlikely (tags == NULL))
return NULL;
- keys = g_hash_table_get_keys (thread->tags);
+ keys = g_hash_table_get_keys (matched ? thread->matched_tags : thread->tags);
for (l = keys; l; l = l->next)
_notmuch_string_list_append (tags, (char *) l->data);
diff --git a/notmuch-search.c b/notmuch-search.c
index 327e1445..58a4ea79 100644
--- a/notmuch-search.c
+++ b/notmuch-search.c
@@ -239,7 +239,7 @@ do_search_threads (search_context_t *ctx)
format->map_key (format, "tags");
format->begin_list (format);
- for (tags = notmuch_thread_get_tags (thread);
+ for (tags = notmuch_thread_get_tags (thread, 1);
notmuch_tags_valid (tags);
notmuch_tags_move_to_next (tags)) {
const char *tag = notmuch_tags_get (tags);
_______________________________________________
notmuch mailing list -- [email protected]
To unsubscribe send an email to [email protected]