* notmuch search for threads vs matched messages
@ 2023-05-02 15:44 Al Haji-Ali
2023-05-02 17:38 ` Teemu Likonen
2023-05-03 6:27 ` NeilBrown
0 siblings, 2 replies; 4+ messages in thread
From: Al Haji-Ali @ 2023-05-02 15:44 UTC (permalink / raw)
To: notmuch
When I search for emails (in the CLI or Emacs), for example all those with the inbox tag, I get a list of threads with the names of all senders in the thread and all tags that are in the thread rather than in the matched messages.
I find this unhelpful since it hides the important information. For example, in an email thread with many tags/senders, I would want to know at a glance in the notmuch-search buffer who sent the matched message and what are its tags rather than all old senders and tags that could have little to do with the matched message. This is especially awkward in Emacs when `notmuch-show-only-matching-messages` is set to t.
I suppose there is no current easy way to only return the information about matched messages.
Do you think such a feature is worth implementing? Would there be something fundamentally difficult about implementing it?
Thanks,
-- Al
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: notmuch search for threads vs matched messages
2023-05-02 15:44 notmuch search for threads vs matched messages Al Haji-Ali
@ 2023-05-02 17:38 ` Teemu Likonen
2023-05-03 6:27 ` NeilBrown
1 sibling, 0 replies; 4+ messages in thread
From: Teemu Likonen @ 2023-05-02 17:38 UTC (permalink / raw)
To: Al Haji-Ali, notmuch
[-- Attachment #1.1: Type: text/plain, Size: 774 bytes --]
* 2023-05-02 16:44:22+0100, Al Haji-Ali wrote:
> When I search for emails (in the CLI or Emacs), for example all those
> with the inbox tag, I get a list of threads with the names of all
> senders in the thread and all tags that are in the thread rather than
> in the matched messages.
In Emacs you can search with "u" command in the *notmuch-hello* buffer.
It returns only the matched messages. There is also "z" command which
returns a tree but shows which messages matched the search pattern.
In command line interpreter and "notmuch-search" command you can use the
"--output" option:
--output=(summary|threads|messages|files|tags)
--
/// Teemu Likonen - .-.. https://www.iki.fi/tlikonen/
// OpenPGP: 6965F03973F0D4CA22B9410F0F2CAE0E07608462
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 251 bytes --]
[-- Attachment #2: Type: text/plain, Size: 0 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: notmuch search for threads vs matched messages
2023-05-02 15:44 notmuch search for threads vs matched messages Al Haji-Ali
2023-05-02 17:38 ` Teemu Likonen
@ 2023-05-03 6:27 ` NeilBrown
2023-05-03 16:24 ` Al Haji-Ali
1 sibling, 1 reply; 4+ messages in thread
From: NeilBrown @ 2023-05-03 6:27 UTC (permalink / raw)
To: Al Haji-Ali; +Cc: notmuch
On Wed, 03 May 2023, Al Haji-Ali wrote:
> When I search for emails (in the CLI or Emacs), for example all those with the inbox tag, I get a list of threads with the names of all senders in the thread and all tags that are in the thread rather than in the matched messages.
>
> I find this unhelpful since it hides the important information. For example, in an email thread with many tags/senders, I would want to know at a glance in the notmuch-search buffer who sent the matched message and what are its tags rather than all old senders and tags that could have little to do with the matched message. This is especially awkward in Emacs when `notmuch-show-only-matching-messages` is set to t.
>
> I suppose there is no current easy way to only return the information about matched messages.
> Do you think such a feature is worth implementing? Would there be something fundamentally difficult about implementing it?
I would find this helpful too.
If there is a message in the thread which does not have tag:inbox but
does have tag:unread, then the whole thread gets the tag:unread flag,
which isn't appropriate if all matching don't have tak:unread.
Unfortunately I have no idea about implementing - I just wanted to
encourage anyone who did that it would be valuable.
Thanks,
NeilBrown
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: notmuch search for threads vs matched messages
2023-05-03 6:27 ` NeilBrown
@ 2023-05-03 16:24 ` Al Haji-Ali
0 siblings, 0 replies; 4+ messages in thread
From: Al Haji-Ali @ 2023-05-03 16:24 UTC (permalink / raw)
To: NeilBrown, David Bremner; +Cc: notmuch
[-- Attachment #1: Type: text/plain, Size: 364 bytes --]
> 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
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: notmuch-tags.patch --]
[-- Type: text/x-patch, Size: 3405 bytes --]
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);
[-- Attachment #3: Type: text/plain, Size: 0 bytes --]
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-05-03 16:30 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-02 15:44 notmuch search for threads vs matched messages Al Haji-Ali
2023-05-02 17:38 ` Teemu Likonen
2023-05-03 6:27 ` NeilBrown
2023-05-03 16:24 ` Al Haji-Ali
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).