unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: david@tethera.net
To: notmuch@notmuchmail.org
Cc: David Bremner <bremner@unb.ca>
Subject: [PATCH] notmuch-show.c: provide an option --format=message-ids which outputs only ids.
Date: Thu, 17 Dec 2009 22:44:54 -0400	[thread overview]
Message-ID: <1261104294-15075-1-git-send-email-david@tethera.net> (raw)
In-Reply-To: <87aaxhrv34.fsf@pivot.cs.unb.ca>

From: David Bremner <bremner@unb.ca>

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

      reply	other threads:[~2009-12-18  2:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-15 21:23 wish: syncable/immutable threads David Bremner
2009-12-16  0:36 ` Carl Worth
2009-12-18  0:20   ` David Bremner
2009-12-18  2:44     ` david [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1261104294-15075-1-git-send-email-david@tethera.net \
    --to=david@tethera.net \
    --cc=bremner@unb.ca \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).