From: Mark Walters <markwalters1009@gmail.com>
To: notmuch@notmuchmail.org
Subject: [PATCH 2/3] cli: all search mode to include msg-ids with JSON output
Date: Fri, 9 Nov 2012 18:58:10 +0000 [thread overview]
Message-ID: <1352487491-31512-3-git-send-email-markwalters1009@gmail.com> (raw)
In-Reply-To: <1352487491-31512-1-git-send-email-markwalters1009@gmail.com>
This adds a --output=with-ids option which gives similar output to the
normal search summary output but with a list of message ids
too. Currently this is not implemented for text format.
---
notmuch-search.c | 40 ++++++++++++++++++++++++++++++++++++++--
1 files changed, 38 insertions(+), 2 deletions(-)
diff --git a/notmuch-search.c b/notmuch-search.c
index 830c4e4..82e168c 100644
--- a/notmuch-search.c
+++ b/notmuch-search.c
@@ -26,7 +26,8 @@ typedef enum {
OUTPUT_THREADS,
OUTPUT_MESSAGES,
OUTPUT_FILES,
- OUTPUT_TAGS
+ OUTPUT_TAGS,
+ OUTPUT_SUMMARY_WITH_IDS
} output_t;
static char *
@@ -46,6 +47,23 @@ sanitize_string (const void *ctx, const char *str)
return out;
}
+static void
+output_msg_ids (sprinter_t *format,
+ notmuch_bool_t matching,
+ notmuch_messages_t *messages)
+{
+ notmuch_message_t *message;
+ for (;
+ notmuch_messages_valid (messages);
+ notmuch_messages_move_to_next (messages))
+ {
+ message = notmuch_messages_get (messages);
+ if (notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_MATCH) == matching)
+ format->string (format, notmuch_message_get_message_id (message));
+ output_msg_ids (format, matching, notmuch_message_get_replies (message));
+ }
+}
+
static int
do_search_threads (sprinter_t *format,
notmuch_query_t *query,
@@ -88,7 +106,7 @@ do_search_threads (sprinter_t *format,
format->string (format,
notmuch_thread_get_thread_id (thread));
format->separator (format);
- } else { /* output == OUTPUT_SUMMARY */
+ } else { /* output == OUTPUT_SUMMARY or OUTPUT_SUMMARY_WITH_IDS */
void *ctx_quote = talloc_new (thread);
const char *authors = notmuch_thread_get_authors (thread);
const char *subject = notmuch_thread_get_subject (thread);
@@ -160,6 +178,18 @@ do_search_threads (sprinter_t *format,
printf (")");
format->end (format);
+
+ if (output == OUTPUT_SUMMARY_WITH_IDS) {
+ format->map_key (format, "matching_msg_ids");
+ format->begin_list (format);
+ output_msg_ids (format, TRUE, notmuch_thread_get_toplevel_messages (thread));
+ format->end (format);
+ format->map_key (format, "nonmatching_msg_ids");
+ format->begin_list (format);
+ output_msg_ids (format, FALSE, notmuch_thread_get_toplevel_messages (thread));
+ format->end (format);
+ }
+
format->end (format);
format->separator (format);
}
@@ -323,6 +353,7 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
{ "messages", OUTPUT_MESSAGES },
{ "files", OUTPUT_FILES },
{ "tags", OUTPUT_TAGS },
+ { "with-ids", OUTPUT_SUMMARY_WITH_IDS },
{ 0, 0 } } },
{ NOTMUCH_OPT_KEYWORD, &exclude, "exclude", 'x',
(notmuch_keyword_t []){ { "true", EXCLUDE_TRUE },
@@ -398,6 +429,11 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
notmuch_query_set_omit_excluded (query, FALSE);
}
+ if (output == OUTPUT_SUMMARY_WITH_IDS && format_sel == NOTMUCH_FORMAT_TEXT) {
+ fprintf (stderr, "Warning: --output=with-ids not implemented for text format.\n");
+ output = OUTPUT_SUMMARY;
+ }
+
switch (output) {
default:
case OUTPUT_SUMMARY:
--
1.7.9.1
next prev parent reply other threads:[~2012-11-09 18:58 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-09 18:58 [PATCH 0/3] Outline fix for emacs tagging race Mark Walters
2012-11-09 18:58 ` [PATCH 1/3] test: test for race when tagging from emacs search Mark Walters
2012-11-09 18:58 ` Mark Walters [this message]
2012-11-22 16:15 ` [PATCH 2/3] cli: all search mode to include msg-ids with JSON output Jameson Graef Rollins
2012-11-22 18:05 ` Michal Nazarewicz
2012-11-22 19:35 ` Mark Walters
2012-11-23 7:23 ` Jameson Graef Rollins
2012-11-23 9:01 ` Tomi Ollila
2012-11-23 20:39 ` Austin Clements
2012-11-09 18:58 ` [PATCH 3/3] emacs: make emacs use message-ids for tagging Mark Walters
2012-11-09 21:25 ` [PATCH 0/3] Outline fix for emacs tagging race Tomi Ollila
2012-11-09 23:27 ` David Bremner
2012-11-10 5:29 ` Austin Clements
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=1352487491-31512-3-git-send-email-markwalters1009@gmail.com \
--to=markwalters1009@gmail.com \
--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).