Re: [PATCH v2 1/3] search: Separately report matching and non-matching authors.
authorDavid Edmondson <dme@dme.org>
Mon, 19 Jan 2015 09:14:48 +0000 (09:14 +0000)
committerW. Trevor King <wking@tremily.us>
Sat, 20 Aug 2016 21:47:36 +0000 (14:47 -0700)
ab/f45141a90fe36d56625823d0c340db810a3dd6 [new file with mode: 0644]

diff --git a/ab/f45141a90fe36d56625823d0c340db810a3dd6 b/ab/f45141a90fe36d56625823d0c340db810a3dd6
new file mode 100644 (file)
index 0000000..7510315
--- /dev/null
@@ -0,0 +1,242 @@
+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 1E683431FB6\r
+       for <notmuch@notmuchmail.org>; Mon, 19 Jan 2015 01:15:00 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 1.739\r
+X-Spam-Level: *\r
+X-Spam-Status: No, score=1.739 tagged_above=-999 required=5\r
+       tests=[DNS_FROM_AHBL_RHSBL=2.438, RCVD_IN_DNSWL_LOW=-0.7,\r
+       UNPARSEABLE_RELAY=0.001] 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 56YoD3jwHBAG for <notmuch@notmuchmail.org>;\r
+       Mon, 19 Jan 2015 01:14:57 -0800 (PST)\r
+Received: from mail-wg0-f45.google.com (mail-wg0-f45.google.com\r
+ [74.125.82.45])       (using TLSv1 with cipher RC4-SHA (128/128 bits))        (No client\r
+ certificate requested)        by olra.theworths.org (Postfix) with ESMTPS id\r
+ 1CEBB431FAF   for <notmuch@notmuchmail.org>; Mon, 19 Jan 2015 01:14:57 -0800\r
+ (PST)\r
+Received: by mail-wg0-f45.google.com with SMTP id y19so30579762wgg.4\r
+       for <notmuch@notmuchmail.org>; Mon, 19 Jan 2015 01:14:52 -0800 (PST)\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:to:subject:in-reply-to:references:user-agent\r
+       :from:date:message-id:mime-version:content-type;\r
+       bh=k/AkbE/POg66ByQx1o/X/0SAj6ZL/mRShmtG/6IMDlk=;\r
+       b=TWtkXEPRHEt84vq8JTkxjUOAWHpK+anlPfjEYLWoBRRWrKcPq1blVbtMEx9gTqp667\r
+       jNv1PHqo5jioOg6gUzXKNdWO4+8al+FRLejAJji/ROf4dsbQqULERqUrYZOIrkXYHsYB\r
+       b//Fgp55pWEJ/vg4rXAtKnwi9IMzrXDndGHcfzJ88ffMx5BKzTkhGVvD9KmrP/KTyLRO\r
+       zhPxiZbXOhDMpdx6Uf2FAzvfs8VqOO2d8xaHHc5rdkMWcqh8gpaqAazDU+4NaHQ52YBY\r
+       5aQ8n97jae8Bwu1BCyMM4AbVc6tg4opiyqhsMDN+6m+RDF7dx10+CC8Hxx+DpHOCx8Zx\r
+       Tu/A==\r
+X-Gm-Message-State:\r
+ ALoCoQmTYeSt8etqkApq1QHMIkKtYDYla2W9mhKPbI/zXehrsDiH/+GSyc+KQzgDYN+vQJEzf6nv\r
+X-Received: by 10.180.83.129 with SMTP id q1mr33065141wiy.8.1421658891341;\r
+       Mon, 19 Jan 2015 01:14:51 -0800 (PST)\r
+Received: from disaster-area.hh.sledj.net\r
+       ([2a01:348:1a2:1:ea39:35ff:fe2c:a227])\r
+       by mx.google.com with ESMTPSA id\r
+       gu5sm13360570wib.24.2015.01.19.01.14.50\r
+       (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
+       Mon, 19 Jan 2015 01:14:50 -0800 (PST)\r
+Received: from localhost (30000@localhost [local]);\r
+       by localhost (OpenSMTPD) with ESMTPA id 1ec861d2;\r
+       Mon, 19 Jan 2015 09:14:48 +0000 (UTC)\r
+To: Mark Walters <markwalters1009@gmail.com>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH v2 1/3] search: Separately report matching and\r
+       non-matching    authors.\r
+In-Reply-To: <87r3usj7fo.fsf@qmul.ac.uk>\r
+References: <1414172643-28270-1-git-send-email-dme@dme.org>\r
+       <1414172643-28270-2-git-send-email-dme@dme.org>\r
+       <87r3usj7fo.fsf@qmul.ac.uk>\r
+User-Agent: none\r
+From: David Edmondson <dme@dme.org>\r
+Date: Mon, 19 Jan 2015 09:14:48 +0000\r
+Message-ID: <cunfvb7ku7r.fsf@gargravarr.hh.sledj.net>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain\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: Mon, 19 Jan 2015 09:15:00 -0000\r
+\r
+On Sun, Jan 18 2015, Mark Walters wrote:\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
+Is that different to what I did originally? Austin suggested the\r
+approach in this version (id:20141024124016.GG7970@csail.mit.edu),\r
+unless I misunderstood him.\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