1 Return-Path: <bart@jukie.net>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id C9087431FC2
\r
6 for <notmuch@notmuchmail.org>; Tue, 24 Nov 2009 18:04:27 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
8 Received: from olra.theworths.org ([127.0.0.1])
\r
9 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
10 with ESMTP id vAaZmgqEaqpA for <notmuch@notmuchmail.org>;
\r
11 Tue, 24 Nov 2009 18:04:27 -0800 (PST)
\r
12 Received: from tau.jukie.net (tau.jukie.net [216.239.93.128])
\r
13 by olra.theworths.org (Postfix) with ESMTP id AE219431FC0
\r
14 for <notmuch@notmuchmail.org>; Tue, 24 Nov 2009 18:04:26 -0800 (PST)
\r
15 Received: from localhost.localdomain (oxygen.jukie.net [10.10.10.8])
\r
16 by tau.jukie.net (Postfix) with ESMTP id 3A63AC00F84;
\r
17 Tue, 24 Nov 2009 21:04:26 -0500 (EST)
\r
18 From: Bart Trojanowski <bart@jukie.net>
\r
19 To: notmuch@notmuchmail.org
\r
20 Date: Tue, 24 Nov 2009 21:03:29 -0500
\r
21 Message-Id: <1259114609-15959-2-git-send-email-bart@jukie.net>
\r
22 X-Mailer: git-send-email 1.6.4.4.2.gc2f148
\r
23 In-Reply-To: <1259114609-15959-1-git-send-email-bart@jukie.net>
\r
24 References: <1259114609-15959-1-git-send-email-bart@jukie.net>
\r
25 Cc: Bart Trojanowski <bart@jukie.net>
\r
26 Subject: [notmuch] [PATCH] notmuch-show: add option to limit display to only
\r
28 X-BeenThere: notmuch@notmuchmail.org
\r
29 X-Mailman-Version: 2.1.12
\r
31 List-Id: "Use and development of the notmuch mail system."
\r
32 <notmuch.notmuchmail.org>
\r
33 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
34 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
35 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
36 List-Post: <mailto:notmuch@notmuchmail.org>
\r
37 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
38 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
39 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
40 X-List-Received-Date: Wed, 25 Nov 2009 02:04:28 -0000
\r
42 This patch adds support for notmuch show --only-matching-messages
\r
43 which limits the output to only the top level messages matching
\r
44 the search terms provides.
\r
48 $ notmuch search subject:git AND thread:23d99d0f364f93e90e15df8b42eddb5b
\r
49 thread:23d99d0f364f93e90e15df8b42eddb5b July 31 [4/12] Johan Herland; [RFCv2 00/12] Foreign VCS helper program for CVS repositories (inbox unread)
\r
51 Note that in this thread 4 out of 12 messages matched. The default show
\r
52 behaviour is to show all messages in the thread:
\r
54 $ notmuch show subject:git AND thread:23d99d0f364f93e90e15df8b42eddb5b | grep 'message{' | wc -l
\r
57 With the --only-matching-messages option the output is limited to the
\r
58 matching messages only:
\r
60 $ notmuch show --only-matching-messages subject:git AND thread:23d99d0f364f93e90e15df8b42eddb5b | grep 'message{' | wc -l
\r
63 Signed-off-by: Bart Trojanowski <bart@jukie.net>
\r
65 notmuch-show.c | 48 +++++++++++++++++++++++++++++++++++++-----------
\r
66 notmuch.c | 7 +++++++
\r
67 2 files changed, 44 insertions(+), 11 deletions(-)
\r
69 diff --git a/notmuch-show.c b/notmuch-show.c
\r
70 index edebaca..8599c6c 100644
\r
71 --- a/notmuch-show.c
\r
72 +++ b/notmuch-show.c
\r
73 @@ -211,6 +211,24 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
\r
74 notmuch_thread_t *thread;
\r
75 notmuch_messages_t *messages;
\r
77 + int only_matching = 0;
\r
80 + for (i = 0; i < argc && argv[i][0] == '-'; i++) {
\r
81 + if (strcmp (argv[i], "--") == 0) {
\r
85 + if (strcmp(argv[i], "--only-matching-messages") == 0) {
\r
86 + only_matching = 1;
\r
88 + fprintf (stderr, "Unrecognized option: %s\n", argv[i]);
\r
96 config = notmuch_config_open (ctx, NULL, NULL);
\r
98 @@ -238,21 +256,29 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
\r
102 - for (threads = notmuch_query_search_threads (query);
\r
103 - notmuch_threads_has_more (threads);
\r
104 - notmuch_threads_advance (threads))
\r
106 - thread = notmuch_threads_get (threads);
\r
107 + if (only_matching) {
\r
108 + messages = notmuch_query_search_messages (query);
\r
109 + if (messages == NULL)
\r
110 + INTERNAL_ERROR ("No messages.\n");
\r
111 + show_messages (ctx, messages, 0);
\r
113 - messages = notmuch_thread_get_toplevel_messages (thread);
\r
115 + for (threads = notmuch_query_search_threads (query);
\r
116 + notmuch_threads_has_more (threads);
\r
117 + notmuch_threads_advance (threads))
\r
119 + thread = notmuch_threads_get (threads);
\r
121 - if (messages == NULL)
\r
122 - INTERNAL_ERROR ("Thread %s has no toplevel messages.\n",
\r
123 - notmuch_thread_get_thread_id (thread));
\r
124 + messages = notmuch_thread_get_toplevel_messages (thread);
\r
126 - show_messages (ctx, messages, 0);
\r
127 + if (messages == NULL)
\r
128 + INTERNAL_ERROR ("Thread %s has no toplevel messages.\n",
\r
129 + notmuch_thread_get_thread_id (thread));
\r
131 + show_messages (ctx, messages, 0);
\r
133 - notmuch_thread_destroy (thread);
\r
134 + notmuch_thread_destroy (thread);
\r
138 notmuch_query_destroy (query);
\r
139 diff --git a/notmuch.c b/notmuch.c
\r
140 index f45b692..a817ae3 100644
\r
143 @@ -177,6 +177,13 @@ command_t commands[] = {
\r
144 "\t\t(all replies to a particular message appear immediately\n"
\r
145 "\t\tafter that message in date order).\n"
\r
147 + "\t\tSupported options for show include:\n"
\r
149 + "\t\t--only-matching-messages\n"
\r
151 + "\t\t\tUsing this option will prevent output of any messages\n"
\r
152 + "\t\t\tthat do not match the search terms.\n"
\r
154 "\t\tThe output format is plain-text, with all text-content\n"
\r
155 "\t\tMIME parts decoded. Various components in the output,\n"
\r
156 "\t\t('message', 'header', 'body', 'attachment', and MIME 'part')\n"
\r