Re: Better Gmail handling by not using Notmuch tags
[notmuch-archives.git] / 8b / 162c8a086a46fa77875224af26801485632920
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 BE000431FBF\r
6         for <notmuch@notmuchmail.org>; Thu, 17 Dec 2009 18:45:11 -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 QWHIbbLjE7jz for <notmuch@notmuchmail.org>;\r
11         Thu, 17 Dec 2009 18:45:10 -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 B455B431FAE\r
14         for <notmuch@notmuchmail.org>; Thu, 17 Dec 2009 18:45:10 -0800 (PST)\r
15 Received: from\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 1NLSq5-0002EE-Fo; Thu, 17 Dec 2009 22:45:10 -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 1NLSpz-0005Dr-J4; Thu, 17 Dec 2009 22:45:03 -0400\r
24 From: david@tethera.net\r
25 To: notmuch@notmuchmail.org\r
26 Date: Thu, 17 Dec 2009 22:44:54 -0400\r
27 Message-Id: <1261104294-15075-1-git-send-email-david@tethera.net>\r
28 X-Mailer: git-send-email 1.6.5.3\r
29 In-Reply-To: <87aaxhrv34.fsf@pivot.cs.unb.ca>\r
30 References: <87aaxhrv34.fsf@pivot.cs.unb.ca>\r
31 X-Sender-Verified: bremner@pivot.cs.unb.ca\r
32 Cc: David Bremner <bremner@unb.ca>\r
33 Subject: [notmuch] [PATCH] notmuch-show.c: provide an option\r
34         --format=message-ids which outputs only ids.\r
35 X-BeenThere: notmuch@notmuchmail.org\r
36 X-Mailman-Version: 2.1.12\r
37 Precedence: list\r
38 List-Id: "Use and development of the notmuch mail system."\r
39         <notmuch.notmuchmail.org>\r
40 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
41         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
42 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
43 List-Post: <mailto:notmuch@notmuchmail.org>\r
44 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
45 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
46         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
47 X-List-Received-Date: Fri, 18 Dec 2009 02:45:11 -0000\r
48 \r
49 From: David Bremner <bremner@unb.ca>\r
50 \r
51 If the option --format=message-ids is passed on the command line, only message\r
52 IDs are output.  A new structure show_options_t is defined to keep track of\r
53 all (currently 2) command line options.\r
54 ---\r
55 \r
56 It seems a shame to parse the entire output of notmuch show to get a\r
57 message id (or all of the message ids) contained in a thread.  One\r
58 might like a shorter command line option, but this seems to leave room\r
59 for --format=json, and so on.  Similarly, defining an option structure is \r
60 arguably overengineering; I'm happy to rework to just pass a second boolean \r
61 parameter to notmuch_show_messages.  \r
62 \r
63  notmuch-show.c |   30 ++++++++++++++++++++++--------\r
64  1 files changed, 22 insertions(+), 8 deletions(-)\r
65 \r
66 diff --git a/notmuch-show.c b/notmuch-show.c\r
67 index 376aacd..4ed8cec 100644\r
68 --- a/notmuch-show.c\r
69 +++ b/notmuch-show.c\r
70 @@ -20,6 +20,11 @@\r
71  \r
72  #include "notmuch-client.h"\r
73  \r
74 +typedef struct {\r
75 +  enum { FORMAT_DEFAULT, FORMAT_MESSAGE_ID } format;\r
76 +  int entire_thread;\r
77 +} show_options_t;\r
78 +    \r
79  static const char *\r
80  _get_tags_as_string (void *ctx, notmuch_message_t *message)\r
81  {\r
82 @@ -185,7 +190,7 @@ show_message (void *ctx, notmuch_message_t *message, int indent)\r
83  \r
84  static void\r
85  show_messages (void *ctx, notmuch_messages_t *messages, int indent,\r
86 -              notmuch_bool_t entire_thread)\r
87 +              show_options_t *options)\r
88  {\r
89      notmuch_message_t *message;\r
90      notmuch_bool_t match;\r
91 @@ -201,13 +206,17 @@ show_messages (void *ctx, notmuch_messages_t *messages, int indent,\r
92  \r
93         next_indent = indent;\r
94  \r
95 -       if (match || entire_thread) {\r
96 -           show_message (ctx, message, indent);\r
97 -           next_indent = indent + 1;\r
98 +       if (match || options->entire_thread) {\r
99 +           if (options->format == FORMAT_DEFAULT) {\r
100 +               show_message (ctx, message, indent);\r
101 +               next_indent = indent + 1;\r
102 +           } else {\r
103 +               puts (notmuch_message_get_message_id (message));\r
104 +           } \r
105         }\r
106  \r
107         show_messages (ctx, notmuch_message_get_replies (message),\r
108 -                      next_indent, entire_thread);\r
109 +                      next_indent, options);\r
110  \r
111         notmuch_message_destroy (message);\r
112      }\r
113 @@ -222,17 +231,22 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
114      notmuch_threads_t *threads;\r
115      notmuch_thread_t *thread;\r
116      notmuch_messages_t *messages;\r
117 +    show_options_t options;\r
118      char *query_string;\r
119 -    int entire_thread = 0;\r
120      int i;\r
121  \r
122 +    options.entire_thread = 0;\r
123 +    options.format = FORMAT_DEFAULT;\r
124 +        \r
125      for (i = 0; i < argc && argv[i][0] == '-'; i++) {\r
126         if (strcmp (argv[i], "--") == 0) {\r
127             i++;\r
128             break;\r
129         }\r
130          if (strcmp(argv[i], "--entire-thread") == 0) {\r
131 -           entire_thread = 1;\r
132 +           options.entire_thread = 1;\r
133 +       } else if (strcmp (argv[i], "--format=message-ids") == 0) {\r
134 +           options.format = FORMAT_MESSAGE_ID;\r
135         } else {\r
136             fprintf (stderr, "Unrecognized option: %s\n", argv[i]);\r
137             return 1;\r
138 @@ -280,7 +294,7 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
139             INTERNAL_ERROR ("Thread %s has no toplevel messages.\n",\r
140                             notmuch_thread_get_thread_id (thread));\r
141  \r
142 -       show_messages (ctx, messages, 0, entire_thread);\r
143 +       show_messages (ctx, messages, 0, &options);\r
144  \r
145         notmuch_thread_destroy (thread);\r
146      }\r
147 -- \r
148 1.6.5.3\r
149 \r