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 A5680431FB6 for ; Sun, 18 Jan 2015 09:59:49 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 1.34 X-Spam-Level: * X-Spam-Status: No, score=1.34 tagged_above=-999 required=5 tests=[DKIM_ADSP_CUSTOM_MED=0.001, DNS_FROM_AHBL_RHSBL=2.438, FREEMAIL_FROM=0.001, NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3] 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 xCOix0zjQp57 for ; Sun, 18 Jan 2015 09:59:46 -0800 (PST) Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id E2BCB431FAF for ; Sun, 18 Jan 2015 09:59:45 -0800 (PST) Received: from smtp.qmul.ac.uk ([138.37.6.40]) by mail2.qmul.ac.uk with esmtp (Exim 4.71) (envelope-from ) id 1YCu8N-0002xL-VU; Sun, 18 Jan 2015 17:59:38 +0000 Received: from 5751dfa2.skybroadband.com ([87.81.223.162] helo=localhost) by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.71) (envelope-from ) id 1YCu8N-0004Ia-Ld; Sun, 18 Jan 2015 17:59:35 +0000 From: Mark Walters To: David Edmondson , notmuch@notmuchmail.org Subject: Re: [PATCH v2 1/3] search: Separately report matching and non-matching authors. In-Reply-To: <1414172643-28270-2-git-send-email-dme@dme.org> References: <1414172643-28270-1-git-send-email-dme@dme.org> <1414172643-28270-2-git-send-email-dme@dme.org> User-Agent: Notmuch/0.18.1+86~gef5e66a (http://notmuchmail.org) Emacs/24.4.1 (x86_64-pc-linux-gnu) Date: Sun, 18 Jan 2015 17:59:55 +0000 Message-ID: <87r3usj7fo.fsf@qmul.ac.uk> MIME-Version: 1.0 Content-Type: text/plain X-Sender-Host-Address: 87.81.223.162 X-QM-Geographic: According to ripencc, this message was delivered by a machine in Britain (UK) (GB). X-QM-SPAM-Info: Sender has good ham record. :) X-QM-Body-MD5: e22bb0a357938a396ce416587c0fec7f (of first 20000 bytes) X-SpamAssassin-Score: -0.0 X-SpamAssassin-SpamBar: / X-SpamAssassin-Report: The QM spam filters have analysed this message to determine if it is spam. We require at least 5.0 points to mark a message as spam. This message scored -0.0 points. Summary of the scoring: * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider * (markwalters1009[at]gmail.com) * -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay * domain X-QM-Scan-Virus: ClamAV says the message is clean 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: Sun, 18 Jan 2015 17:59:49 -0000 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. 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