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 AF672431FBD for ; Fri, 9 Nov 2012 10:58:28 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0.201 X-Spam-Level: X-Spam-Status: No, score=0.201 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled 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 ROQjZyqm58nU for ; Fri, 9 Nov 2012 10:58:28 -0800 (PST) Received: from mail-wg0-f45.google.com (mail-wg0-f45.google.com [74.125.82.45]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id EB269431FAE for ; Fri, 9 Nov 2012 10:58:27 -0800 (PST) Received: by mail-wg0-f45.google.com with SMTP id dq12so2288423wgb.2 for ; Fri, 09 Nov 2012 10:58:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=6f5Trh6jvu/FRTUCd8oNmPXvKMnpi9AzfQkdRolibGc=; b=EEf9hkoRMYc5NQWzbiLWco3ksHa562jlHqfSf0wlc4mYTRF1y48jwWb6HVMsU/3P5Y /jNezRhqMCMOvY3PQn5UBaRKbq2leC6z6rLmXzWPbRBfn0DRGlWBXrq7gMIb+R6UOYnF 7HjiZzC3FRKIiwCwPXeQef3zWfYx6p92uvby+z6RjUoHkwu21stEU4u+rhQT4+JrwMJO 0weOUSVZ4f3CcpPOABAHT2lIngD5/kt3gOifTDJpLO8PI4w5tPXB1nS7LrWF1XneX2Oj 9A2+RzstBmA5bYkZls1/1lqwlWPPS2dCzyRv+RPDhWJ3dr8Y1LRXllkNhfOJTFMRw2eC Wo3Q== Received: by 10.180.102.166 with SMTP id fp6mr4165109wib.9.1352487507604; Fri, 09 Nov 2012 10:58:27 -0800 (PST) Received: from localhost (93-97-24-31.zone5.bethere.co.uk. [93.97.24.31]) by mx.google.com with ESMTPS id gg4sm3767301wib.6.2012.11.09.10.58.26 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 09 Nov 2012 10:58:26 -0800 (PST) From: Mark Walters 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 Message-Id: <1352487491-31512-3-git-send-email-markwalters1009@gmail.com> X-Mailer: git-send-email 1.7.9.1 In-Reply-To: <1352487491-31512-1-git-send-email-markwalters1009@gmail.com> References: <1352487491-31512-1-git-send-email-markwalters1009@gmail.com> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 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, 09 Nov 2012 18:58:28 -0000 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