--- /dev/null
+Return-Path: <m.walters@qmul.ac.uk>\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 A5680431FB6\r
+ for <notmuch@notmuchmail.org>; Sun, 18 Jan 2015 09:59:49 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 1.34\r
+X-Spam-Level: *\r
+X-Spam-Status: No, score=1.34 tagged_above=-999 required=5\r
+ tests=[DKIM_ADSP_CUSTOM_MED=0.001, DNS_FROM_AHBL_RHSBL=2.438,\r
+ FREEMAIL_FROM=0.001, NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3]\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 xCOix0zjQp57 for <notmuch@notmuchmail.org>;\r
+ Sun, 18 Jan 2015 09:59:46 -0800 (PST)\r
+Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6])\r
+ (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id E2BCB431FAF\r
+ for <notmuch@notmuchmail.org>; Sun, 18 Jan 2015 09:59:45 -0800 (PST)\r
+Received: from smtp.qmul.ac.uk ([138.37.6.40])\r
+ by mail2.qmul.ac.uk with esmtp (Exim 4.71)\r
+ (envelope-from <m.walters@qmul.ac.uk>)\r
+ id 1YCu8N-0002xL-VU; Sun, 18 Jan 2015 17:59:38 +0000\r
+Received: from 5751dfa2.skybroadband.com ([87.81.223.162] helo=localhost)\r
+ by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.71)\r
+ (envelope-from <m.walters@qmul.ac.uk>)\r
+ id 1YCu8N-0004Ia-Ld; Sun, 18 Jan 2015 17:59:35 +0000\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: David Edmondson <dme@dme.org>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH v2 1/3] search: Separately report matching and\r
+ non-matching authors.\r
+In-Reply-To: <1414172643-28270-2-git-send-email-dme@dme.org>\r
+References: <1414172643-28270-1-git-send-email-dme@dme.org>\r
+ <1414172643-28270-2-git-send-email-dme@dme.org>\r
+User-Agent: Notmuch/0.18.1+86~gef5e66a (http://notmuchmail.org) Emacs/24.4.1\r
+ (x86_64-pc-linux-gnu)\r
+Date: Sun, 18 Jan 2015 17:59:55 +0000\r
+Message-ID: <87r3usj7fo.fsf@qmul.ac.uk>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain\r
+X-Sender-Host-Address: 87.81.223.162\r
+X-QM-Geographic: According to ripencc,\r
+ this message was delivered by a machine in Britain (UK) (GB).\r
+X-QM-SPAM-Info: Sender has good ham record. :)\r
+X-QM-Body-MD5: e22bb0a357938a396ce416587c0fec7f (of first 20000 bytes)\r
+X-SpamAssassin-Score: -0.0\r
+X-SpamAssassin-SpamBar: /\r
+X-SpamAssassin-Report: The QM spam filters have analysed this message to\r
+ determine if it is\r
+ spam. We require at least 5.0 points to mark a message as spam.\r
+ This message scored -0.0 points.\r
+ Summary of the scoring: \r
+ * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail\r
+ provider * (markwalters1009[at]gmail.com)\r
+ * -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay\r
+ * domain\r
+X-QM-Scan-Virus: ClamAV says the message is clean\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: Sun, 18 Jan 2015 17:59:49 -0000\r
+\r
+On Fri, 24 Oct 2014, David Edmondson <dme@dme.org> wrote:\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
+Hi\r
+\r
+Sorry to be so slow reviewing this. Would it be possible to do the\r
+matching/non-matching stuff in lib/thread.cc and just call that from\r
+notmuch-search.c? I guess you would need to add a matched_authors, and\r
+unmatched_authors string to the notmuch_thread struct.\r
+\r
+Doing this in search.c seems to redo things that the thread code is\r
+already doing but maybe I don't really know this code.\r
+\r
+Best wishes\r
+\r
+Mark\r
+\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
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r