[PATCH 08/11] cli: add thread recipients to search output
authorJameson Graef Rollins <jrollins@finestructure.net>
Mon, 20 Aug 2012 01:52:47 +0000 (18:52 +1700)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:49:09 +0000 (09:49 -0800)
94/68b4501028f3a9312f3761444a86bd8c86a9ad [new file with mode: 0644]

diff --git a/94/68b4501028f3a9312f3761444a86bd8c86a9ad b/94/68b4501028f3a9312f3761444a86bd8c86a9ad
new file mode 100644 (file)
index 0000000..a9766df
--- /dev/null
@@ -0,0 +1,218 @@
+Return-Path: <jrollins@finestructure.net>\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 4A69E431FC0\r
+       for <notmuch@notmuchmail.org>; Sun, 19 Aug 2012 18:53:12 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -2.3\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_MED=-2.3] 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 XVHEU2ZXjptE for <notmuch@notmuchmail.org>;\r
+       Sun, 19 Aug 2012 18:53:10 -0700 (PDT)\r
+Received: from outgoing-mail.its.caltech.edu (outgoing-mail.its.caltech.edu\r
+       [131.215.239.19])\r
+       by olra.theworths.org (Postfix) with ESMTP id F34D2431FBD\r
+       for <notmuch@notmuchmail.org>; Sun, 19 Aug 2012 18:53:07 -0700 (PDT)\r
+Received: from earth-doxen.imss.caltech.edu (localhost [127.0.0.1])\r
+       by earth-doxen-postvirus (Postfix) with ESMTP id BBF3366E00DF\r
+       for <notmuch@notmuchmail.org>; Sun, 19 Aug 2012 18:53:07 -0700 (PDT)\r
+X-Spam-Scanned: at Caltech-IMSS on earth-doxen by amavisd-new\r
+Received: from finestructure.net (unknown [76.89.192.57])\r
+       (Authenticated sender: jrollins)\r
+       by earth-doxen-submit (Postfix) with ESMTP id A2A7966E00DE\r
+       for <notmuch@notmuchmail.org>; Sun, 19 Aug 2012 18:53:05 -0700 (PDT)\r
+Received: by finestructure.net (Postfix, from userid 1000)\r
+       id DE5B1CD7; Sun, 19 Aug 2012 18:53:03 -0700 (PDT)\r
+From: Jameson Graef Rollins <jrollins@finestructure.net>\r
+To: Notmuch Mail <notmuch@notmuchmail.org>\r
+Subject: [PATCH 08/11] cli: add thread recipients to search output\r
+Date: Sun, 19 Aug 2012 18:52:47 -0700\r
+Message-Id: <1345427570-26518-9-git-send-email-jrollins@finestructure.net>\r
+X-Mailer: git-send-email 1.7.10.4\r
+In-Reply-To: <1345427570-26518-8-git-send-email-jrollins@finestructure.net>\r
+References: <1345427570-26518-1-git-send-email-jrollins@finestructure.net>\r
+       <1345427570-26518-2-git-send-email-jrollins@finestructure.net>\r
+       <1345427570-26518-3-git-send-email-jrollins@finestructure.net>\r
+       <1345427570-26518-4-git-send-email-jrollins@finestructure.net>\r
+       <1345427570-26518-5-git-send-email-jrollins@finestructure.net>\r
+       <1345427570-26518-6-git-send-email-jrollins@finestructure.net>\r
+       <1345427570-26518-7-git-send-email-jrollins@finestructure.net>\r
+       <1345427570-26518-8-git-send-email-jrollins@finestructure.net>\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: Mon, 20 Aug 2012 01:53:12 -0000\r
+\r
+This adds a "--include-recipients" option to notmuch search.  With\r
+structured output formats (e.g. json), a new recipients field will be\r
+included that holds recipients of the thread.  Matched and non-matched\r
+recipients are delineated as with authors.\r
+\r
+As mentioned in the previous patch for the underlying lib functions,\r
+the need for the option is because message recipients are not stored\r
+in the database and therefore retrieving them adds a significant\r
+overhead.  If they were included, this option would not be necessary.\r
+---\r
+ lib/notmuch.h    |    6 +++++-\r
+ lib/query.cc     |    5 +++--\r
+ notmuch-search.c |   14 +++++++++++---\r
+ notmuch-show.c   |    2 +-\r
+ test/json        |    1 -\r
+ 5 files changed, 20 insertions(+), 8 deletions(-)\r
+\r
+diff --git a/lib/notmuch.h b/lib/notmuch.h\r
+index f9e71c1..8eb455e 100644\r
+--- a/lib/notmuch.h\r
++++ b/lib/notmuch.h\r
+@@ -642,6 +642,9 @@ notmuch_threads_valid (notmuch_threads_t *threads);\r
\r
+ /* Get the current thread from 'threads' as a notmuch_thread_t.\r
+  *\r
++ * If the include_recipients flag is TRUE, thread recipients will be\r
++ * included in the returned thread object.\r
++ *\r
+  * Note: The returned thread belongs to 'threads' and has a lifetime\r
+  * identical to it (and the query to which it belongs).\r
+  *\r
+@@ -652,7 +655,8 @@ notmuch_threads_valid (notmuch_threads_t *threads);\r
+  * NULL.\r
+  */\r
+ notmuch_thread_t *\r
+-notmuch_threads_get (notmuch_threads_t *threads);\r
++notmuch_threads_get (notmuch_threads_t *threads,\r
++                   notmuch_bool_t include_recipients);\r
\r
+ /* Move the 'threads' iterator to the next thread.\r
+  *\r
+diff --git a/lib/query.cc b/lib/query.cc\r
+index 54833a7..0a4f058 100644\r
+--- a/lib/query.cc\r
++++ b/lib/query.cc\r
+@@ -472,7 +472,8 @@ notmuch_threads_valid (notmuch_threads_t *threads)\r
+ }\r
\r
+ notmuch_thread_t *\r
+-notmuch_threads_get (notmuch_threads_t *threads)\r
++notmuch_threads_get (notmuch_threads_t *threads,\r
++                   notmuch_bool_t include_recipients)\r
+ {\r
+     unsigned int doc_id;\r
\r
+@@ -487,7 +488,7 @@ notmuch_threads_get (notmuch_threads_t *threads)\r
+                                  &threads->match_set,\r
+                                  threads->query->exclude_terms,\r
+                                  threads->query->sort,\r
+-                                 FALSE);\r
++                                 include_recipients);\r
+ }\r
\r
+ void\r
+diff --git a/notmuch-search.c b/notmuch-search.c\r
+index 830c4e4..f610a84 100644\r
+--- a/notmuch-search.c\r
++++ b/notmuch-search.c\r
+@@ -52,7 +52,8 @@ do_search_threads (sprinter_t *format,\r
+                  notmuch_sort_t sort,\r
+                  output_t output,\r
+                  int offset,\r
+-                 int limit)\r
++                 int limit,\r
++                 notmuch_bool_t include_recipients)\r
+ {\r
+     notmuch_thread_t *thread;\r
+     notmuch_threads_t *threads;\r
+@@ -76,7 +77,7 @@ do_search_threads (sprinter_t *format,\r
+        notmuch_threads_valid (threads) && (limit < 0 || i < offset + limit);\r
+        notmuch_threads_move_to_next (threads), i++)\r
+     {\r
+-      thread = notmuch_threads_get (threads);\r
++      thread = notmuch_threads_get (threads, include_recipients);\r
\r
+       if (i < offset) {\r
+           notmuch_thread_destroy (thread);\r
+@@ -91,6 +92,7 @@ do_search_threads (sprinter_t *format,\r
+       } else { /* output == OUTPUT_SUMMARY */\r
+           void *ctx_quote = talloc_new (thread);\r
+           const char *authors = notmuch_thread_get_authors (thread);\r
++          const char *recipients = notmuch_thread_get_recipients (thread);\r
+           const char *subject = notmuch_thread_get_subject (thread);\r
+           const char *thread_id = notmuch_thread_get_thread_id (thread);\r
+           int matched = notmuch_thread_get_matched_messages (thread);\r
+@@ -129,6 +131,10 @@ do_search_threads (sprinter_t *format,\r
+               format->integer (format, total);\r
+               format->map_key (format, "authors");\r
+               format->string (format, authors);\r
++              if (include_recipients) {\r
++                  format->map_key (format, "recipients");\r
++                  format->string (format, recipients);\r
++              }\r
+               format->map_key (format, "subject");\r
+               format->string (format, subject);\r
+           }\r
+@@ -303,6 +309,7 @@ notmuch_search_command (void *ctx, int argc, char *argv[])\r
+     int offset = 0;\r
+     int limit = -1; /* unlimited */\r
+     int exclude = EXCLUDE_TRUE;\r
++    notmuch_bool_t include_recipients = FALSE;\r
+     unsigned int i;\r
\r
+     enum { NOTMUCH_FORMAT_JSON, NOTMUCH_FORMAT_TEXT }\r
+@@ -331,6 +338,7 @@ notmuch_search_command (void *ctx, int argc, char *argv[])\r
+                                   { 0, 0 } } },\r
+       { NOTMUCH_OPT_INT, &offset, "offset", 'O', 0 },\r
+       { NOTMUCH_OPT_INT, &limit, "limit", 'L', 0  },\r
++      { NOTMUCH_OPT_BOOLEAN, &include_recipients, "include-recipients", 'r', 0 },\r
+       { 0, 0, 0, 0, 0 }\r
+     };\r
\r
+@@ -402,7 +410,7 @@ notmuch_search_command (void *ctx, int argc, char *argv[])\r
+     default:\r
+     case OUTPUT_SUMMARY:\r
+     case OUTPUT_THREADS:\r
+-      ret = do_search_threads (format, query, sort, output, offset, limit);\r
++      ret = do_search_threads (format, query, sort, output, offset, limit, include_recipients);\r
+       break;\r
+     case OUTPUT_MESSAGES:\r
+     case OUTPUT_FILES:\r
+diff --git a/notmuch-show.c b/notmuch-show.c\r
+index 3556293..cc4b428 100644\r
+--- a/notmuch-show.c\r
++++ b/notmuch-show.c\r
+@@ -965,7 +965,7 @@ do_show (void *ctx,\r
+        notmuch_threads_valid (threads);\r
+        notmuch_threads_move_to_next (threads))\r
+     {\r
+-      thread = notmuch_threads_get (threads);\r
++      thread = notmuch_threads_get (threads, FALSE);\r
\r
+       messages = notmuch_thread_get_toplevel_messages (thread);\r
\r
+diff --git a/test/json b/test/json\r
+index ac423a8..f441b59 100755\r
+--- a/test/json\r
++++ b/test/json\r
+@@ -61,7 +61,6 @@ test_expect_equal_json "$output" "[{\"thread\": \"XXX\",\r
+  \"unread\"]}]"\r
\r
+ test_begin_subtest "Search message: include recipients"\r
+-test_subtest_known_broken\r
+ output=$(notmuch search --format=json --include-recipients "json-search-message" | notmuch_search_sanitize)\r
+ test_expect_equal_json "$output" "[{\"thread\": \"XXX\",\r
+  \"timestamp\": 946728000,\r
+-- \r
+1.7.10.4\r
+\r