1 Return-Path: <bremner@pivot.cs.unb.ca>
\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 35505431FCB
\r
6 for <notmuch@notmuchmail.org>; Sat, 19 Dec 2009 06:56:04 -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 Y6RtE5gCMQK0 for <notmuch@notmuchmail.org>;
\r
11 Sat, 19 Dec 2009 06:56:02 -0800 (PST)
\r
12 Received: from pivot.cs.unb.ca (pivot.cs.unb.ca [131.202.240.57])
\r
13 by olra.theworths.org (Postfix) with ESMTP id 13AD4431FBF
\r
14 for <notmuch@notmuchmail.org>; Sat, 19 Dec 2009 06:56:02 -0800 (PST)
\r
16 fctnnbsc30w-142167182194.pppoe-dynamic.high-speed.nb.bellaliant.net
\r
17 ([142.167.182.194] helo=localhost)
\r
18 by pivot.cs.unb.ca with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32)
\r
19 (Exim 4.69) (envelope-from <bremner@pivot.cs.unb.ca>)
\r
20 id 1NM0iv-0003aS-H0; Sat, 19 Dec 2009 10:56:01 -0400
\r
21 Received: from bremner by localhost with local (Exim 4.69)
\r
22 (envelope-from <bremner@pivot.cs.unb.ca>)
\r
23 id 1NM0iq-0006ec-27; Sat, 19 Dec 2009 10:55:56 -0400
\r
24 From: david@tethera.net
\r
25 To: notmuch@notmuchmail.org
\r
26 Date: Sat, 19 Dec 2009 10:55:24 -0400
\r
27 Message-Id: <1261234524-25522-4-git-send-email-david@tethera.net>
\r
28 X-Mailer: git-send-email 1.6.5.3
\r
29 In-Reply-To: <1261234524-25522-3-git-send-email-david@tethera.net>
\r
30 References: <87iqc4yyo8.fsf@yoom.home.cworth.org>
\r
31 <1261234524-25522-1-git-send-email-david@tethera.net>
\r
32 <1261234524-25522-2-git-send-email-david@tethera.net>
\r
33 <1261234524-25522-3-git-send-email-david@tethera.net>
\r
34 X-Sender-Verified: bremner@pivot.cs.unb.ca
\r
35 Cc: David Bremner <bremner@unb.ca>
\r
36 Subject: [notmuch] [PATCH 3/3] notmuch-show.c: prototype tabular output
\r
37 format, with output control
\r
38 X-BeenThere: notmuch@notmuchmail.org
\r
39 X-Mailman-Version: 2.1.12
\r
41 List-Id: "Use and development of the notmuch mail system."
\r
42 <notmuch.notmuchmail.org>
\r
43 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
44 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
45 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
46 List-Post: <mailto:notmuch@notmuchmail.org>
\r
47 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
48 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
49 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
50 X-List-Received-Date: Sat, 19 Dec 2009 14:56:04 -0000
\r
52 From: David Bremner <bremner@unb.ca>
\r
54 Currently this only outputs the information from the "message header";
\r
55 i.e. the part before the rfc2822 header or body.
\r
57 Adding this required adding an extra parameter, currently unused, to
\r
58 format_message_text and format_message_json. Also the struct
\r
59 definition is changed to match the new function prototypes.
\r
61 An int (enum) is used as a mask, each bit corresponds to some part to
\r
62 be shown or not shown. This enum will need to be extended as more
\r
63 things are controllable via --show.
\r
65 notmuch-show.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++-------
\r
66 1 files changed, 77 insertions(+), 12 deletions(-)
\r
68 diff --git a/notmuch-show.c b/notmuch-show.c
\r
69 index 51aa87d..99a4d3c 100644
\r
70 --- a/notmuch-show.c
\r
71 +++ b/notmuch-show.c
\r
74 #include "notmuch-client.h"
\r
76 +/* These should be powers of 2 */
\r
77 +typedef enum {SHOW_MESSAGE_ID = 1,
\r
82 +static const show_mask_t SHOW_ALL = ~0;
\r
84 typedef struct show_format {
\r
85 const char *message_set_start;
\r
86 const char *message_start;
\r
87 - void (*message) (const void *ctx,
\r
88 + void (*message) (const void *ctx, show_mask_t show_mask,
\r
89 notmuch_message_t *message,
\r
91 const char *header_start;
\r
92 @@ -40,7 +48,7 @@ typedef struct show_format {
\r
96 -format_message_text (unused (const void *ctx),
\r
97 +format_message_text (unused (const void *ctx), show_mask_t show_mask,
\r
98 notmuch_message_t *message,
\r
101 @@ -59,7 +67,21 @@ static const show_format_t format_text = {
\r
105 -format_message_json (const void *ctx,
\r
106 +format_message_tabular (unused (const void *ctx), show_mask_t show_mask,
\r
107 + notmuch_message_t *message,
\r
110 +static const show_format_t format_tabular = {
\r
112 + "", format_message_tabular,
\r
120 +format_message_json (const void *ctx, show_mask_t show_mask,
\r
121 notmuch_message_t *message,
\r
122 unused (int indent));
\r
124 @@ -124,7 +146,30 @@ _get_one_line_summary (const void *ctx, notmuch_message_t *message)
\r
128 -format_message_text (unused (const void *ctx), notmuch_message_t *message, int indent)
\r
129 +format_message_tabular (unused (const void *ctx), show_mask_t show_mask,
\r
130 + notmuch_message_t *message,
\r
131 + unused(int indent))
\r
135 + if (show_mask & SHOW_MESSAGE_ID) {
\r
136 + fputs ( notmuch_message_get_message_id (message), stdout);
\r
140 + if (show_mask & SHOW_MATCH)
\r
141 + printf ("%s%d", count++ ? "\t" : "",
\r
142 + notmuch_message_get_flag (message,
\r
143 + NOTMUCH_MESSAGE_FLAG_MATCH));
\r
145 + if (show_mask & SHOW_FILENAME)
\r
146 + printf("%s%s", count++ ? "\t" : "",
\r
147 + notmuch_message_get_filename (message));
\r
151 +format_message_text (unused (const void *ctx), unused(show_mask_t show_mask),
\r
152 + notmuch_message_t *message, int indent)
\r
154 printf ("id:%s depth:%d match:%d filename:%s\n",
\r
155 notmuch_message_get_message_id (message),
\r
156 @@ -134,7 +179,8 @@ format_message_text (unused (const void *ctx), notmuch_message_t *message, int i
\r
160 -format_message_json (const void *ctx, notmuch_message_t *message, unused (int indent))
\r
161 +format_message_json (const void *ctx, unused(show_mask_t show_mask),
\r
162 + notmuch_message_t *message, unused (int indent))
\r
164 void *ctx_quote = talloc_new (ctx);
\r
166 @@ -323,11 +369,12 @@ format_part_json (GMimeObject *part, int *part_count)
\r
170 -show_message (void *ctx, const show_format_t *format, notmuch_message_t *message, int indent)
\r
171 +show_message (void *ctx, const show_format_t *format, show_mask_t show_mask,
\r
172 + notmuch_message_t *message, int indent)
\r
174 fputs (format->message_start, stdout);
\r
175 if (format->message)
\r
176 - format->message(ctx, message, indent);
\r
177 + format->message(ctx, show_mask, message, indent);
\r
179 fputs (format->header_start, stdout);
\r
180 if (format->header)
\r
181 @@ -344,8 +391,8 @@ show_message (void *ctx, const show_format_t *format, notmuch_message_t *message
\r
185 -show_messages (void *ctx, const show_format_t *format, notmuch_messages_t *messages, int indent,
\r
186 - notmuch_bool_t entire_thread)
\r
187 +show_messages (void *ctx, const show_format_t *format, show_mask_t show_mask,
\r
188 + notmuch_messages_t *messages, int indent, notmuch_bool_t entire_thread)
\r
190 notmuch_message_t *message;
\r
191 notmuch_bool_t match;
\r
192 @@ -371,13 +418,14 @@ show_messages (void *ctx, const show_format_t *format, notmuch_messages_t *messa
\r
193 next_indent = indent;
\r
195 if (match || entire_thread) {
\r
196 - show_message (ctx, format, message, indent);
\r
197 + show_message (ctx, format, show_mask, message, indent);
\r
198 next_indent = indent + 1;
\r
200 fputs (format->message_set_sep, stdout);
\r
203 - show_messages (ctx, format, notmuch_message_get_replies (message),
\r
204 + show_messages (ctx, format, show_mask,
\r
205 + notmuch_message_get_replies (message),
\r
206 next_indent, entire_thread);
\r
208 notmuch_message_destroy (message);
\r
209 @@ -403,6 +451,7 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
\r
210 int entire_thread = 0;
\r
212 int first_toplevel = 1;
\r
213 + show_mask_t show_mask=SHOW_ALL;
\r
215 for (i = 0; i < argc && argv[i][0] == '-'; i++) {
\r
216 if (strcmp (argv[i], "--") == 0) {
\r
217 @@ -422,6 +471,22 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
\r
218 fprintf (stderr, "Invalid value for --format: %s\n", opt);
\r
221 + } else if (STRNCMP_LITERAL (argv[i], "--show=") == 0) {
\r
222 + char *keyword=NULL;
\r
224 + opt = argv[i] + sizeof ("--show=") - 1;
\r
225 + while ((keyword=strsep (&opt,", "))) {
\r
226 + if (strcmp (keyword, "message-id") == 0) {
\r
227 + show_mask |= SHOW_MESSAGE_ID;
\r
228 + } else if (strcmp (keyword, "match") == 0) {
\r
229 + show_mask |= SHOW_MATCH;
\r
230 + } else if (strcmp (keyword, "filename") == 0) {
\r
231 + show_mask |= SHOW_FILENAME;
\r
233 + fprintf (stderr, "Invalid value for --show: %s\n", opt);
\r
237 } else if (STRNCMP_LITERAL (argv[i], "--entire-thread") == 0) {
\r
240 @@ -477,7 +542,7 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
\r
241 fputs (format->message_set_sep, stdout);
\r
242 first_toplevel = 0;
\r
244 - show_messages (ctx, format, messages, 0, entire_thread);
\r
245 + show_messages (ctx, format, show_mask, messages, 0, entire_thread);
\r
247 notmuch_thread_destroy (thread);
\r