1 Return-Path: <markwalters1009@gmail.com>
\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 arlo.cworth.org (Postfix) with ESMTP id 51F946DE179D
\r
6 for <notmuch@notmuchmail.org>; Mon, 14 Dec 2015 09:23:15 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org
\r
11 X-Spam-Status: No, score=-0.266 tagged_above=-999 required=5 tests=[AWL=0.304,
\r
12 DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
\r
13 FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7,
\r
14 RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001]
\r
16 Received: from arlo.cworth.org ([127.0.0.1])
\r
17 by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)
\r
18 with ESMTP id bGCt-vbPss6c for <notmuch@notmuchmail.org>;
\r
19 Mon, 14 Dec 2015 09:23:13 -0800 (PST)
\r
20 Received: from mail-wm0-f47.google.com (mail-wm0-f47.google.com
\r
21 [74.125.82.47]) by arlo.cworth.org (Postfix) with ESMTPS id 82D296DE0FB0 for
\r
22 <notmuch@notmuchmail.org>; Mon, 14 Dec 2015 09:23:06 -0800 (PST)
\r
23 Received: by mail-wm0-f47.google.com with SMTP id p66so54448619wmp.0
\r
24 for <notmuch@notmuchmail.org>; Mon, 14 Dec 2015 09:23:06 -0800 (PST)
\r
25 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;
\r
26 h=from:to:cc:subject:date:message-id:in-reply-to:references;
\r
27 bh=ipsZGs1ZgLEXYbpaTMpRWBYYwPeo3MYpsgykBe8BoC4=;
\r
28 b=sC+4D2MerAT2Ym5WiZiiXQKGDmUGWpysAYHcROMocCnNbwQkNYNDTGi3ZLEGqe/1Pq
\r
29 YV93PH0bVuV8WaVSvIOvlhy9D7N+ExGosidTg2GksmyXaJcYNH5WAs6k2ReZxdRHjc7j
\r
30 zKxryaik7EBUpfMkVrUGfPUpMpOoI88cj9Plu0B9VaAsR9xkqKmQLeRSO372URh5Gaak
\r
31 DJFPXCvbcju8a4QsBvMVtDJ4hGmzn1m7lbC/QD2H48Q+EBzZXkchq7EF1a/esKs+xGB8
\r
32 9A0UndZZfGUVsPoVW1SShYpPUrzMHc3CG8frd/QiN7X2Q5/NreGPlcuBqJOzb9rJs9Df
\r
34 X-Received: by 10.194.77.51 with SMTP id p19mr38359624wjw.159.1450113783260;
\r
35 Mon, 14 Dec 2015 09:23:03 -0800 (PST)
\r
36 Received: from localhost (92.40.77.76.threembb.co.uk. [92.40.77.76])
\r
37 by smtp.gmail.com with ESMTPSA id s11sm17180610wmb.14.2015.12.14.09.22.58
\r
38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
\r
39 Mon, 14 Dec 2015 09:23:00 -0800 (PST)
\r
40 From: Mark Walters <markwalters1009@gmail.com>
\r
41 To: notmuch@notmuchmail.org
\r
42 Subject: [PATCH v2 (rebased) 1/3] search: Separately report matching and
\r
43 non-matching authors.
\r
44 Date: Mon, 14 Dec 2015 17:22:44 +0000
\r
45 Message-Id: <1450113766-20518-2-git-send-email-markwalters1009@gmail.com>
\r
46 X-Mailer: git-send-email 2.1.4
\r
47 In-Reply-To: <1450113766-20518-1-git-send-email-markwalters1009@gmail.com>
\r
48 References: <1450113766-20518-1-git-send-email-markwalters1009@gmail.com>
\r
49 X-BeenThere: notmuch@notmuchmail.org
\r
50 X-Mailman-Version: 2.1.20
\r
52 List-Id: "Use and development of the notmuch mail system."
\r
53 <notmuch.notmuchmail.org>
\r
54 List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,
\r
55 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
56 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>
\r
57 List-Post: <mailto:notmuch@notmuchmail.org>
\r
58 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
59 List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,
\r
60 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
61 X-List-Received-Date: Mon, 14 Dec 2015 17:23:15 -0000
\r
63 From: David Edmondson <dme@dme.org>
\r
65 In addition to the 'authors' attribute of each search result, include
\r
66 'authors_matched' and 'authors_non_matched' attributes. Both
\r
67 attributes are always included and are formatted as a list of
\r
68 authors. If there are no matching authors, the 'authors_non_matched'
\r
69 attribute is set to the empty list.
\r
71 notmuch-search.c | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
\r
72 1 file changed, 105 insertions(+)
\r
74 diff --git a/notmuch-search.c b/notmuch-search.c
\r
75 index 6d08c25..6c6e497 100644
\r
76 --- a/notmuch-search.c
\r
77 +++ b/notmuch-search.c
\r
79 #include "sprinter.h"
\r
80 #include "string-util.h"
\r
85 /* Search command */
\r
86 OUTPUT_SUMMARY = 1 << 0,
\r
87 @@ -109,6 +111,105 @@ get_thread_query (notmuch_thread_t *thread,
\r
91 +/* Return a more pleasent rendering of the mail address
\r
92 + * `nasty_author'. */
\r
93 +static const char *
\r
94 +_nice_author (void *ctx, const char *nasty_author)
\r
96 + const char *nice_author = NULL;
\r
98 + InternetAddressList *list = internet_address_list_parse_string (nasty_author);
\r
100 + InternetAddress *address = internet_address_list_get_address (list, 0);
\r
102 + nice_author = internet_address_get_name (address);
\r
103 + if (nice_author == NULL) {
\r
104 + InternetAddressMailbox *mailbox = INTERNET_ADDRESS_MAILBOX (address);
\r
105 + nice_author = internet_address_mailbox_get_addr (mailbox);
\r
108 + /* Duplicate the string before `g_object_unref' destroys
\r
111 + nice_author = talloc_strdup (ctx, nice_author);
\r
113 + g_object_unref (G_OBJECT (list));
\r
117 + return nice_author;
\r
119 + return nasty_author;
\r
123 +_enumerate_authors (sprinter_t *format,
\r
124 + notmuch_thread_t *thread)
\r
126 + notmuch_messages_t *messages;
\r
127 + GHashTable *matched_hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);
\r
128 + GHashTable *unmatched_hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);
\r
129 + GPtrArray *matched_array = g_ptr_array_new ();
\r
130 + GPtrArray *unmatched_array = g_ptr_array_new ();
\r
132 + /* Iterate over the messages in the thread collecting matching and
\r
133 + * non-matching authors. */
\r
134 + for (messages = notmuch_thread_get_messages (thread);
\r
135 + notmuch_messages_valid (messages);
\r
136 + notmuch_messages_move_to_next (messages))
\r
138 + notmuch_message_t *message = notmuch_messages_get (messages);
\r
139 + const char *author = _nice_author (thread, notmuch_message_get_header (message, "from"));
\r
142 + GHashTable *hash;
\r
143 + GPtrArray *array;
\r
145 + if (notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_MATCH)) {
\r
146 + hash = matched_hash;
\r
147 + array = matched_array;
\r
149 + hash = unmatched_hash;
\r
150 + array = unmatched_array;
\r
153 + if (!g_hash_table_lookup_extended (hash, author, NULL, NULL)) {
\r
154 + char *copy = talloc_strdup (thread, author);
\r
155 + g_hash_table_insert (hash, copy, NULL);
\r
156 + g_ptr_array_add (array, (char *) copy);
\r
161 + /* Output the matched authors. */
\r
163 + format->map_key (format, "authors_matched");
\r
164 + format->begin_list (format);
\r
165 + for (i = 0; i < matched_array->len; i++)
\r
166 + format->string (format, (char *) g_ptr_array_index( matched_array, i));
\r
167 + format->end (format);
\r
169 + /* Output the non-matched authors, but not if they were seen
\r
170 + * already in the matched authors list. */
\r
171 + format->map_key (format, "authors_non_matched");
\r
172 + format->begin_list (format);
\r
173 + for (i = 0; i < unmatched_array->len; i++) {
\r
174 + char *author = (char *) g_ptr_array_index( unmatched_array, i);
\r
176 + if (!g_hash_table_lookup_extended (matched_hash, author, NULL, NULL))
\r
177 + format->string (format, author);
\r
179 + format->end (format);
\r
181 + g_hash_table_unref (matched_hash);
\r
182 + g_hash_table_unref (unmatched_hash);
\r
184 + g_ptr_array_free (matched_array, TRUE);
\r
185 + g_ptr_array_free (unmatched_array, TRUE);
\r
191 do_search_threads (search_context_t *ctx)
\r
193 @@ -195,6 +296,10 @@ do_search_threads (search_context_t *ctx)
\r
194 format->integer (format, total);
\r
195 format->map_key (format, "authors");
\r
196 format->string (format, authors);
\r
197 + if (_enumerate_authors (format, thread) < 0) {
\r
198 + fprintf (stderr, "Out of memory\n");
\r
201 format->map_key (format, "subject");
\r
202 format->string (format, subject);
\r
203 if (notmuch_format_version >= 2) {
\r