Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 1E683431FB6 for ; Mon, 19 Jan 2015 01:15:00 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 1.739 X-Spam-Level: * X-Spam-Status: No, score=1.739 tagged_above=-999 required=5 tests=[DNS_FROM_AHBL_RHSBL=2.438, RCVD_IN_DNSWL_LOW=-0.7, UNPARSEABLE_RELAY=0.001] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 56YoD3jwHBAG for ; Mon, 19 Jan 2015 01:14:57 -0800 (PST) Received: from mail-wg0-f45.google.com (mail-wg0-f45.google.com [74.125.82.45]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 1CEBB431FAF for ; Mon, 19 Jan 2015 01:14:57 -0800 (PST) Received: by mail-wg0-f45.google.com with SMTP id y19so30579762wgg.4 for ; Mon, 19 Jan 2015 01:14:52 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:to:subject:in-reply-to:references:user-agent :from:date:message-id:mime-version:content-type; bh=k/AkbE/POg66ByQx1o/X/0SAj6ZL/mRShmtG/6IMDlk=; b=TWtkXEPRHEt84vq8JTkxjUOAWHpK+anlPfjEYLWoBRRWrKcPq1blVbtMEx9gTqp667 jNv1PHqo5jioOg6gUzXKNdWO4+8al+FRLejAJji/ROf4dsbQqULERqUrYZOIrkXYHsYB b//Fgp55pWEJ/vg4rXAtKnwi9IMzrXDndGHcfzJ88ffMx5BKzTkhGVvD9KmrP/KTyLRO zhPxiZbXOhDMpdx6Uf2FAzvfs8VqOO2d8xaHHc5rdkMWcqh8gpaqAazDU+4NaHQ52YBY 5aQ8n97jae8Bwu1BCyMM4AbVc6tg4opiyqhsMDN+6m+RDF7dx10+CC8Hxx+DpHOCx8Zx Tu/A== X-Gm-Message-State: ALoCoQmTYeSt8etqkApq1QHMIkKtYDYla2W9mhKPbI/zXehrsDiH/+GSyc+KQzgDYN+vQJEzf6nv X-Received: by 10.180.83.129 with SMTP id q1mr33065141wiy.8.1421658891341; Mon, 19 Jan 2015 01:14:51 -0800 (PST) Received: from disaster-area.hh.sledj.net ([2a01:348:1a2:1:ea39:35ff:fe2c:a227]) by mx.google.com with ESMTPSA id gu5sm13360570wib.24.2015.01.19.01.14.50 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Jan 2015 01:14:50 -0800 (PST) Received: from localhost (30000@localhost [local]); by localhost (OpenSMTPD) with ESMTPA id 1ec861d2; Mon, 19 Jan 2015 09:14:48 +0000 (UTC) To: Mark Walters , notmuch@notmuchmail.org Subject: Re: [PATCH v2 1/3] search: Separately report matching and non-matching authors. In-Reply-To: <87r3usj7fo.fsf@qmul.ac.uk> References: <1414172643-28270-1-git-send-email-dme@dme.org> <1414172643-28270-2-git-send-email-dme@dme.org> <87r3usj7fo.fsf@qmul.ac.uk> User-Agent: none From: David Edmondson Date: Mon, 19 Jan 2015 09:14:48 +0000 Message-ID: MIME-Version: 1.0 Content-Type: text/plain X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 19 Jan 2015 09:15:00 -0000 On Sun, Jan 18 2015, Mark Walters wrote: > On Fri, 24 Oct 2014, David Edmondson wrote: >> In addition to the 'authors' attribute of each search result, include >> 'authors_matched' and 'authors_non_matched' attributes. Both >> attributes are always included and are formatted as a list of >> authors. If there are no matching authors, the 'authors_non_matched' >> attribute is set to the empty list. > > Hi > > Sorry to be so slow reviewing this. Would it be possible to do the > matching/non-matching stuff in lib/thread.cc and just call that from > notmuch-search.c? I guess you would need to add a matched_authors, and > unmatched_authors string to the notmuch_thread struct. > > Doing this in search.c seems to redo things that the thread code is > already doing but maybe I don't really know this code. Is that different to what I did originally? Austin suggested the approach in this version (id:20141024124016.GG7970@csail.mit.edu), unless I misunderstood him. > Best wishes > > Mark > >> --- >> notmuch-search.c | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ >> 1 file changed, 105 insertions(+) >> >> diff --git a/notmuch-search.c b/notmuch-search.c >> index bc9be45..18c3b20 100644 >> --- a/notmuch-search.c >> +++ b/notmuch-search.c >> @@ -22,6 +22,8 @@ >> #include "sprinter.h" >> #include "string-util.h" >> >> +#include >> + >> typedef enum { >> OUTPUT_SUMMARY, >> OUTPUT_THREADS, >> @@ -69,6 +71,105 @@ get_thread_query (notmuch_thread_t *thread, >> return 0; >> } >> >> +/* Return a more pleasent rendering of the mail address >> + * `nasty_author'. */ >> +static const char * >> +_nice_author (void *ctx, const char *nasty_author) >> +{ >> + const char *nice_author = NULL; >> + >> + InternetAddressList *list = internet_address_list_parse_string (nasty_author); >> + if (list) { >> + InternetAddress *address = internet_address_list_get_address (list, 0); >> + if (address) { >> + nice_author = internet_address_get_name (address); >> + if (nice_author == NULL) { >> + InternetAddressMailbox *mailbox = INTERNET_ADDRESS_MAILBOX (address); >> + nice_author = internet_address_mailbox_get_addr (mailbox); >> + } >> + } >> + /* Duplicate the string before `g_object_unref' destroys >> + * it. */ >> + if (nice_author) >> + nice_author = talloc_strdup (ctx, nice_author); >> + >> + g_object_unref (G_OBJECT (list)); >> + } >> + >> + if (nice_author) >> + return nice_author; >> + else >> + return nasty_author; >> +} >> + >> +static int >> +_enumerate_authors (sprinter_t *format, >> + notmuch_thread_t *thread) >> +{ >> + notmuch_messages_t *messages; >> + GHashTable *matched_hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL); >> + GHashTable *unmatched_hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL); >> + GPtrArray *matched_array = g_ptr_array_new (); >> + GPtrArray *unmatched_array = g_ptr_array_new (); >> + >> + /* Iterate over the messages in the thread collecting matching and >> + * non-matching authors. */ >> + for (messages = notmuch_thread_get_messages (thread); >> + notmuch_messages_valid (messages); >> + notmuch_messages_move_to_next (messages)) >> + { >> + notmuch_message_t *message = notmuch_messages_get (messages); >> + const char *author = _nice_author (thread, notmuch_message_get_header (message, "from")); >> + >> + if (author) { >> + GHashTable *hash; >> + GPtrArray *array; >> + >> + if (notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_MATCH)) { >> + hash = matched_hash; >> + array = matched_array; >> + } else { >> + hash = unmatched_hash; >> + array = unmatched_array; >> + } >> + >> + if (!g_hash_table_lookup_extended (hash, author, NULL, NULL)) { >> + char *copy = talloc_strdup (thread, author); >> + g_hash_table_insert (hash, copy, NULL); >> + g_ptr_array_add (array, (char *) copy); >> + } >> + } >> + } >> + >> + /* Output the matched authors. */ >> + unsigned int i; >> + format->map_key (format, "authors_matched"); >> + format->begin_list (format); >> + for (i = 0; i < matched_array->len; i++) >> + format->string (format, (char *) g_ptr_array_index( matched_array, i)); >> + format->end (format); >> + >> + /* Output the non-matched authors, but not if they were seen >> + * already in the matched authors list. */ >> + format->map_key (format, "authors_non_matched"); >> + format->begin_list (format); >> + for (i = 0; i < unmatched_array->len; i++) { >> + char *author = (char *) g_ptr_array_index( unmatched_array, i); >> + >> + if (!g_hash_table_lookup_extended (matched_hash, author, NULL, NULL)) >> + format->string (format, author); >> + } >> + format->end (format); >> + >> + g_hash_table_unref (matched_hash); >> + g_hash_table_unref (unmatched_hash); >> + >> + g_ptr_array_free (matched_array, TRUE); >> + g_ptr_array_free (unmatched_array, TRUE); >> + >> + return 0; >> +} >> + >> static int >> do_search_threads (sprinter_t *format, >> notmuch_query_t *query, >> @@ -152,6 +253,10 @@ do_search_threads (sprinter_t *format, >> format->integer (format, total); >> format->map_key (format, "authors"); >> format->string (format, authors); >> + if (_enumerate_authors (format, thread) < 0) { >> + fprintf (stderr, "Out of memory\n"); >> + return 1; >> + } >> format->map_key (format, "subject"); >> format->string (format, subject); >> if (notmuch_format_version >= 2) { >> -- >> 2.1.1 >> >> _______________________________________________ >> notmuch mailing list >> notmuch@notmuchmail.org >> http://notmuchmail.org/mailman/listinfo/notmuch