unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Jameson Graef Rollins <jrollins@finestructure.net>
To: Notmuch Mail <notmuch@notmuchmail.org>
Subject: [PATCH 08/11] cli: add thread recipients to search output
Date: Sun, 19 Aug 2012 18:52:47 -0700	[thread overview]
Message-ID: <1345427570-26518-9-git-send-email-jrollins@finestructure.net> (raw)
In-Reply-To: <1345427570-26518-8-git-send-email-jrollins@finestructure.net>

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

  reply	other threads:[~2012-08-20  1:53 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-20  1:52 [PATCH 00/11] add recipients to search output Jameson Graef Rollins
2012-08-20  1:52 ` [PATCH 01/11] lib: new thread addresses structure Jameson Graef Rollins
2012-08-20  1:52   ` [PATCH 02/11] lib: use new addresses structure for thread authors Jameson Graef Rollins
2012-08-20  1:52     ` [PATCH 03/11] lib: give _thread_cleanup_author a more generic name Jameson Graef Rollins
2012-08-20  1:52       ` [PATCH 04/11] lib: remove no longer needed author-specific thread functions Jameson Graef Rollins
2012-08-20  1:52         ` [PATCH 05/11] lib: add ability to store recipients in message structure Jameson Graef Rollins
2012-08-20  1:52           ` [PATCH 06/11] lib: store thread recipients in thread structure Jameson Graef Rollins
2012-08-20  1:52             ` [PATCH 07/11] test: search recipient output Jameson Graef Rollins
2012-08-20  1:52               ` Jameson Graef Rollins [this message]
2012-08-20  1:52                 ` [PATCH 09/11] emacs: add ability to show recipients instead of author in search Jameson Graef Rollins
2012-08-20  1:52                   ` [PATCH 10/11] emacs: add function to toggle showing authors/recipients " Jameson Graef Rollins
2012-08-20  1:52                     ` [PATCH 11/11] lib: add recipients to database Jameson Graef Rollins
2012-08-31 21:34                       ` Michal Sojka
2012-08-31 21:00                 ` [PATCH 08/11] cli: add thread recipients to search output Michal Sojka
2012-08-31 20:44             ` [PATCH 06/11] lib: store thread recipients in thread structure Michal Sojka
2012-09-02  7:52             ` Mark Walters
2012-09-08 17:25             ` Austin Clements
2012-08-31 20:19           ` [PATCH 05/11] lib: add ability to store recipients in message structure Michal Sojka
2012-09-08 17:24           ` Austin Clements
2012-09-08 17:25       ` [PATCH 03/11] lib: give _thread_cleanup_author a more generic name Austin Clements
2012-09-08 17:24     ` [PATCH 02/11] lib: use new addresses structure for thread authors Austin Clements
2012-08-30 15:38   ` [PATCH 01/11] lib: new thread addresses structure Michal Sojka
2012-08-30 16:33     ` Jameson Graef Rollins
2012-09-08 17:24   ` Austin Clements
2012-08-22 20:43 ` [PATCH 00/11] add recipients to search output Jameson Graef Rollins
2012-08-23  7:21 ` Tomi Ollila
2012-09-08 17:23 ` 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=1345427570-26518-9-git-send-email-jrollins@finestructure.net \
    --to=jrollins@finestructure.net \
    --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).