[PATCH 08/11] cli: add thread recipients to search output

Jameson Graef Rollins jrollins at finestructure.net
Sun Aug 19 18:52:47 PDT 2012


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



More information about the notmuch mailing list