1 Return-Path: <sojkam1@fel.cvut.cz>
\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 1B6E0429E47
\r
6 for <notmuch@notmuchmail.org>; Sat, 1 Nov 2014 17:50:36 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5
\r
12 tests=[RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id 3JC3jKPqnZ2W for <notmuch@notmuchmail.org>;
\r
16 Sat, 1 Nov 2014 17:50:30 -0700 (PDT)
\r
17 Received: from max.feld.cvut.cz (max.feld.cvut.cz [147.32.192.36])
\r
18 by olra.theworths.org (Postfix) with ESMTP id 86768431E62
\r
19 for <notmuch@notmuchmail.org>; Sat, 1 Nov 2014 17:50:15 -0700 (PDT)
\r
20 Received: from localhost (unknown [192.168.200.7])
\r
21 by max.feld.cvut.cz (Postfix) with ESMTP id E28A85CD28D
\r
22 for <notmuch@notmuchmail.org>; Sun, 2 Nov 2014 01:50:14 +0100 (CET)
\r
23 X-Virus-Scanned: IMAP STYX AMAVIS
\r
24 Received: from max.feld.cvut.cz ([192.168.200.1])
\r
25 by localhost (styx.feld.cvut.cz [192.168.200.7]) (amavisd-new,
\r
26 port 10044) with ESMTP id xPLK3xamo-9l for <notmuch@notmuchmail.org>;
\r
27 Sun, 2 Nov 2014 01:50:10 +0100 (CET)
\r
28 Received: from imap.feld.cvut.cz (imap.feld.cvut.cz [147.32.192.34])
\r
29 by max.feld.cvut.cz (Postfix) with ESMTP id 3181B5CD287
\r
30 for <notmuch@notmuchmail.org>; Sun, 2 Nov 2014 01:50:10 +0100 (CET)
\r
31 Received: from wsh by steelpick.2x.cz with local (Exim 4.84)
\r
32 (envelope-from <sojkam1@fel.cvut.cz>)
\r
33 id 1XkjMq-00085V-LX; Sun, 02 Nov 2014 01:50:04 +0100
\r
34 From: Michal Sojka <sojkam1@fel.cvut.cz>
\r
35 To: notmuch@notmuchmail.org
\r
36 Subject: [PATCH 10/10] cli: address: Add --filter-by option to configure
\r
38 Date: Sun, 2 Nov 2014 01:50:00 +0100
\r
39 Message-Id: <1414889400-30977-11-git-send-email-sojkam1@fel.cvut.cz>
\r
40 X-Mailer: git-send-email 2.1.1
\r
41 In-Reply-To: <1414889400-30977-1-git-send-email-sojkam1@fel.cvut.cz>
\r
42 References: <1414889400-30977-1-git-send-email-sojkam1@fel.cvut.cz>
\r
43 X-BeenThere: notmuch@notmuchmail.org
\r
44 X-Mailman-Version: 2.1.13
\r
46 List-Id: "Use and development of the notmuch mail system."
\r
47 <notmuch.notmuchmail.org>
\r
48 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
49 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
50 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
51 List-Post: <mailto:notmuch@notmuchmail.org>
\r
52 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
53 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
54 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
55 X-List-Received-Date: Sun, 02 Nov 2014 00:50:36 -0000
\r
57 This option allows to configure the criterion for duplicate address
\r
58 filtering. Without this option, all unique combinations of name and
\r
59 address parts are printed. This option allows to filter the output
\r
60 more, for example to only contain unique address parts.
\r
62 completion/notmuch-completion.bash | 6 +++-
\r
63 completion/notmuch-completion.zsh | 1 +
\r
64 doc/man1/notmuch-address.rst | 36 ++++++++++++++++++-
\r
65 notmuch-search.c | 48 +++++++++++++++++++++++--
\r
66 test/T097-address-filter-by.sh | 73 ++++++++++++++++++++++++++++++++++++++
\r
67 5 files changed, 160 insertions(+), 4 deletions(-)
\r
68 create mode 100755 test/T097-address-filter-by.sh
\r
70 diff --git a/completion/notmuch-completion.bash b/completion/notmuch-completion.bash
\r
71 index db152f3..2cb1586 100644
\r
72 --- a/completion/notmuch-completion.bash
\r
73 +++ b/completion/notmuch-completion.bash
\r
74 @@ -310,7 +310,7 @@ _notmuch_search()
\r
78 - local options="--format= --output= --sort= --offset= --limit= --exclude= --duplicate="
\r
79 + local options="--format= --output= --sort= --offset= --limit= --exclude= --duplicate= --filter-by="
\r
81 COMPREPLY=( $(compgen -W "$options" -- ${cur}) )
\r
83 @@ -343,6 +343,10 @@ _notmuch_address()
\r
84 COMPREPLY=( $( compgen -W "true false flag all" -- "${cur}" ) )
\r
88 + COMPREPLY=( $( compgen -W "nameaddr name addr addrfold nameaddrfold" -- "${cur}" ) )
\r
94 diff --git a/completion/notmuch-completion.zsh b/completion/notmuch-completion.zsh
\r
95 index 8968562..3758f1a 100644
\r
96 --- a/completion/notmuch-completion.zsh
\r
97 +++ b/completion/notmuch-completion.zsh
\r
98 @@ -62,6 +62,7 @@ _notmuch_address()
\r
100 '--sort=[sort results]:sorting:((newest-first\:"reverse chronological order" oldest-first\:"chronological order"))' \
\r
101 '--output=[select what to output]:output:((sender recipients count))'
\r
102 + '--filter-by=[filter out duplicate addresses]:filter-by:((nameaddr\:"both name and address part" name\:"name part" addr\:"address part" addrfold\:"case-insensitive address part" nameaddrfold\:"name and case-insensitive address part"))'
\r
106 diff --git a/doc/man1/notmuch-address.rst b/doc/man1/notmuch-address.rst
\r
107 index 18473a7..524ab91 100644
\r
108 --- a/doc/man1/notmuch-address.rst
\r
109 +++ b/doc/man1/notmuch-address.rst
\r
110 @@ -11,7 +11,8 @@ DESCRIPTION
\r
113 Search for messages matching the given search terms, and display the
\r
114 -addresses from them. Duplicate addresses are filtered out.
\r
115 +addresses from them. Duplicate addresses are filtered out. Filtering
\r
116 +can be configured with the --filter-by option.
\r
118 See **notmuch-search-terms(7)** for details of the supported syntax for
\r
120 @@ -85,6 +86,39 @@ Supported options for **address** include
\r
121 is the number of matching non-excluded messages in the thread,
\r
122 rather than the number of matching messages.
\r
124 + ``--filter-by=``\ (**nameaddr**\ \|\ **name** \|\ **addr**\ \|\ **addrfold**\ \|\ **nameaddrfold**\)
\r
126 + Controls how to filter out duplicate addresses. The filtering
\r
127 + algorithm receives a sequence of email addresses and outputs
\r
128 + the same sequence without the addresses that are considered a
\r
129 + duplicate of a previously output address. What is considered a
\r
130 + duplicate depends on how the two addresses are compared:
\r
132 + **nameaddr** means that both name and address parts are
\r
133 + compared in case-sensitive manner. Therefore, all same looking
\r
134 + addresses strings are considered duplicate. This is the
\r
137 + **name** means that only the name part is compared (in
\r
138 + case-sensitive manner). For example, the addresses "John Doe
\r
139 + <me@example.com>" and "John Doe <john@doe.name>" will be
\r
140 + considered duplicate.
\r
142 + **addr** means that only the address part is compared (in
\r
143 + case-sensitive manner). For example, the addresses "John Doe
\r
144 + <john@example.com>" and "Dr. John Doe <john@example.com>" will
\r
145 + be considered duplicate.
\r
147 + **addrfold** is like **addr**, but comparison is done in
\r
148 + canse-insensitive manner. For example, the addresses "John Doe
\r
149 + <john@example.com>" and "Dr. John Doe <JOHN@EXAMPLE.COM>" will
\r
150 + be considered duplicate.
\r
152 + **nameaddrfold** is like **nameaddr**, but address comparison
\r
153 + is done in canse-insensitive manner. For example, the
\r
154 + addresses "John Doe <john@example.com>" and "John Doe
\r
155 + <JOHN@EXAMPLE.COM>" will be considered duplicate.
\r
160 diff --git a/notmuch-search.c b/notmuch-search.c
\r
161 index b45d480..ee1aead 100644
\r
162 --- a/notmuch-search.c
\r
163 +++ b/notmuch-search.c
\r
164 @@ -43,6 +43,14 @@ typedef enum {
\r
165 NOTMUCH_FORMAT_SEXP
\r
169 + FILTER_BY_NAMEADDR = 0,
\r
172 + FILTER_BY_ADDRFOLD,
\r
173 + FILTER_BY_NAMEADDRFOLD,
\r
177 notmuch_database_t *notmuch;
\r
178 format_sel_t format_sel;
\r
179 @@ -55,6 +63,7 @@ typedef struct {
\r
182 GHashTable *addresses;
\r
183 + filter_by_t filter_by;
\r
184 } search_context_t;
\r
187 @@ -243,15 +252,42 @@ do_search_threads (search_context_t *ctx)
\r
191 -/* Returns TRUE iff name and addr is duplicate. */
\r
192 +/* Returns TRUE iff name and/or addr is considered duplicate. */
\r
193 static notmuch_bool_t
\r
194 is_duplicate (const search_context_t *ctx, const char *name, const char *addr)
\r
196 notmuch_bool_t duplicate;
\r
198 + gchar *addrfold = NULL;
\r
199 mailbox_t *mailbox;
\r
201 - key = talloc_asprintf (ctx->format, "%s <%s>", name, addr);
\r
202 + if (ctx->filter_by == FILTER_BY_ADDRFOLD ||
\r
203 + ctx->filter_by == FILTER_BY_NAMEADDRFOLD)
\r
204 + addrfold = g_utf8_casefold (addr, -1);
\r
206 + switch (ctx->filter_by) {
\r
207 + case FILTER_BY_NAMEADDR:
\r
208 + key = talloc_asprintf (ctx->format, "%s <%s>", name, addr);
\r
210 + case FILTER_BY_NAMEADDRFOLD:
\r
211 + key = talloc_asprintf (ctx->format, "%s <%s>", name, addrfold);
\r
213 + case FILTER_BY_NAME:
\r
214 + key = talloc_strdup (ctx->format, name); /* !name results in !key */
\r
216 + case FILTER_BY_ADDR:
\r
217 + key = talloc_strdup (ctx->format, addr);
\r
219 + case FILTER_BY_ADDRFOLD:
\r
220 + key = talloc_strdup (ctx->format, addrfold);
\r
223 + INTERNAL_ERROR("invalid --filter-by flags");
\r
227 + g_free (addrfold);
\r
232 @@ -694,10 +730,18 @@ notmuch_address_command (notmuch_config_t *config, int argc, char *argv[])
\r
233 { "recipients", OUTPUT_RECIPIENTS },
\r
234 { "count", OUTPUT_COUNT },
\r
236 + { NOTMUCH_OPT_KEYWORD, &ctx->filter_by, "filter-by", 'b',
\r
237 + (notmuch_keyword_t []){ { "nameaddr", FILTER_BY_NAMEADDR },
\r
238 + { "name", FILTER_BY_NAME },
\r
239 + { "addr", FILTER_BY_ADDR },
\r
240 + { "addrfold", FILTER_BY_ADDRFOLD },
\r
241 + { "nameaddrfold", FILTER_BY_NAMEADDRFOLD },
\r
243 { NOTMUCH_OPT_INHERIT, &common_options, NULL, 0, 0 },
\r
247 + ctx->filter_by = FILTER_BY_NAMEADDR,
\r
248 opt_index = parse_arguments (argc, argv, options, 1);
\r
250 return EXIT_FAILURE;
\r
251 diff --git a/test/T097-address-filter-by.sh b/test/T097-address-filter-by.sh
\r
252 new file mode 100755
\r
253 index 0000000..544d8e8
\r
255 +++ b/test/T097-address-filter-by.sh
\r
257 +#!/usr/bin/env bash
\r
258 +test_description='duplicite address filtering in "notmuch address"'
\r
261 +add_message '[to]="John Doe <foo@example.com>, John Doe <bar@example.com>"'
\r
262 +add_message '[to]="\"Doe, John\" <foo@example.com>"' '[cc]="John Doe <Bar@Example.COM>"'
\r
263 +add_message '[to]="\"Doe, John\" <foo@example.com>"' '[bcc]="John Doe <Bar@Example.COM>"'
\r
265 +test_begin_subtest "--output=recipients"
\r
266 +notmuch address --output=recipients "*" >OUTPUT
\r
267 +cat <<EOF >EXPECTED
\r
268 +John Doe <foo@example.com>
\r
269 +John Doe <bar@example.com>
\r
270 +"Doe, John" <foo@example.com>
\r
271 +John Doe <Bar@Example.COM>
\r
273 +test_expect_equal_file OUTPUT EXPECTED
\r
275 +test_begin_subtest "--output=recipients --filter-by=nameaddr"
\r
276 +notmuch address --output=recipients --filter-by=nameaddr "*" >OUTPUT
\r
277 +# The same as above
\r
278 +cat <<EOF >EXPECTED
\r
279 +John Doe <foo@example.com>
\r
280 +John Doe <bar@example.com>
\r
281 +"Doe, John" <foo@example.com>
\r
282 +John Doe <Bar@Example.COM>
\r
284 +test_expect_equal_file OUTPUT EXPECTED
\r
286 +test_begin_subtest "--output=recipients --filter-by=name"
\r
287 +notmuch address --output=recipients --filter-by=name "*" >OUTPUT
\r
288 +cat <<EOF >EXPECTED
\r
289 +John Doe <foo@example.com>
\r
290 +"Doe, John" <foo@example.com>
\r
292 +test_expect_equal_file OUTPUT EXPECTED
\r
294 +test_begin_subtest "--output=recipients --filter-by=addr"
\r
295 +notmuch address --output=recipients --filter-by=addr "*" >OUTPUT
\r
296 +cat <<EOF >EXPECTED
\r
297 +John Doe <foo@example.com>
\r
298 +John Doe <bar@example.com>
\r
299 +John Doe <Bar@Example.COM>
\r
301 +test_expect_equal_file OUTPUT EXPECTED
\r
303 +test_begin_subtest "--output=recipients --filter-by=addrfold"
\r
304 +notmuch address --output=recipients --filter-by=addrfold "*" >OUTPUT
\r
305 +cat <<EOF >EXPECTED
\r
306 +John Doe <foo@example.com>
\r
307 +John Doe <bar@example.com>
\r
309 +test_expect_equal_file OUTPUT EXPECTED
\r
311 +test_begin_subtest "--output=recipients --filter-by=nameaddrfold"
\r
312 +notmuch address --output=recipients --filter-by=nameaddrfold "*" >OUTPUT
\r
313 +cat <<EOF >EXPECTED
\r
314 +John Doe <foo@example.com>
\r
315 +John Doe <bar@example.com>
\r
316 +"Doe, John" <foo@example.com>
\r
318 +test_expect_equal_file OUTPUT EXPECTED
\r
320 +test_begin_subtest "--output=recipients --filter-by=nameaddrfold --output=count"
\r
321 +notmuch address --output=recipients --filter-by=nameaddrfold --output=count "*" | sort -n >OUTPUT
\r
322 +cat <<EOF >EXPECTED
\r
323 +1 John Doe <foo@example.com>
\r
324 +2 "Doe, John" <foo@example.com>
\r
325 +3 John Doe <bar@example.com>
\r
327 +test_expect_equal_file OUTPUT EXPECTED
\r