1 Return-Path: <dme@dme.org>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id D70F6431FBD
\r
6 for <notmuch@notmuchmail.org>; Fri, 24 Oct 2014 10:44:14 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-0.699 tagged_above=-999 required=5
\r
12 tests=[RCVD_IN_DNSWL_LOW=-0.7, UNPARSEABLE_RELAY=0.001]
\r
14 Received: from olra.theworths.org ([127.0.0.1])
\r
15 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
16 with ESMTP id tqOMfgOSZwAI for <notmuch@notmuchmail.org>;
\r
17 Fri, 24 Oct 2014 10:44:09 -0700 (PDT)
\r
18 Received: from mail-wi0-f171.google.com (mail-wi0-f171.google.com
\r
19 [209.85.212.171]) (using TLSv1 with cipher RC4-SHA (128/128 bits))
\r
20 (No client certificate requested)
\r
21 by olra.theworths.org (Postfix) with ESMTPS id 2B129431FC9
\r
22 for <notmuch@notmuchmail.org>; Fri, 24 Oct 2014 10:44:09 -0700 (PDT)
\r
23 Received: by mail-wi0-f171.google.com with SMTP id em10so1829387wid.4
\r
24 for <notmuch@notmuchmail.org>; Fri, 24 Oct 2014 10:44:07 -0700 (PDT)
\r
25 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
\r
26 d=1e100.net; s=20130820;
\r
27 h=x-gm-message-state:user-agent:from:to:subject:date:message-id
\r
28 :in-reply-to:references;
\r
29 bh=opJEioawjY0kER38ub6Pm8UXSXCZK/juFaTe6XuKjeU=;
\r
30 b=RKNU4HsCAY3x+w7vMNWIPAF5Cx4PqbDE+OMT1HQ9PFlo140lxedGrj9oZvA6Q6Sd2X
\r
31 SDPVdPZvm0HYyAwSSItbPa33IvdjoMAOWLgFdtlYwkuwuV2VuKAto8vLyC+A+A2KrCDt
\r
32 8bXTGEmNbn239MgqZlXBbPmacnHIuhQz0ajEf4auDwhbtnOKBtJH5PPk18u/ggcdTEkJ
\r
33 Ujd1jiIb98WD2WpWrqVIotPm1SDjDDaaGVZgjmKFwM0Bd6AkXdzdP2urfR+8W0sq0vja
\r
34 7eG4FIKyWYyHtI7a94BsOkIoK+u3xcIAd474iCi0MiAOnzkQmS4Z66DRKnJE3SIPEfWE
\r
37 ALoCoQlfZ17TPby3V3zqcOLzVS1KypQf7CYbvpsn7lwdqCKH2fda+8o7EhMJY63EqqSyTbmARnwt
\r
38 X-Received: by 10.194.5.227 with SMTP id v3mr6439097wjv.63.1414172647609;
\r
39 Fri, 24 Oct 2014 10:44:07 -0700 (PDT)
\r
40 Received: from disaster-area.hh.sledj.net (disaster-area.hh.sledj.net.
\r
42 by mx.google.com with ESMTPSA id dq7sm2726263wid.12.2014.10.24.10.44.06
\r
43 for <notmuch@notmuchmail.org>
\r
44 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
\r
45 Fri, 24 Oct 2014 10:44:07 -0700 (PDT)
\r
46 Received: from localhost (30000@localhost [local]);
\r
47 by localhost (OpenSMTPD) with ESMTPA id b52aed99;
\r
48 for <notmuch@notmuchmail.org>; Fri, 24 Oct 2014 17:44:03 +0000 (UTC)
\r
49 User-Agent: OpenSMTPD enqueuer (Demoostik)
\r
50 From: David Edmondson <dme@dme.org>
\r
51 To: notmuch@notmuchmail.org
\r
52 Subject: [PATCH v2 1/3] search: Separately report matching and non-matching
\r
54 Date: Fri, 24 Oct 2014 18:44:01 +0100
\r
55 Message-Id: <1414172643-28270-2-git-send-email-dme@dme.org>
\r
56 X-Mailer: git-send-email 2.1.1
\r
57 In-Reply-To: <1414172643-28270-1-git-send-email-dme@dme.org>
\r
58 References: <1414172643-28270-1-git-send-email-dme@dme.org>
\r
59 X-BeenThere: notmuch@notmuchmail.org
\r
60 X-Mailman-Version: 2.1.13
\r
62 List-Id: "Use and development of the notmuch mail system."
\r
63 <notmuch.notmuchmail.org>
\r
64 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
65 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
66 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
67 List-Post: <mailto:notmuch@notmuchmail.org>
\r
68 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
69 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
70 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
71 X-List-Received-Date: Fri, 24 Oct 2014 17:44:15 -0000
\r
73 In addition to the 'authors' attribute of each search result, include
\r
74 'authors_matched' and 'authors_non_matched' attributes. Both
\r
75 attributes are always included and are formatted as a list of
\r
76 authors. If there are no matching authors, the 'authors_non_matched'
\r
77 attribute is set to the empty list.
\r
79 notmuch-search.c | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
\r
80 1 file changed, 105 insertions(+)
\r
82 diff --git a/notmuch-search.c b/notmuch-search.c
\r
83 index bc9be45..18c3b20 100644
\r
84 --- a/notmuch-search.c
\r
85 +++ b/notmuch-search.c
\r
87 #include "sprinter.h"
\r
88 #include "string-util.h"
\r
95 @@ -69,6 +71,105 @@ get_thread_query (notmuch_thread_t *thread,
\r
99 +/* Return a more pleasent rendering of the mail address
\r
100 + * `nasty_author'. */
\r
101 +static const char *
\r
102 +_nice_author (void *ctx, const char *nasty_author)
\r
104 + const char *nice_author = NULL;
\r
106 + InternetAddressList *list = internet_address_list_parse_string (nasty_author);
\r
108 + InternetAddress *address = internet_address_list_get_address (list, 0);
\r
110 + nice_author = internet_address_get_name (address);
\r
111 + if (nice_author == NULL) {
\r
112 + InternetAddressMailbox *mailbox = INTERNET_ADDRESS_MAILBOX (address);
\r
113 + nice_author = internet_address_mailbox_get_addr (mailbox);
\r
116 + /* Duplicate the string before `g_object_unref' destroys
\r
119 + nice_author = talloc_strdup (ctx, nice_author);
\r
121 + g_object_unref (G_OBJECT (list));
\r
125 + return nice_author;
\r
127 + return nasty_author;
\r
131 +_enumerate_authors (sprinter_t *format,
\r
132 + notmuch_thread_t *thread)
\r
134 + notmuch_messages_t *messages;
\r
135 + GHashTable *matched_hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);
\r
136 + GHashTable *unmatched_hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);
\r
137 + GPtrArray *matched_array = g_ptr_array_new ();
\r
138 + GPtrArray *unmatched_array = g_ptr_array_new ();
\r
140 + /* Iterate over the messages in the thread collecting matching and
\r
141 + * non-matching authors. */
\r
142 + for (messages = notmuch_thread_get_messages (thread);
\r
143 + notmuch_messages_valid (messages);
\r
144 + notmuch_messages_move_to_next (messages))
\r
146 + notmuch_message_t *message = notmuch_messages_get (messages);
\r
147 + const char *author = _nice_author (thread, notmuch_message_get_header (message, "from"));
\r
150 + GHashTable *hash;
\r
151 + GPtrArray *array;
\r
153 + if (notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_MATCH)) {
\r
154 + hash = matched_hash;
\r
155 + array = matched_array;
\r
157 + hash = unmatched_hash;
\r
158 + array = unmatched_array;
\r
161 + if (!g_hash_table_lookup_extended (hash, author, NULL, NULL)) {
\r
162 + char *copy = talloc_strdup (thread, author);
\r
163 + g_hash_table_insert (hash, copy, NULL);
\r
164 + g_ptr_array_add (array, (char *) copy);
\r
169 + /* Output the matched authors. */
\r
171 + format->map_key (format, "authors_matched");
\r
172 + format->begin_list (format);
\r
173 + for (i = 0; i < matched_array->len; i++)
\r
174 + format->string (format, (char *) g_ptr_array_index( matched_array, i));
\r
175 + format->end (format);
\r
177 + /* Output the non-matched authors, but not if they were seen
\r
178 + * already in the matched authors list. */
\r
179 + format->map_key (format, "authors_non_matched");
\r
180 + format->begin_list (format);
\r
181 + for (i = 0; i < unmatched_array->len; i++) {
\r
182 + char *author = (char *) g_ptr_array_index( unmatched_array, i);
\r
184 + if (!g_hash_table_lookup_extended (matched_hash, author, NULL, NULL))
\r
185 + format->string (format, author);
\r
187 + format->end (format);
\r
189 + g_hash_table_unref (matched_hash);
\r
190 + g_hash_table_unref (unmatched_hash);
\r
192 + g_ptr_array_free (matched_array, TRUE);
\r
193 + g_ptr_array_free (unmatched_array, TRUE);
\r
199 do_search_threads (sprinter_t *format,
\r
200 notmuch_query_t *query,
\r
201 @@ -152,6 +253,10 @@ do_search_threads (sprinter_t *format,
\r
202 format->integer (format, total);
\r
203 format->map_key (format, "authors");
\r
204 format->string (format, authors);
\r
205 + if (_enumerate_authors (format, thread) < 0) {
\r
206 + fprintf (stderr, "Out of memory\n");
\r
209 format->map_key (format, "subject");
\r
210 format->string (format, subject);
\r
211 if (notmuch_format_version >= 2) {
\r