Hi everyone,
The TODO list mentions a features I really wanted, which is making a way to display an entire thread, including archived messages. I'm not sure what the best way to wire this up is, but here is some sample code that replaces the current search with something that returns the entire thread.
sup worked this way, but it was very difficult to use with big threads because it was almost impossible to find individual messages that you cared about. mutt has all the normal limiting/searching commands, so having a huge thread returned isn't a big deal.
This patch is about 10 minutes old, treat it gently. It needs a conditional to switch between whole-thread matching and strict message matching, but I'll let people that know mutt internals better suggest how to do that.
diff --git a/mutt_notmuch.c b/mutt_notmuch.c --- a/mutt_notmuch.c +++ b/mutt_notmuch.c @@ -699,9 +702,95 @@ done: FREE(&newpath); }
+/* + * add all the replies to a given messages into the display. + * Careful, this calls itself recursively to make sure we get + * everything. + */ +static void append_replies(CONTEXT *ctx, notmuch_message_t *top) +{ + notmuch_messages_t *msgs; + for (msgs = notmuch_message_get_replies(top); + notmuch_messages_valid(msgs); + notmuch_messages_move_to_next(msgs)) { + notmuch_message_t *m = notmuch_messages_get(msgs); + append_message(ctx, m); + /* recurse through all the replies to this message too */ + append_replies(ctx, m); + notmuch_message_destroy(m); + } +} + +/* + * add each top level reply in the thread, and then add each + * reply to the top level replies + */ +static void append_thread(CONTEXT *ctx, notmuch_thread_t *thread) +{ + notmuch_messages_t *msgs; + for (msgs = notmuch_thread_get_toplevel_messages(thread); + notmuch_messages_valid(msgs); + notmuch_messages_move_to_next(msgs)) { + notmuch_message_t *m = notmuch_messages_get(msgs); + append_message(ctx, m); + append_replies(ctx, m); + notmuch_message_destroy(m); + } +} + +/* + * The default read_query function, this one finds all the + * matching threads and then iterates through them + */ int nm_read_query(CONTEXT *ctx) { notmuch_query_t *q; + notmuch_threads_t *threads; + struct nm_ctxdata *data; + int limit, rc = -1; + + if (init_context(ctx) != 0) + return -1; + + data = get_ctxdata(ctx); + if (!data) + return -1; + + dprint(1, (debugfile, "nm: reading messages...\n")); + + q = get_query(data, FALSE); + if (q) { + limit = get_limit(data); + + for (threads = notmuch_query_search_threads(q); + notmuch_threads_valid(threads) && + (limit == 0 || ctx->msgcount < limit); + notmuch_threads_move_to_next(threads)) { + + notmuch_thread_t *thread = notmuch_threads_get(threads); + append_thread(ctx, thread); + notmuch_thread_destroy(thread); + } + + notmuch_query_destroy(q); + rc = 0; + } + + if (!is_longrun(data)) + release_db(data); + + ctx->mtime = time(NULL); + + mx_update_context(ctx, ctx->msgcount); + + dprint(1, (debugfile, "nm: reading messages... done [rc=%d, count=%d]\n", + rc, ctx->msgcount)); + return rc; +} + +int nm_read_query_messages(CONTEXT *ctx) +{ + notmuch_query_t *q; notmuch_messages_t *msgs; struct nm_ctxdata *data; int limit, rc = -1;
On Wed, Jun 13, 2012 at 01:27:39PM -0400, Chris Mason wrote:
This patch is about 10 minutes old, treat it gently. It needs a
Thanks! I love patches :-)
conditional to switch between whole-thread matching and strict message matching, but I'll let people that know mutt internals better suggest how to do that.
It seems good idea to distinguish between whole-threads and messages for notmuch queries. I have added (based on your patch) support for a new keyword type=<threads|messages> for notmuch URLs.
It means that you can in your .muttrc use something like:
virtual-mailboxes \ "INBOX" "notmuch://?type=threads&query=tag:inbox and NOT tag:archive" ^^^^^^^^^^^^ to get whole-threads for the query.
It also works with <vfolder-from-query> command (default <Esc>X key), where you can in mutt dialog type:
Query: something &type=threads
(so append "&type=.." to the query).
Note that nm_check_database() still reads messages only. I'm going to fix it on Monday.
Karel
mutt-kz@lists.fedoraproject.org