1 Return-Path: <amthrax@drake.mit.edu>
\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 8D27841ED73
\r
6 for <notmuch@notmuchmail.org>; Sat, 14 Jan 2012 16:17:40 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5
\r
12 tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 Q4Z2lQ16nKZr for <notmuch@notmuchmail.org>;
\r
16 Sat, 14 Jan 2012 16:17:38 -0800 (PST)
\r
17 Received: from dmz-mailsec-scanner-2.mit.edu (DMZ-MAILSEC-SCANNER-2.MIT.EDU
\r
19 by olra.theworths.org (Postfix) with ESMTP id 740AD41ED6B
\r
20 for <notmuch@notmuchmail.org>; Sat, 14 Jan 2012 16:17:38 -0800 (PST)
\r
21 X-AuditID: 1209190d-b7fbf6d0000008ba-31-4f121b217b6e
\r
22 Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])
\r
23 by dmz-mailsec-scanner-2.mit.edu (Symantec Messaging Gateway) with SMTP
\r
24 id 1D.56.02234.12B121F4; Sat, 14 Jan 2012 19:17:38 -0500 (EST)
\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])
\r
26 by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id q0F0HbMP032305;
\r
27 Sat, 14 Jan 2012 19:17:37 -0500
\r
28 Received: from drake.mit.edu (26-4-180.dynamic.csail.mit.edu [18.26.4.180])
\r
29 (authenticated bits=0)
\r
30 (User authenticated as amdragon@ATHENA.MIT.EDU)
\r
31 by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q0F0HZwu027544
\r
32 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);
\r
33 Sat, 14 Jan 2012 19:17:36 -0500 (EST)
\r
34 Received: from amthrax by drake.mit.edu with local (Exim 4.77)
\r
35 (envelope-from <amthrax@drake.mit.edu>)
\r
36 id 1RmDmx-0004S0-U3; Sat, 14 Jan 2012 19:17:35 -0500
\r
37 From: Austin Clements <amdragon@MIT.EDU>
\r
38 To: notmuch@notmuchmail.org
\r
39 Subject: [PATCH v3 2/2] search: Support automatic tag exclusions
\r
40 Date: Sat, 14 Jan 2012 19:17:34 -0500
\r
41 Message-Id: <1326586654-16840-3-git-send-email-amdragon@mit.edu>
\r
42 X-Mailer: git-send-email 1.7.7.3
\r
43 In-Reply-To: <1326586654-16840-1-git-send-email-amdragon@mit.edu>
\r
44 References: <1326496024-14403-1-git-send-email-amdragon@mit.edu>
\r
45 <1326586654-16840-1-git-send-email-amdragon@mit.edu>
\r
47 Content-Type: text/plain; charset=UTF-8
\r
48 Content-Transfer-Encoding: 8bit
\r
49 X-Brightmail-Tracker:
\r
50 H4sIAAAAAAAAA+NgFupkleLIzCtJLcpLzFFi42IRYrdT11WSFvI3uPmGyaJpurPFnn1eFtdv
\r
51 zmR2YPa4e5rL49b91+wez1bdYg5gjuKySUnNySxLLdK3S+DKWPFmBlPBDruKq/evsTYwnjbq
\r
52 YuTkkBAwkTj9dgErhC0mceHeerYuRi4OIYF9jBJz5nxkAkkICWxglLh7lR8icZxJ4sb36ywQ
\r
53 znxGia/bj7KAVLEJaEhs27+cEcQWEZCW2Hl3NthYZgFHiZ/3HoLZwgIJEq+mLgWrZxFQlbjw
\r
54 fwtYnFfAQeLlqvVMEGcoSJxbfY4dxOYE6p1zoAtoJgfQsnKJa/fCIMoFJU7OfMICEmYWUJdY
\r
55 P08IYpO8RPPW2cwTGIVmIamahVA1C0nVAkbmVYyyKblVurmJmTnFqcm6xcmJeXmpRbpGermZ
\r
56 JXqpKaWbGEEhzinJu4Px3UGlQ4wCHIxKPLxFOQL+QqyJZcWVuYcYJTmYlER57aWE/IX4kvJT
\r
57 KjMSizPii0pzUosPMUpwMCuJ8C5gBcrxpiRWVqUW5cOkpDlYlMR5VbXe+QkJpCeWpGanphak
\r
58 FsFkZTg4lCR494AMFSxKTU+tSMvMKUFIM3FwggznARpeBVLDW1yQmFucmQ6RP8WoKCXOewQk
\r
59 IQCSyCjNg+uFpaBXjOJArwjz7gSp4gGmL7juV0CDmYAGl6XwgQwuSURISTUwXn15qblP5ex0
\r
60 V4mqlllZZwQc1PjfxW2/OuftrufRBscXxB5I5IriDk/ieHCyd54j1x+Zg9l8czPkjvyRPtu/
\r
61 V+ncS+1Lq703fTXTWW+0y0FZMkZhzU6r95OO/EuTUfbiXskyQ03oXN6DzV1FF8Kjb9xmKOP3
\r
62 nHD3Sf37Fs+bB7nCJyTvzSharsRSnJFoqMVcVJwIAMu/rWccAwAA
\r
63 X-BeenThere: notmuch@notmuchmail.org
\r
64 X-Mailman-Version: 2.1.13
\r
66 List-Id: "Use and development of the notmuch mail system."
\r
67 <notmuch.notmuchmail.org>
\r
68 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
69 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
70 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
71 List-Post: <mailto:notmuch@notmuchmail.org>
\r
72 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
73 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
74 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
75 X-List-Received-Date: Sun, 15 Jan 2012 00:17:40 -0000
\r
77 This adds a "search" section to the config file and an
\r
78 "auto_tag_exclusions" setting in that section. The search and count
\r
79 commands pass tag tags from the configuration to the library.
\r
81 notmuch-client.h | 8 ++++++++
\r
82 notmuch-config.c | 42 ++++++++++++++++++++++++++++++++++++++++++
\r
83 notmuch-count.c | 8 ++++++++
\r
84 notmuch-search.c | 8 ++++++++
\r
85 test/search | 18 ++++++++++++++++++
\r
86 5 files changed, 84 insertions(+), 0 deletions(-)
\r
88 diff --git a/notmuch-client.h b/notmuch-client.h
\r
89 index 517c010..62ede28 100644
\r
90 --- a/notmuch-client.h
\r
91 +++ b/notmuch-client.h
\r
92 @@ -235,6 +235,14 @@ void
\r
93 notmuch_config_set_maildir_synchronize_flags (notmuch_config_t *config,
\r
94 notmuch_bool_t synchronize_flags);
\r
97 +notmuch_config_get_auto_exclude_tags (notmuch_config_t *config, size_t *length);
\r
100 +notmuch_config_set_auto_exclude_tags (notmuch_config_t *config,
\r
101 + const char *list[],
\r
105 notmuch_run_hook (const char *db_path, const char *hook);
\r
107 diff --git a/notmuch-config.c b/notmuch-config.c
\r
108 index d697138..3d4d5b9 100644
\r
109 --- a/notmuch-config.c
\r
110 +++ b/notmuch-config.c
\r
111 @@ -84,6 +84,15 @@ static const char maildir_config_comment[] =
\r
112 "\tand update tags, while the \"notmuch tag\" and \"notmuch restore\"\n"
\r
113 "\tcommands will notice tag changes and update flags in filenames\n";
\r
115 +static const char search_config_comment[] =
\r
116 + " Search configuration\n"
\r
118 + " The following option is supported here:\n"
\r
120 + "\tauto_exclude_tags A ;-separated list of tags that will be\n"
\r
121 + "\t excluded from search results by default. Using an excluded tag\n"
\r
122 + "\t in a query will override that exclusion.\n";
\r
124 struct _notmuch_config {
\r
126 GKeyFile *key_file;
\r
127 @@ -96,6 +105,8 @@ struct _notmuch_config {
\r
128 const char **new_tags;
\r
129 size_t new_tags_length;
\r
130 notmuch_bool_t maildir_synchronize_flags;
\r
131 + const char **auto_exclude_tags;
\r
132 + size_t auto_exclude_tags_length;
\r
136 @@ -221,6 +232,7 @@ notmuch_config_open (void *ctx,
\r
137 int file_had_new_group;
\r
138 int file_had_user_group;
\r
139 int file_had_maildir_group;
\r
140 + int file_had_search_group;
\r
144 @@ -252,6 +264,8 @@ notmuch_config_open (void *ctx,
\r
145 config->new_tags = NULL;
\r
146 config->new_tags_length = 0;
\r
147 config->maildir_synchronize_flags = TRUE;
\r
148 + config->auto_exclude_tags = NULL;
\r
149 + config->auto_exclude_tags_length = 0;
\r
151 if (! g_key_file_load_from_file (config->key_file,
\r
153 @@ -295,6 +309,7 @@ notmuch_config_open (void *ctx,
\r
154 file_had_new_group = g_key_file_has_group (config->key_file, "new");
\r
155 file_had_user_group = g_key_file_has_group (config->key_file, "user");
\r
156 file_had_maildir_group = g_key_file_has_group (config->key_file, "maildir");
\r
157 + file_had_search_group = g_key_file_has_group (config->key_file, "search");
\r
160 if (notmuch_config_get_database_path (config) == NULL) {
\r
161 @@ -345,6 +360,11 @@ notmuch_config_open (void *ctx,
\r
162 notmuch_config_set_new_tags (config, tags, 2);
\r
165 + if (notmuch_config_get_auto_exclude_tags (config, &tmp) == NULL) {
\r
166 + const char *tags[] = { "deleted", "spam" };
\r
167 + notmuch_config_set_auto_exclude_tags (config, tags, 2);
\r
171 config->maildir_synchronize_flags =
\r
172 g_key_file_get_boolean (config->key_file,
\r
173 @@ -387,6 +407,11 @@ notmuch_config_open (void *ctx,
\r
174 maildir_config_comment, NULL);
\r
177 + if (! file_had_search_group) {
\r
178 + g_key_file_set_comment (config->key_file, "search", NULL,
\r
179 + search_config_comment, NULL);
\r
183 *is_new_ret = is_new;
\r
185 @@ -597,6 +622,23 @@ notmuch_config_set_new_tags (notmuch_config_t *config,
\r
186 &(config->new_tags));
\r
190 +notmuch_config_get_auto_exclude_tags (notmuch_config_t *config, size_t *length)
\r
192 + return _config_get_list (config, "search", "auto_exclude_tags",
\r
193 + &(config->auto_exclude_tags),
\r
194 + &(config->auto_exclude_tags_length), length);
\r
198 +notmuch_config_set_auto_exclude_tags (notmuch_config_t *config,
\r
199 + const char *list[],
\r
202 + _config_set_list (config, "search", "auto_exclude_tags", list, length,
\r
203 + &(config->auto_exclude_tags));
\r
206 /* Given a configuration item of the form <group>.<key> return the
\r
207 * component group and key. If any error occurs, print a message on
\r
208 * stderr and return 1. Otherwise, return 0.
\r
209 diff --git a/notmuch-count.c b/notmuch-count.c
\r
210 index 0982f99..f77861e 100644
\r
211 --- a/notmuch-count.c
\r
212 +++ b/notmuch-count.c
\r
213 @@ -35,6 +35,9 @@ notmuch_count_command (void *ctx, int argc, char *argv[])
\r
216 int output = OUTPUT_MESSAGES;
\r
217 + const char **auto_exclude_tags;
\r
218 + size_t auto_exclude_tags_length;
\r
221 notmuch_opt_desc_t options[] = {
\r
222 { NOTMUCH_OPT_KEYWORD, &output, "output", 'o',
\r
223 @@ -75,6 +78,11 @@ notmuch_count_command (void *ctx, int argc, char *argv[])
\r
227 + auto_exclude_tags = notmuch_config_get_auto_exclude_tags
\r
228 + (config, &auto_exclude_tags_length);
\r
229 + for (i = 0; i < auto_exclude_tags_length; i++)
\r
230 + notmuch_query_add_tag_exclude (query, auto_exclude_tags[i]);
\r
233 case OUTPUT_MESSAGES:
\r
234 printf ("%u\n", notmuch_query_count_messages (query));
\r
235 diff --git a/notmuch-search.c b/notmuch-search.c
\r
236 index 4baab56..8867aab 100644
\r
237 --- a/notmuch-search.c
\r
238 +++ b/notmuch-search.c
\r
239 @@ -423,6 +423,9 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
\r
240 output_t output = OUTPUT_SUMMARY;
\r
242 int limit = -1; /* unlimited */
\r
243 + const char **auto_exclude_tags;
\r
244 + size_t auto_exclude_tags_length;
\r
247 enum { NOTMUCH_FORMAT_JSON, NOTMUCH_FORMAT_TEXT }
\r
248 format_sel = NOTMUCH_FORMAT_TEXT;
\r
249 @@ -490,6 +493,11 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
\r
251 notmuch_query_set_sort (query, sort);
\r
253 + auto_exclude_tags = notmuch_config_get_auto_exclude_tags
\r
254 + (config, &auto_exclude_tags_length);
\r
255 + for (i = 0; i < auto_exclude_tags_length; i++)
\r
256 + notmuch_query_add_tag_exclude (query, auto_exclude_tags[i]);
\r
260 case OUTPUT_SUMMARY:
\r
261 diff --git a/test/search b/test/search
\r
262 index a7a0b18..bf965e7 100755
\r
265 @@ -129,4 +129,22 @@ add_message '[subject]="utf8-message-body-subject"' '[date]="Sat, 01 Jan 2000 12
\r
266 output=$(notmuch search "bödý" | notmuch_search_sanitize)
\r
267 test_expect_equal "$output" "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; utf8-message-body-subject (inbox unread)"
\r
269 +test_begin_subtest "Exclude \"deleted\" messages from search"
\r
270 +generate_message '[subject]="Not deleted"'
\r
271 +generate_message '[subject]="Deleted"'
\r
272 +notmuch new > /dev/null
\r
273 +notmuch tag +deleted id:$gen_msg_id
\r
274 +output=$(notmuch search subject:deleted | notmuch_search_sanitize)
\r
275 +test_expect_equal "$output" "thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Not deleted (inbox unread)"
\r
277 +test_begin_subtest "Exclude \"deleted\" messages from search, overridden"
\r
278 +output=$(notmuch search subject:deleted and tag:deleted | notmuch_search_sanitize)
\r
279 +test_expect_equal "$output" "thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Deleted (deleted inbox unread)"
\r
281 +test_begin_subtest "Exclude \"deleted\" messages from threads"
\r
282 +add_message '[subject]="Not deleted reply"' '[in-reply-to]="<$gen_msg_id>"'
\r
283 +output=$(notmuch search subject:deleted | notmuch_search_sanitize)
\r
284 +test_expect_equal "$output" "thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Not deleted (inbox unread)
\r
285 +thread:XXX 2001-01-05 [1/2] Notmuch Test Suite; Not deleted reply (deleted inbox unread)"
\r