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