[PATCH 2/3] cli: all search mode to include msg-ids with JSON output
authorMark Walters <markwalters1009@gmail.com>
Fri, 9 Nov 2012 18:58:10 +0000 (18:58 +0000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:50:28 +0000 (09:50 -0800)
1a/4a458f268b5bc4e5c6abec22f2d52676a3089d [new file with mode: 0644]

diff --git a/1a/4a458f268b5bc4e5c6abec22f2d52676a3089d b/1a/4a458f268b5bc4e5c6abec22f2d52676a3089d
new file mode 100644 (file)
index 0000000..7c1e37b
--- /dev/null
@@ -0,0 +1,158 @@
+Return-Path: <markwalters1009@gmail.com>\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 AF672431FBD\r
+       for <notmuch@notmuchmail.org>; Fri,  9 Nov 2012 10:58:28 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.201\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.201 tagged_above=-999 required=5\r
+       tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+       FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001,\r
+       RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\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 ROQjZyqm58nU for <notmuch@notmuchmail.org>;\r
+       Fri,  9 Nov 2012 10:58:28 -0800 (PST)\r
+Received: from mail-wg0-f45.google.com (mail-wg0-f45.google.com\r
+ [74.125.82.45])       (using TLSv1 with cipher RC4-SHA (128/128 bits))        (No client\r
+ certificate requested)        by olra.theworths.org (Postfix) with ESMTPS id\r
+ EB269431FAE   for <notmuch@notmuchmail.org>; Fri,  9 Nov 2012 10:58:27 -0800\r
+ (PST)\r
+Received: by mail-wg0-f45.google.com with SMTP id dq12so2288423wgb.2\r
+       for <notmuch@notmuchmail.org>; Fri, 09 Nov 2012 10:58:27 -0800 (PST)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+       h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references;\r
+       bh=6f5Trh6jvu/FRTUCd8oNmPXvKMnpi9AzfQkdRolibGc=;\r
+       b=EEf9hkoRMYc5NQWzbiLWco3ksHa562jlHqfSf0wlc4mYTRF1y48jwWb6HVMsU/3P5Y\r
+       /jNezRhqMCMOvY3PQn5UBaRKbq2leC6z6rLmXzWPbRBfn0DRGlWBXrq7gMIb+R6UOYnF\r
+       7HjiZzC3FRKIiwCwPXeQef3zWfYx6p92uvby+z6RjUoHkwu21stEU4u+rhQT4+JrwMJO\r
+       0weOUSVZ4f3CcpPOABAHT2lIngD5/kt3gOifTDJpLO8PI4w5tPXB1nS7LrWF1XneX2Oj\r
+       9A2+RzstBmA5bYkZls1/1lqwlWPPS2dCzyRv+RPDhWJ3dr8Y1LRXllkNhfOJTFMRw2eC\r
+       Wo3Q==\r
+Received: by 10.180.102.166 with SMTP id fp6mr4165109wib.9.1352487507604;\r
+       Fri, 09 Nov 2012 10:58:27 -0800 (PST)\r
+Received: from localhost (93-97-24-31.zone5.bethere.co.uk. [93.97.24.31])\r
+       by mx.google.com with ESMTPS id gg4sm3767301wib.6.2012.11.09.10.58.26\r
+       (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Fri, 09 Nov 2012 10:58:26 -0800 (PST)\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 2/3] cli: all search mode to include msg-ids with JSON output\r
+Date: Fri,  9 Nov 2012 18:58:10 +0000\r
+Message-Id: <1352487491-31512-3-git-send-email-markwalters1009@gmail.com>\r
+X-Mailer: git-send-email 1.7.9.1\r
+In-Reply-To: <1352487491-31512-1-git-send-email-markwalters1009@gmail.com>\r
+References: <1352487491-31512-1-git-send-email-markwalters1009@gmail.com>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\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, 09 Nov 2012 18:58:28 -0000\r
+\r
+This adds a --output=with-ids option which gives similar output to the\r
+normal search summary output but with a list of message ids\r
+too. Currently this is not implemented for text format.\r
+---\r
+ notmuch-search.c |   40 ++++++++++++++++++++++++++++++++++++++--\r
+ 1 files changed, 38 insertions(+), 2 deletions(-)\r
+\r
+diff --git a/notmuch-search.c b/notmuch-search.c\r
+index 830c4e4..82e168c 100644\r
+--- a/notmuch-search.c\r
++++ b/notmuch-search.c\r
+@@ -26,7 +26,8 @@ typedef enum {\r
+     OUTPUT_THREADS,\r
+     OUTPUT_MESSAGES,\r
+     OUTPUT_FILES,\r
+-    OUTPUT_TAGS\r
++    OUTPUT_TAGS,\r
++    OUTPUT_SUMMARY_WITH_IDS\r
+ } output_t;\r
+ \r
+ static char *\r
+@@ -46,6 +47,23 @@ sanitize_string (const void *ctx, const char *str)\r
+     return out;\r
+ }\r
+ \r
++static void\r
++output_msg_ids (sprinter_t *format,\r
++              notmuch_bool_t matching,\r
++              notmuch_messages_t *messages)\r
++{\r
++    notmuch_message_t *message;\r
++    for (;\r
++       notmuch_messages_valid (messages);\r
++       notmuch_messages_move_to_next (messages))\r
++    {\r
++      message = notmuch_messages_get (messages);\r
++      if (notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_MATCH) == matching)\r
++          format->string (format, notmuch_message_get_message_id (message));\r
++      output_msg_ids (format, matching, notmuch_message_get_replies (message));\r
++    }\r
++}\r
++\r
+ static int\r
+ do_search_threads (sprinter_t *format,\r
+                  notmuch_query_t *query,\r
+@@ -88,7 +106,7 @@ do_search_threads (sprinter_t *format,\r
+           format->string (format,\r
+                           notmuch_thread_get_thread_id (thread));\r
+           format->separator (format);\r
+-      } else { /* output == OUTPUT_SUMMARY */\r
++      } else { /* output == OUTPUT_SUMMARY or OUTPUT_SUMMARY_WITH_IDS */\r
+           void *ctx_quote = talloc_new (thread);\r
+           const char *authors = notmuch_thread_get_authors (thread);\r
+           const char *subject = notmuch_thread_get_subject (thread);\r
+@@ -160,6 +178,18 @@ do_search_threads (sprinter_t *format,\r
+               printf (")");\r
+ \r
+           format->end (format);\r
++\r
++      if (output == OUTPUT_SUMMARY_WITH_IDS) {\r
++          format->map_key (format, "matching_msg_ids");\r
++          format->begin_list (format);\r
++          output_msg_ids (format, TRUE, notmuch_thread_get_toplevel_messages (thread));\r
++          format->end (format);\r
++          format->map_key (format, "nonmatching_msg_ids");\r
++          format->begin_list (format);\r
++          output_msg_ids (format, FALSE, notmuch_thread_get_toplevel_messages (thread));\r
++          format->end (format);\r
++      }\r
++\r
+           format->end (format);\r
+           format->separator (format);\r
+       }\r
+@@ -323,6 +353,7 @@ notmuch_search_command (void *ctx, int argc, char *argv[])\r
+                                 { "messages", OUTPUT_MESSAGES },\r
+                                 { "files", OUTPUT_FILES },\r
+                                 { "tags", OUTPUT_TAGS },\r
++                                { "with-ids", OUTPUT_SUMMARY_WITH_IDS },\r
+                                 { 0, 0 } } },\r
+         { NOTMUCH_OPT_KEYWORD, &exclude, "exclude", 'x',\r
+           (notmuch_keyword_t []){ { "true", EXCLUDE_TRUE },\r
+@@ -398,6 +429,11 @@ notmuch_search_command (void *ctx, int argc, char *argv[])\r
+           notmuch_query_set_omit_excluded (query, FALSE);\r
+     }\r
+ \r
++    if (output == OUTPUT_SUMMARY_WITH_IDS && format_sel == NOTMUCH_FORMAT_TEXT) {\r
++      fprintf (stderr, "Warning: --output=with-ids not implemented for text format.\n");\r
++      output = OUTPUT_SUMMARY;\r
++    }\r
++\r
+     switch (output) {\r
+     default:\r
+     case OUTPUT_SUMMARY:\r
+-- \r
+1.7.9.1\r
+\r