--- /dev/null
+Return-Path: <markwalters1009@gmail.com>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by arlo.cworth.org (Postfix) with ESMTP id 51F946DE179D\r
+ for <notmuch@notmuchmail.org>; Mon, 14 Dec 2015 09:23:15 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.266\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.266 tagged_above=-999 required=5 tests=[AWL=0.304,\r
+ DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+ FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7,\r
+ RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001]\r
+ autolearn=disabled\r
+Received: from arlo.cworth.org ([127.0.0.1])\r
+ by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id bGCt-vbPss6c for <notmuch@notmuchmail.org>;\r
+ Mon, 14 Dec 2015 09:23:13 -0800 (PST)\r
+Received: from mail-wm0-f47.google.com (mail-wm0-f47.google.com\r
+ [74.125.82.47]) by arlo.cworth.org (Postfix) with ESMTPS id 82D296DE0FB0 for\r
+ <notmuch@notmuchmail.org>; Mon, 14 Dec 2015 09:23:06 -0800 (PST)\r
+Received: by mail-wm0-f47.google.com with SMTP id p66so54448619wmp.0\r
+ for <notmuch@notmuchmail.org>; Mon, 14 Dec 2015 09:23:06 -0800 (PST)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+ h=from:to:cc:subject:date:message-id:in-reply-to:references;\r
+ bh=ipsZGs1ZgLEXYbpaTMpRWBYYwPeo3MYpsgykBe8BoC4=;\r
+ b=sC+4D2MerAT2Ym5WiZiiXQKGDmUGWpysAYHcROMocCnNbwQkNYNDTGi3ZLEGqe/1Pq\r
+ YV93PH0bVuV8WaVSvIOvlhy9D7N+ExGosidTg2GksmyXaJcYNH5WAs6k2ReZxdRHjc7j\r
+ zKxryaik7EBUpfMkVrUGfPUpMpOoI88cj9Plu0B9VaAsR9xkqKmQLeRSO372URh5Gaak\r
+ DJFPXCvbcju8a4QsBvMVtDJ4hGmzn1m7lbC/QD2H48Q+EBzZXkchq7EF1a/esKs+xGB8\r
+ 9A0UndZZfGUVsPoVW1SShYpPUrzMHc3CG8frd/QiN7X2Q5/NreGPlcuBqJOzb9rJs9Df\r
+ WKTg==\r
+X-Received: by 10.194.77.51 with SMTP id p19mr38359624wjw.159.1450113783260;\r
+ Mon, 14 Dec 2015 09:23:03 -0800 (PST)\r
+Received: from localhost (92.40.77.76.threembb.co.uk. [92.40.77.76])\r
+ by smtp.gmail.com with ESMTPSA id s11sm17180610wmb.14.2015.12.14.09.22.58\r
+ (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
+ Mon, 14 Dec 2015 09:23:00 -0800 (PST)\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v2 (rebased) 1/3] search: Separately report matching and\r
+ non-matching authors.\r
+Date: Mon, 14 Dec 2015 17:22:44 +0000\r
+Message-Id: <1450113766-20518-2-git-send-email-markwalters1009@gmail.com>\r
+X-Mailer: git-send-email 2.1.4\r
+In-Reply-To: <1450113766-20518-1-git-send-email-markwalters1009@gmail.com>\r
+References: <1450113766-20518-1-git-send-email-markwalters1009@gmail.com>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.20\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <https://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: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Mon, 14 Dec 2015 17:23:15 -0000\r
+\r
+From: David Edmondson <dme@dme.org>\r
+\r
+In addition to the 'authors' attribute of each search result, include\r
+'authors_matched' and 'authors_non_matched' attributes. Both\r
+attributes are always included and are formatted as a list of\r
+authors. If there are no matching authors, the 'authors_non_matched'\r
+attribute is set to the empty list.\r
+---\r
+ notmuch-search.c | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++++++\r
+ 1 file changed, 105 insertions(+)\r
+\r
+diff --git a/notmuch-search.c b/notmuch-search.c\r
+index 6d08c25..6c6e497 100644\r
+--- a/notmuch-search.c\r
++++ b/notmuch-search.c\r
+@@ -22,6 +22,8 @@\r
+ #include "sprinter.h"\r
+ #include "string-util.h"\r
+ \r
++#include <glib.h>\r
++\r
+ typedef enum {\r
+ /* Search command */\r
+ OUTPUT_SUMMARY = 1 << 0,\r
+@@ -109,6 +111,105 @@ get_thread_query (notmuch_thread_t *thread,\r
+ return 0;\r
+ }\r
+ \r
++/* Return a more pleasent rendering of the mail address\r
++ * `nasty_author'. */\r
++static const char *\r
++_nice_author (void *ctx, const char *nasty_author)\r
++{\r
++ const char *nice_author = NULL;\r
++\r
++ InternetAddressList *list = internet_address_list_parse_string (nasty_author);\r
++ if (list) {\r
++ InternetAddress *address = internet_address_list_get_address (list, 0);\r
++ if (address) {\r
++ nice_author = internet_address_get_name (address);\r
++ if (nice_author == NULL) {\r
++ InternetAddressMailbox *mailbox = INTERNET_ADDRESS_MAILBOX (address);\r
++ nice_author = internet_address_mailbox_get_addr (mailbox);\r
++ }\r
++ }\r
++ /* Duplicate the string before `g_object_unref' destroys\r
++ * it. */\r
++ if (nice_author)\r
++ nice_author = talloc_strdup (ctx, nice_author);\r
++\r
++ g_object_unref (G_OBJECT (list));\r
++ }\r
++\r
++ if (nice_author)\r
++ return nice_author;\r
++ else\r
++ return nasty_author;\r
++}\r
++\r
++static int\r
++_enumerate_authors (sprinter_t *format,\r
++ notmuch_thread_t *thread)\r
++{\r
++ notmuch_messages_t *messages;\r
++ GHashTable *matched_hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);\r
++ GHashTable *unmatched_hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);\r
++ GPtrArray *matched_array = g_ptr_array_new ();\r
++ GPtrArray *unmatched_array = g_ptr_array_new ();\r
++\r
++ /* Iterate over the messages in the thread collecting matching and\r
++ * non-matching authors. */\r
++ for (messages = notmuch_thread_get_messages (thread);\r
++ notmuch_messages_valid (messages);\r
++ notmuch_messages_move_to_next (messages))\r
++ {\r
++ notmuch_message_t *message = notmuch_messages_get (messages);\r
++ const char *author = _nice_author (thread, notmuch_message_get_header (message, "from"));\r
++\r
++ if (author) {\r
++ GHashTable *hash;\r
++ GPtrArray *array;\r
++\r
++ if (notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_MATCH)) {\r
++ hash = matched_hash;\r
++ array = matched_array;\r
++ } else {\r
++ hash = unmatched_hash;\r
++ array = unmatched_array;\r
++ }\r
++\r
++ if (!g_hash_table_lookup_extended (hash, author, NULL, NULL)) {\r
++ char *copy = talloc_strdup (thread, author);\r
++ g_hash_table_insert (hash, copy, NULL);\r
++ g_ptr_array_add (array, (char *) copy);\r
++ }\r
++ }\r
++ }\r
++\r
++ /* Output the matched authors. */\r
++ unsigned int i;\r
++ format->map_key (format, "authors_matched");\r
++ format->begin_list (format);\r
++ for (i = 0; i < matched_array->len; i++)\r
++ format->string (format, (char *) g_ptr_array_index( matched_array, i));\r
++ format->end (format);\r
++\r
++ /* Output the non-matched authors, but not if they were seen\r
++ * already in the matched authors list. */\r
++ format->map_key (format, "authors_non_matched");\r
++ format->begin_list (format);\r
++ for (i = 0; i < unmatched_array->len; i++) {\r
++ char *author = (char *) g_ptr_array_index( unmatched_array, i);\r
++\r
++ if (!g_hash_table_lookup_extended (matched_hash, author, NULL, NULL))\r
++ format->string (format, author);\r
++ }\r
++ format->end (format);\r
++\r
++ g_hash_table_unref (matched_hash);\r
++ g_hash_table_unref (unmatched_hash);\r
++\r
++ g_ptr_array_free (matched_array, TRUE);\r
++ g_ptr_array_free (unmatched_array, TRUE);\r
++\r
++ return 0;\r
++}\r
++\r
+ static int\r
+ do_search_threads (search_context_t *ctx)\r
+ {\r
+@@ -195,6 +296,10 @@ do_search_threads (search_context_t *ctx)\r
+ format->integer (format, total);\r
+ format->map_key (format, "authors");\r
+ format->string (format, authors);\r
++ if (_enumerate_authors (format, thread) < 0) {\r
++ fprintf (stderr, "Out of memory\n");\r
++ return 1;\r
++ }\r
+ format->map_key (format, "subject");\r
+ format->string (format, subject);\r
+ if (notmuch_format_version >= 2) {\r
+-- \r
+2.1.4\r
+\r