[notmuch] [PATCH] notmuch-show.c: provide an option --format=message-ids which output...
authordavid <david@tethera.net>
Fri, 18 Dec 2009 02:44:54 +0000 (22:44 +2000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:35:53 +0000 (09:35 -0800)
8b/162c8a086a46fa77875224af26801485632920 [new file with mode: 0644]

diff --git a/8b/162c8a086a46fa77875224af26801485632920 b/8b/162c8a086a46fa77875224af26801485632920
new file mode 100644 (file)
index 0000000..33bfd03
--- /dev/null
@@ -0,0 +1,149 @@
+Return-Path: <bremner@pivot.cs.unb.ca>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id BE000431FBF\r
+       for <notmuch@notmuchmail.org>; Thu, 17 Dec 2009 18:45:11 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id QWHIbbLjE7jz for <notmuch@notmuchmail.org>;\r
+       Thu, 17 Dec 2009 18:45:10 -0800 (PST)\r
+Received: from pivot.cs.unb.ca (pivot.cs.unb.ca [131.202.240.57])\r
+       by olra.theworths.org (Postfix) with ESMTP id B455B431FAE\r
+       for <notmuch@notmuchmail.org>; Thu, 17 Dec 2009 18:45:10 -0800 (PST)\r
+Received: from\r
+       fctnnbsc30w-142167182194.pppoe-dynamic.high-speed.nb.bellaliant.net\r
+       ([142.167.182.194] helo=localhost)\r
+       by pivot.cs.unb.ca with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32)\r
+       (Exim 4.69) (envelope-from <bremner@pivot.cs.unb.ca>)\r
+       id 1NLSq5-0002EE-Fo; Thu, 17 Dec 2009 22:45:10 -0400\r
+Received: from bremner by localhost with local (Exim 4.69)\r
+       (envelope-from <bremner@pivot.cs.unb.ca>)\r
+       id 1NLSpz-0005Dr-J4; Thu, 17 Dec 2009 22:45:03 -0400\r
+From: david@tethera.net\r
+To: notmuch@notmuchmail.org\r
+Date: Thu, 17 Dec 2009 22:44:54 -0400\r
+Message-Id: <1261104294-15075-1-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 1.6.5.3\r
+In-Reply-To: <87aaxhrv34.fsf@pivot.cs.unb.ca>\r
+References: <87aaxhrv34.fsf@pivot.cs.unb.ca>\r
+X-Sender-Verified: bremner@pivot.cs.unb.ca\r
+Cc: David Bremner <bremner@unb.ca>\r
+Subject: [notmuch] [PATCH] notmuch-show.c: provide an option\r
+       --format=message-ids which outputs only ids.\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.12\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Fri, 18 Dec 2009 02:45:11 -0000\r
+\r
+From: David Bremner <bremner@unb.ca>\r
+\r
+If the option --format=message-ids is passed on the command line, only message\r
+IDs are output.  A new structure show_options_t is defined to keep track of\r
+all (currently 2) command line options.\r
+---\r
+\r
+It seems a shame to parse the entire output of notmuch show to get a\r
+message id (or all of the message ids) contained in a thread.  One\r
+might like a shorter command line option, but this seems to leave room\r
+for --format=json, and so on.  Similarly, defining an option structure is \r
+arguably overengineering; I'm happy to rework to just pass a second boolean \r
+parameter to notmuch_show_messages.  \r
+\r
+ notmuch-show.c |   30 ++++++++++++++++++++++--------\r
+ 1 files changed, 22 insertions(+), 8 deletions(-)\r
+\r
+diff --git a/notmuch-show.c b/notmuch-show.c\r
+index 376aacd..4ed8cec 100644\r
+--- a/notmuch-show.c\r
++++ b/notmuch-show.c\r
+@@ -20,6 +20,11 @@\r
\r
+ #include "notmuch-client.h"\r
\r
++typedef struct {\r
++  enum { FORMAT_DEFAULT, FORMAT_MESSAGE_ID } format;\r
++  int entire_thread;\r
++} show_options_t;\r
++    \r
+ static const char *\r
+ _get_tags_as_string (void *ctx, notmuch_message_t *message)\r
+ {\r
+@@ -185,7 +190,7 @@ show_message (void *ctx, notmuch_message_t *message, int indent)\r
\r
+ static void\r
+ show_messages (void *ctx, notmuch_messages_t *messages, int indent,\r
+-             notmuch_bool_t entire_thread)\r
++             show_options_t *options)\r
+ {\r
+     notmuch_message_t *message;\r
+     notmuch_bool_t match;\r
+@@ -201,13 +206,17 @@ show_messages (void *ctx, notmuch_messages_t *messages, int indent,\r
\r
+       next_indent = indent;\r
\r
+-      if (match || entire_thread) {\r
+-          show_message (ctx, message, indent);\r
+-          next_indent = indent + 1;\r
++      if (match || options->entire_thread) {\r
++          if (options->format == FORMAT_DEFAULT) {\r
++              show_message (ctx, message, indent);\r
++              next_indent = indent + 1;\r
++          } else {\r
++              puts (notmuch_message_get_message_id (message));\r
++          } \r
+       }\r
\r
+       show_messages (ctx, notmuch_message_get_replies (message),\r
+-                     next_indent, entire_thread);\r
++                     next_indent, options);\r
\r
+       notmuch_message_destroy (message);\r
+     }\r
+@@ -222,17 +231,22 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
+     notmuch_threads_t *threads;\r
+     notmuch_thread_t *thread;\r
+     notmuch_messages_t *messages;\r
++    show_options_t options;\r
+     char *query_string;\r
+-    int entire_thread = 0;\r
+     int i;\r
\r
++    options.entire_thread = 0;\r
++    options.format = FORMAT_DEFAULT;\r
++        \r
+     for (i = 0; i < argc && argv[i][0] == '-'; i++) {\r
+       if (strcmp (argv[i], "--") == 0) {\r
+           i++;\r
+           break;\r
+       }\r
+         if (strcmp(argv[i], "--entire-thread") == 0) {\r
+-          entire_thread = 1;\r
++          options.entire_thread = 1;\r
++      } else if (strcmp (argv[i], "--format=message-ids") == 0) {\r
++          options.format = FORMAT_MESSAGE_ID;\r
+       } else {\r
+           fprintf (stderr, "Unrecognized option: %s\n", argv[i]);\r
+           return 1;\r
+@@ -280,7 +294,7 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
+           INTERNAL_ERROR ("Thread %s has no toplevel messages.\n",\r
+                           notmuch_thread_get_thread_id (thread));\r
\r
+-      show_messages (ctx, messages, 0, entire_thread);\r
++      show_messages (ctx, messages, 0, &options);\r
\r
+       notmuch_thread_destroy (thread);\r
+     }\r
+-- \r
+1.6.5.3\r
+\r