1 Return-Path: <too@guru.guru-group.fi>
\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 9E4AE42117B
\r
6 for <notmuch@notmuchmail.org>; Wed, 15 Feb 2012 01:17:42 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]
\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 tbuYgcPCkXS6 for <notmuch@notmuchmail.org>;
\r
16 Wed, 15 Feb 2012 01:17:38 -0800 (PST)
\r
17 Received: from guru.guru-group.fi (guru-group.fi [87.108.86.66])
\r
18 by olra.theworths.org (Postfix) with ESMTP id EAF6C431FBD
\r
19 for <notmuch@notmuchmail.org>; Wed, 15 Feb 2012 01:17:37 -0800 (PST)
\r
20 Received: by guru.guru-group.fi (Postfix, from userid 501)
\r
21 id CC01968056; Wed, 15 Feb 2012 11:17:39 +0200 (EET)
\r
22 From: Tomi Ollila <tomi.ollila@iki.fi>
\r
23 To: notmuch@notmuchmail.org
\r
24 Subject: [PATCH v7 2/3] add support for user-specified files & directories to
\r
26 Date: Wed, 15 Feb 2012 11:17:31 +0200
\r
27 Message-Id: <1329297452-20852-3-git-send-email-tomi.ollila@iki.fi>
\r
28 X-Mailer: git-send-email 1.7.6.1
\r
29 In-Reply-To: <1329297452-20852-1-git-send-email-tomi.ollila@iki.fi>
\r
30 References: <1315949524-4948-1-git-send-email-tomi.ollila@iki.fi>
\r
31 <1329297452-20852-1-git-send-email-tomi.ollila@iki.fi>
\r
32 Cc: Tomi Ollila <tomi.ollila@iki.fi>
\r
33 X-BeenThere: notmuch@notmuchmail.org
\r
34 X-Mailman-Version: 2.1.13
\r
36 List-Id: "Use and development of the notmuch mail system."
\r
37 <notmuch.notmuchmail.org>
\r
38 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
39 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
40 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
41 List-Post: <mailto:notmuch@notmuchmail.org>
\r
42 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
43 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
44 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
45 X-List-Received-Date: Wed, 15 Feb 2012 09:17:43 -0000
\r
47 A new configuration key 'new.ignore' is used to determine which
\r
48 files and directories user wants not to be scanned as new mails.
\r
50 Mark the corresponding test as no longer broken.
\r
51 This work merges my previous attempts and Andreas Amann's work
\r
52 in id:"ylp7hi23mw8.fsf@tyndall.ie"
\r
54 notmuch-client.h | 9 +++++++++
\r
55 notmuch-config.c | 30 +++++++++++++++++++++++++++++-
\r
56 notmuch-new.c | 45 +++++++++++++++++++++++++++++++++------------
\r
58 4 files changed, 71 insertions(+), 14 deletions(-)
\r
60 diff --git a/notmuch-client.h b/notmuch-client.h
\r
61 index 60828aa..f4a62cc 100644
\r
62 --- a/notmuch-client.h
\r
63 +++ b/notmuch-client.h
\r
64 @@ -250,6 +250,15 @@ notmuch_config_set_new_tags (notmuch_config_t *config,
\r
65 const char *new_tags[],
\r
69 +notmuch_config_get_new_ignore (notmuch_config_t *config,
\r
73 +notmuch_config_set_new_ignore (notmuch_config_t *config,
\r
74 + const char *new_ignore[],
\r
78 notmuch_config_get_maildir_synchronize_flags (notmuch_config_t *config);
\r
80 diff --git a/notmuch-config.c b/notmuch-config.c
\r
81 index a124e34..1f01128 100644
\r
82 --- a/notmuch-config.c
\r
83 +++ b/notmuch-config.c
\r
84 @@ -44,7 +44,10 @@ static const char new_config_comment[] =
\r
85 " The following options are supported here:\n"
\r
87 "\ttags A list (separated by ';') of the tags that will be\n"
\r
88 - "\t added to all messages incorporated by \"notmuch new\".\n";
\r
89 + "\t added to all messages incorporated by \"notmuch new\".\n"
\r
91 + "\tignore A list (separated by ';') of file and directory names\n"
\r
92 + "\t that will not be searched for messages by \"notmuch new\".\n";
\r
94 static const char user_config_comment[] =
\r
95 " User configuration\n"
\r
96 @@ -105,6 +108,8 @@ struct _notmuch_config {
\r
97 size_t user_other_email_length;
\r
98 const char **new_tags;
\r
99 size_t new_tags_length;
\r
100 + const char **new_ignore;
\r
101 + size_t new_ignore_length;
\r
102 notmuch_bool_t maildir_synchronize_flags;
\r
103 const char **search_exclude_tags;
\r
104 size_t search_exclude_tags_length;
\r
105 @@ -264,6 +269,8 @@ notmuch_config_open (void *ctx,
\r
106 config->user_other_email_length = 0;
\r
107 config->new_tags = NULL;
\r
108 config->new_tags_length = 0;
\r
109 + config->new_ignore = NULL;
\r
110 + config->new_ignore_length = 0;
\r
111 config->maildir_synchronize_flags = TRUE;
\r
112 config->search_exclude_tags = NULL;
\r
113 config->search_exclude_tags_length = 0;
\r
114 @@ -361,6 +368,10 @@ notmuch_config_open (void *ctx,
\r
115 notmuch_config_set_new_tags (config, tags, 2);
\r
118 + if (notmuch_config_get_new_ignore (config, &tmp) == NULL) {
\r
119 + notmuch_config_set_new_ignore (config, NULL, 0);
\r
122 if (notmuch_config_get_search_exclude_tags (config, &tmp) == NULL) {
\r
124 const char *tags[] = { "deleted", "spam" };
\r
125 @@ -609,6 +620,14 @@ notmuch_config_get_new_tags (notmuch_config_t *config, size_t *length)
\r
126 &(config->new_tags_length), length);
\r
130 +notmuch_config_get_new_ignore (notmuch_config_t *config, size_t *length)
\r
132 + return _config_get_list (config, "new", "ignore",
\r
133 + &(config->new_ignore),
\r
134 + &(config->new_ignore_length), length);
\r
138 notmuch_config_set_user_other_email (notmuch_config_t *config,
\r
139 const char *list[],
\r
140 @@ -627,6 +646,15 @@ notmuch_config_set_new_tags (notmuch_config_t *config,
\r
141 &(config->new_tags));
\r
145 +notmuch_config_set_new_ignore (notmuch_config_t *config,
\r
146 + const char *list[],
\r
149 + _config_set_list (config, "new", "ignore", list, length,
\r
150 + &(config->new_ignore));
\r
154 notmuch_config_get_search_exclude_tags (notmuch_config_t *config, size_t *length)
\r
156 diff --git a/notmuch-new.c b/notmuch-new.c
\r
157 index 8dbebb3..4f13535 100644
\r
158 --- a/notmuch-new.c
\r
159 +++ b/notmuch-new.c
\r
160 @@ -39,6 +39,8 @@ typedef struct {
\r
162 const char **new_tags;
\r
163 size_t new_tags_length;
\r
164 + const char **new_ignore;
\r
165 + size_t new_ignore_length;
\r
168 int processed_files;
\r
169 @@ -181,6 +183,20 @@ _entries_resemble_maildir (struct dirent **entries, int count)
\r
173 +/* Test if the file/directory is to be ignored.
\r
175 +static notmuch_bool_t
\r
176 +_entry_in_ignore_list (const char *entry, add_files_state_t *state)
\r
180 + for (i = 0; i < state->new_ignore_length; i++)
\r
181 + if (strcmp (entry, state->new_ignore[i]) == 0)
\r
187 /* Examine 'path' recursively as follows:
\r
189 * o Ask the filesystem for the mtime of 'path' (fs_mtime)
\r
190 @@ -320,15 +336,15 @@ add_files_recursive (notmuch_database_t *notmuch,
\r
193 /* Ignore special directories to avoid infinite recursion.
\r
194 - * Also ignore the .notmuch directory and any "tmp" directory
\r
195 - * that appears within a maildir.
\r
196 + * Also ignore the .notmuch directory, any "tmp" directory
\r
197 + * that appears within a maildir and files/directories
\r
198 + * the user has configured to be ignored.
\r
200 - /* XXX: Eventually we'll want more sophistication to let the
\r
201 - * user specify files to be ignored. */
\r
202 if (strcmp (entry->d_name, ".") == 0 ||
\r
203 strcmp (entry->d_name, "..") == 0 ||
\r
204 (is_maildir && strcmp (entry->d_name, "tmp") == 0) ||
\r
205 - strcmp (entry->d_name, ".notmuch") ==0)
\r
206 + strcmp (entry->d_name, ".notmuch") == 0 ||
\r
207 + _entry_in_ignore_list (entry->d_name, state))
\r
211 @@ -369,6 +385,10 @@ add_files_recursive (notmuch_database_t *notmuch,
\r
213 entry = fs_entries[i];
\r
215 + /* Ignore files & directories user has configured to be ignored */
\r
216 + if (_entry_in_ignore_list (entry->d_name, state))
\r
219 /* Check if we've walked past any names in db_files or
\r
220 * db_subdirs. If so, these have been deleted. */
\r
221 while (notmuch_filenames_valid (db_files) &&
\r
222 @@ -650,7 +670,7 @@ add_files (notmuch_database_t *notmuch,
\r
223 * initialized to zero by the top-level caller before calling
\r
226 -count_files (const char *path, int *count)
\r
227 +count_files (const char *path, int *count, add_files_state_t *state)
\r
229 struct dirent *entry = NULL;
\r
231 @@ -672,13 +692,13 @@ count_files (const char *path, int *count)
\r
232 entry = fs_entries[i++];
\r
234 /* Ignore special directories to avoid infinite recursion.
\r
235 - * Also ignore the .notmuch directory.
\r
236 + * Also ignore the .notmuch directory and files/directories
\r
237 + * the user has configured to be ignored.
\r
239 - /* XXX: Eventually we'll want more sophistication to let the
\r
240 - * user specify files to be ignored. */
\r
241 if (strcmp (entry->d_name, ".") == 0 ||
\r
242 strcmp (entry->d_name, "..") == 0 ||
\r
243 - strcmp (entry->d_name, ".notmuch") == 0)
\r
244 + strcmp (entry->d_name, ".notmuch") == 0 ||
\r
245 + _entry_in_ignore_list (entry->d_name, state))
\r
249 @@ -699,7 +719,7 @@ count_files (const char *path, int *count)
\r
252 } else if (S_ISDIR (st.st_mode)) {
\r
253 - count_files (next, count);
\r
254 + count_files (next, count, state);
\r
258 @@ -841,6 +861,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
\r
261 add_files_state.new_tags = notmuch_config_get_new_tags (config, &add_files_state.new_tags_length);
\r
262 + add_files_state.new_ignore = notmuch_config_get_new_ignore (config, &add_files_state.new_ignore_length);
\r
263 add_files_state.synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);
\r
264 db_path = notmuch_config_get_database_path (config);
\r
266 @@ -856,7 +877,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
\r
270 - count_files (db_path, &count);
\r
271 + count_files (db_path, &count, &add_files_state);
\r
275 diff --git a/test/new b/test/new
\r
276 index e453684..79a6c97 100755
\r
279 @@ -167,7 +167,6 @@ Note: Ignoring non-mail file: ${MAIL_DIR}/ignored_file
\r
280 Added 1 new message to the database."
\r
282 test_begin_subtest "Ignore files and directories specified in new.ignore"
\r
283 -test_subtest_known_broken
\r
285 notmuch config set new.ignore .git ignored_file .ignored_hidden_file
\r
286 touch "${MAIL_DIR}"/.git # change .git's mtime for notmuch new to rescan.
\r