In addition to the :authors attribute of each search result, include
:authors_matched and :authors_non_matched attributes. Both attributes
are always included. If there are no non-matching authors, the
:authors_non_matched attribute is set to the empty string.
---
 lib/notmuch.h    | 34 ++++++++++++++++++++++++++++++++
 lib/thread.cc    | 60 +++++++++++++++++++++++++++++++++++++++-----------------
 notmuch-search.c |  6 ++++++
 3 files changed, 82 insertions(+), 18 deletions(-)

diff --git a/lib/notmuch.h b/lib/notmuch.h
index dae0416..30ce6c3 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -993,6 +993,40 @@ const char *
 notmuch_thread_get_authors (notmuch_thread_t *thread);
 
 /**
+ * Get the matched authors of 'thread' as a UTF-8 string.
+ *
+ * The returned string is a comma-separated list of the names of the
+ * authors of mail messages in the query results that belong to this
+ * thread.
+ *
+ * Authors are ordered by date.
+ *
+ * The returned string belongs to 'thread' and as such, should not be
+ * modified by the caller and will only be valid for as long as the
+ * thread is valid, (which is until notmuch_thread_destroy or until
+ * the query from which it derived is destroyed).
+ */
+const char *
+notmuch_thread_get_authors_matched (notmuch_thread_t *thread);
+
+/**
+ * Get the non-matched authors of 'thread' as a UTF-8 string.
+ *
+ * The returned string is a comma-separated list of the names of the
+ * authors of mail messages in the query results that belong to this
+ * thread.
+ *
+ * Authors are ordered by date.
+ *
+ * The returned string belongs to 'thread' and as such, should not be
+ * modified by the caller and will only be valid for as long as the
+ * thread is valid, (which is until notmuch_thread_destroy or until
+ * the query from which it derived is destroyed).
+ */
+const char *
+notmuch_thread_get_authors_non_matched (notmuch_thread_t *thread);
+
+/**
  * Get the subject of 'thread' as a UTF-8 string.
  *
  * The subject is taken from the first message (according to the query
diff --git a/lib/thread.cc b/lib/thread.cc
index 8922403..b344875 100644
--- a/lib/thread.cc
+++ b/lib/thread.cc
@@ -33,6 +33,8 @@ struct visible _notmuch_thread {
     GHashTable *matched_authors_hash;
     GPtrArray *matched_authors_array;
     char *authors;
+    char *authors_matched;
+    char *authors_non_matched;
     GHashTable *tags;
 
     /* All messages, oldest first. */
@@ -112,10 +114,11 @@ _thread_add_matched_author (notmuch_thread_t *thread,
     g_ptr_array_add (thread->matched_authors_array, author_copy);
 }
 
-/* Construct an authors string from matched_authors_array and
- * authors_array. The string contains matched authors first, then
- * non-matched authors (with the two groups separated by '|'). Within
- * each group, authors are listed in date order. */
+/* Construct the authors_matched, authors_non_matched and authors
+ * strings from matched_authors_array and authors_array. The authors
+ * string contains matched authors first, then non-matched authors
+ * (with the two groups separated by '|'). Within each group, authors
+ * are listed in date order. */
 static void
 _resolve_thread_authors_string (notmuch_thread_t *thread)
 {
@@ -123,36 +126,43 @@ _resolve_thread_authors_string (notmuch_thread_t *thread)
     char *author;
     int first_non_matched_author = 1;
 
-    /* First, list all matched authors in date order. */
+    /* List all matched authors in date order. */
     for (i = 0; i < thread->matched_authors_array->len; i++) {
        author = (char *) g_ptr_array_index (thread->matched_authors_array, i);
-       if (thread->authors)
-           thread->authors = talloc_asprintf (thread, "%s, %s",
-                                              thread->authors,
-                                              author);
-       else
-           thread->authors = author;
+       if (thread->authors_matched) {
+           thread->authors_matched = talloc_asprintf (thread, "%s, %s",
+                                                      thread->authors_matched,
+                                                      author);
+       } else {
+           thread->authors_matched = author;
+       }
     }
 
-    /* Next, append any non-matched authors that haven't already appeared. */
+    /* List any non-matched authors that haven't already appeared. */
     for (i = 0; i < thread->authors_array->len; i++) {
        author = (char *) g_ptr_array_index (thread->authors_array, i);
        if (g_hash_table_lookup_extended (thread->matched_authors_hash,
                                          author, NULL, NULL))
            continue;
        if (first_non_matched_author) {
-           thread->authors = talloc_asprintf (thread, "%s| %s",
-                                              thread->authors,
-                                              author);
+           thread->authors_non_matched = author;
        } else {
-           thread->authors = talloc_asprintf (thread, "%s, %s",
-                                              thread->authors,
-                                              author);
+           thread->authors_non_matched = talloc_asprintf (thread, "%s, %s",
+                                                          
thread->authors_non_matched,
+                                                          author);
        }
 
        first_non_matched_author = 0;
     }
 
+    /* List both matched and any non-matched authors. */
+    if (thread->authors_non_matched)
+       thread->authors = talloc_asprintf (thread, "%s| %s",
+                                          thread->authors_matched,
+                                          thread->authors_non_matched);
+    else
+       thread->authors = thread->authors_matched;
+
     g_ptr_array_free (thread->authors_array, TRUE);
     thread->authors_array = NULL;
     g_ptr_array_free (thread->matched_authors_array, TRUE);
@@ -473,6 +483,8 @@ _notmuch_thread_create (void *ctx,
                                                          NULL, NULL);
     thread->matched_authors_array = g_ptr_array_new ();
     thread->authors = NULL;
+    thread->authors_matched = NULL;
+    thread->authors_non_matched = NULL;
     thread->tags = g_hash_table_new_full (g_str_hash, g_str_equal,
                                          free, NULL);
 
@@ -568,6 +580,18 @@ notmuch_thread_get_authors (notmuch_thread_t *thread)
 }
 
 const char *
+notmuch_thread_get_authors_matched (notmuch_thread_t *thread)
+{
+    return thread->authors_matched;
+}
+
+const char *
+notmuch_thread_get_authors_non_matched (notmuch_thread_t *thread)
+{
+    return thread->authors_non_matched;
+}
+
+const char *
 notmuch_thread_get_subject (notmuch_thread_t *thread)
 {
     return thread->subject;
diff --git a/notmuch-search.c b/notmuch-search.c
index bc9be45..f1b096d 100644
--- a/notmuch-search.c
+++ b/notmuch-search.c
@@ -114,6 +114,8 @@ 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 *authors_matched = notmuch_thread_get_authors_matched 
(thread);
+           const char *authors_non_matched = 
notmuch_thread_get_authors_non_matched (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);
@@ -152,6 +154,10 @@ do_search_threads (sprinter_t *format,
                format->integer (format, total);
                format->map_key (format, "authors");
                format->string (format, authors);
+               format->map_key (format, "authors_matched");
+               format->string (format, authors_matched);
+               format->map_key (format, "authors_non_matched");
+               format->string (format, authors_non_matched);
                format->map_key (format, "subject");
                format->string (format, subject);
                if (notmuch_format_version >= 2) {
-- 
2.1.1

_______________________________________________
notmuch mailing list
[email protected]
http://notmuchmail.org/mailman/listinfo/notmuch

Reply via email to