--- /dev/null
+Return-Path: <dme@dme.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id D70F6431FBD\r
+ for <notmuch@notmuchmail.org>; Fri, 24 Oct 2014 10:44:14 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.699\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.699 tagged_above=-999 required=5\r
+ tests=[RCVD_IN_DNSWL_LOW=-0.7, UNPARSEABLE_RELAY=0.001]\r
+ autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id tqOMfgOSZwAI for <notmuch@notmuchmail.org>;\r
+ Fri, 24 Oct 2014 10:44:09 -0700 (PDT)\r
+Received: from mail-wi0-f171.google.com (mail-wi0-f171.google.com\r
+ [209.85.212.171]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 2B129431FC9\r
+ for <notmuch@notmuchmail.org>; Fri, 24 Oct 2014 10:44:09 -0700 (PDT)\r
+Received: by mail-wi0-f171.google.com with SMTP id em10so1829387wid.4\r
+ for <notmuch@notmuchmail.org>; Fri, 24 Oct 2014 10:44:07 -0700 (PDT)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+ d=1e100.net; s=20130820;\r
+ h=x-gm-message-state:user-agent:from:to:subject:date:message-id\r
+ :in-reply-to:references;\r
+ bh=opJEioawjY0kER38ub6Pm8UXSXCZK/juFaTe6XuKjeU=;\r
+ b=RKNU4HsCAY3x+w7vMNWIPAF5Cx4PqbDE+OMT1HQ9PFlo140lxedGrj9oZvA6Q6Sd2X\r
+ SDPVdPZvm0HYyAwSSItbPa33IvdjoMAOWLgFdtlYwkuwuV2VuKAto8vLyC+A+A2KrCDt\r
+ 8bXTGEmNbn239MgqZlXBbPmacnHIuhQz0ajEf4auDwhbtnOKBtJH5PPk18u/ggcdTEkJ\r
+ Ujd1jiIb98WD2WpWrqVIotPm1SDjDDaaGVZgjmKFwM0Bd6AkXdzdP2urfR+8W0sq0vja\r
+ 7eG4FIKyWYyHtI7a94BsOkIoK+u3xcIAd474iCi0MiAOnzkQmS4Z66DRKnJE3SIPEfWE\r
+ /fDQ==\r
+X-Gm-Message-State:\r
+ ALoCoQlfZ17TPby3V3zqcOLzVS1KypQf7CYbvpsn7lwdqCKH2fda+8o7EhMJY63EqqSyTbmARnwt\r
+X-Received: by 10.194.5.227 with SMTP id v3mr6439097wjv.63.1414172647609;\r
+ Fri, 24 Oct 2014 10:44:07 -0700 (PDT)\r
+Received: from disaster-area.hh.sledj.net (disaster-area.hh.sledj.net.\r
+ [81.149.164.25])\r
+ by mx.google.com with ESMTPSA id dq7sm2726263wid.12.2014.10.24.10.44.06\r
+ for <notmuch@notmuchmail.org>\r
+ (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
+ Fri, 24 Oct 2014 10:44:07 -0700 (PDT)\r
+Received: from localhost (30000@localhost [local]);\r
+ by localhost (OpenSMTPD) with ESMTPA id b52aed99;\r
+ for <notmuch@notmuchmail.org>; Fri, 24 Oct 2014 17:44:03 +0000 (UTC)\r
+User-Agent: OpenSMTPD enqueuer (Demoostik)\r
+From: David Edmondson <dme@dme.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v2 1/3] search: Separately report matching and non-matching\r
+ authors.\r
+Date: Fri, 24 Oct 2014 18:44:01 +0100\r
+Message-Id: <1414172643-28270-2-git-send-email-dme@dme.org>\r
+X-Mailer: git-send-email 2.1.1\r
+In-Reply-To: <1414172643-28270-1-git-send-email-dme@dme.org>\r
+References: <1414172643-28270-1-git-send-email-dme@dme.org>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://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: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Fri, 24 Oct 2014 17:44:15 -0000\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 bc9be45..18c3b20 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
+ OUTPUT_SUMMARY,\r
+ OUTPUT_THREADS,\r
+@@ -69,6 +71,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 (sprinter_t *format,\r
+ notmuch_query_t *query,\r
+@@ -152,6 +253,10 @@ do_search_threads (sprinter_t *format,\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.1\r
+\r