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