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 3FD89431FAF
\r
6 for <notmuch@notmuchmail.org>; Thu, 2 Feb 2012 07:17:37 -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 cbm97wznjCRk for <notmuch@notmuchmail.org>;
\r
16 Thu, 2 Feb 2012 07:17:36 -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 D7FBF431FAE
\r
19 for <notmuch@notmuchmail.org>; Thu, 2 Feb 2012 07:17:35 -0800 (PST)
\r
20 Received: by guru.guru-group.fi (Postfix, from userid 501)
\r
21 id 3969268055; Thu, 2 Feb 2012 17:17:35 +0200 (EET)
\r
22 From: Tomi Ollila <tomi.ollila@iki.fi>
\r
23 To: notmuch@notmuchmail.org
\r
24 Subject: [PATCH] add support for user-specified files & directories to ignore
\r
25 Date: Thu, 2 Feb 2012 17:17:33 +0200
\r
26 Message-Id: <20120202-new-ignore-1-git-send-email-too@iki.fi>
\r
27 X-Mailer: git-send-email 1.7.6.1
\r
28 In-Reply-To: <id:"1315949524-4948-1-git-send-email-tomi.ollila@iki.fi">
\r
29 References: <id:"1315949524-4948-1-git-send-email-tomi.ollila@iki.fi">
\r
30 Cc: Tomi Ollila <tomi.ollila@iki.fi>
\r
31 X-BeenThere: notmuch@notmuchmail.org
\r
32 X-Mailman-Version: 2.1.13
\r
34 List-Id: "Use and development of the notmuch mail system."
\r
35 <notmuch.notmuchmail.org>
\r
36 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
37 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
38 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
39 List-Post: <mailto:notmuch@notmuchmail.org>
\r
40 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
41 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
42 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
43 X-List-Received-Date: Thu, 02 Feb 2012 15:17:37 -0000
\r
45 A new configuration key 'new.ignore' is used to determine which
\r
46 files and directories user wants not to be scanned as new mails.
\r
48 Mark the corresponding test as no longer broken
\r
49 (test from id:"1328105573-4626-1-git-send-email-pieter@praet.org" ).
\r
51 This work merges my previous attempts and Andreas Amann's work
\r
52 in id:"ylp7hi23mw8.fsf@tyndall.ie"
\r
54 See notes in id:"20120202-new-ignore-1-git-send-email-too@iki.fi"
\r
57 Whenever some already existing directory is added to the exclude list
\r
58 and the parent directory timestamp has not changed, notmuch new will not
\r
59 notice the directory has gone (as it still is there), user needs to 'touch'
\r
60 the parent directory before next 'notmuch new' no make notmuch notice.
\r
62 2012-01-26: could notmuch track mtime of the configuration file and if
\r
63 that changes, ignore mail directory timestamps ?
\r
65 See previous notes in id:"20120131-new-ignore-1-git-send-email-too@iki.fi"
\r
67 notmuch-client.h | 10 ++++++++++
\r
68 notmuch-config.c | 33 +++++++++++++++++++++++++++++++--
\r
69 notmuch-new.c | 45 +++++++++++++++++++++++++++++++++------------
\r
71 4 files changed, 74 insertions(+), 15 deletions(-)
\r
73 diff --git a/notmuch-client.h b/notmuch-client.h
\r
74 index e0eb594..26153df 100644
\r
75 --- a/notmuch-client.h
\r
76 +++ b/notmuch-client.h
\r
77 @@ -245,11 +245,21 @@ notmuch_config_set_user_other_email (notmuch_config_t *config,
\r
79 notmuch_config_get_new_tags (notmuch_config_t *config,
\r
83 notmuch_config_set_new_tags (notmuch_config_t *config,
\r
84 const char *new_tags[],
\r
88 +notmuch_config_get_new_ignore (notmuch_config_t *config,
\r
92 +notmuch_config_set_new_ignore (notmuch_config_t *config,
\r
93 + const char *new_ignore[],
\r
97 notmuch_config_get_maildir_synchronize_flags (notmuch_config_t *config);
\r
99 diff --git a/notmuch-config.c b/notmuch-config.c
\r
100 index a124e34..1f01004 100644
\r
101 --- a/notmuch-config.c
\r
102 +++ b/notmuch-config.c
\r
103 @@ -44,7 +44,10 @@ static const char new_config_comment[] =
\r
104 " The following options are supported here:\n"
\r
106 "\ttags A list (separated by ';') of the tags that will be\n"
\r
107 - "\t added to all messages incorporated by \"notmuch new\".\n";
\r
108 + "\t added to all messages incorporated by \"notmuch new\".\n"
\r
110 + "\tignore A list (separated by ';') of file and directory names\n"
\r
111 + "\t that will not be searched for messages by \"notmuch new\".\n";
\r
113 static const char user_config_comment[] =
\r
114 " User configuration\n"
\r
115 @@ -105,6 +108,8 @@ struct _notmuch_config {
\r
116 size_t user_other_email_length;
\r
117 const char **new_tags;
\r
118 size_t new_tags_length;
\r
119 + const char **new_ignore;
\r
120 + size_t new_ignore_length;
\r
121 notmuch_bool_t maildir_synchronize_flags;
\r
122 const char **search_exclude_tags;
\r
123 size_t search_exclude_tags_length;
\r
124 @@ -264,6 +269,8 @@ notmuch_config_open (void *ctx,
\r
125 config->user_other_email_length = 0;
\r
126 config->new_tags = NULL;
\r
127 config->new_tags_length = 0;
\r
128 + config->new_ignore = NULL;
\r
129 + config->new_ignore_length = 0;
\r
130 config->maildir_synchronize_flags = TRUE;
\r
131 config->search_exclude_tags = NULL;
\r
132 config->search_exclude_tags_length = 0;
\r
133 @@ -361,6 +368,10 @@ notmuch_config_open (void *ctx,
\r
134 notmuch_config_set_new_tags (config, tags, 2);
\r
137 + if (notmuch_config_get_new_ignore (config, &tmp) == NULL) {
\r
138 + notmuch_config_set_new_ignore (config, NULL, 0);
\r
141 if (notmuch_config_get_search_exclude_tags (config, &tmp) == NULL) {
\r
143 const char *tags[] = { "deleted", "spam" };
\r
144 @@ -504,7 +515,8 @@ _config_set_list (notmuch_config_t *config,
\r
145 const char *list[],
\r
146 size_t length, const char ***config_var )
\r
148 - g_key_file_set_string_list (config->key_file, group, name, list, length);
\r
149 + g_key_file_set_string_list (config->key_file,
\r
150 + group, name, list, length);
\r
151 talloc_free (*config_var);
\r
152 *config_var = NULL;
\r
154 @@ -609,6 +621,14 @@ notmuch_config_get_new_tags (notmuch_config_t *config, size_t *length)
\r
155 &(config->new_tags_length), length);
\r
159 +notmuch_config_get_new_ignore (notmuch_config_t *config, size_t *length)
\r
161 + return _config_get_list (config, "new", "ignore",
\r
162 + &(config->new_ignore),
\r
163 + &(config->new_ignore_length), length);
\r
167 notmuch_config_set_user_other_email (notmuch_config_t *config,
\r
168 const char *list[],
\r
169 @@ -627,6 +647,15 @@ notmuch_config_set_new_tags (notmuch_config_t *config,
\r
170 &(config->new_tags));
\r
174 +notmuch_config_set_new_ignore (notmuch_config_t *config,
\r
175 + const char *list[],
\r
178 + _config_set_list (config, "new", "ignore", list, length,
\r
179 + &(config->new_ignore));
\r
183 notmuch_config_get_search_exclude_tags (notmuch_config_t *config, size_t *length)
\r
185 diff --git a/notmuch-new.c b/notmuch-new.c
\r
186 index a569a54..f1c271a 100644
\r
187 --- a/notmuch-new.c
\r
188 +++ b/notmuch-new.c
\r
189 @@ -39,6 +39,8 @@ typedef struct {
\r
191 const char **new_tags;
\r
192 size_t new_tags_length;
\r
193 + const char **new_ignore;
\r
194 + size_t new_ignore_length;
\r
197 int processed_files;
\r
198 @@ -181,6 +183,20 @@ _entries_resemble_maildir (struct dirent **entries, int count)
\r
202 +/* Test if the file/directory is to be ignored. */
\r
204 +static notmuch_bool_t
\r
205 +_entry_in_ignore_list (const char *entry, add_files_state_t *state)
\r
209 + for (i = 0; i < state->new_ignore_length; i++)
\r
210 + if (strcmp (entry, state->new_ignore[i]) == 0)
\r
216 /* Examine 'path' recursively as follows:
\r
218 * o Ask the filesystem for the mtime of 'path' (fs_mtime)
\r
219 @@ -320,15 +336,15 @@ add_files_recursive (notmuch_database_t *notmuch,
\r
222 /* Ignore special directories to avoid infinite recursion.
\r
223 - * Also ignore the .notmuch directory and any "tmp" directory
\r
224 - * that appears within a maildir.
\r
225 + * Also ignore the .notmuch directory, any "tmp" directory
\r
226 + * that appears within a maildir and files/directories
\r
227 + * the user has configured to be ignored.
\r
229 - /* XXX: Eventually we'll want more sophistication to let the
\r
230 - * user specify files to be ignored. */
\r
231 if (strcmp (entry->d_name, ".") == 0 ||
\r
232 strcmp (entry->d_name, "..") == 0 ||
\r
233 (is_maildir && strcmp (entry->d_name, "tmp") == 0) ||
\r
234 - strcmp (entry->d_name, ".notmuch") ==0)
\r
235 + strcmp (entry->d_name, ".notmuch") == 0 ||
\r
236 + _entry_in_ignore_list (entry->d_name, state))
\r
240 @@ -369,6 +385,10 @@ add_files_recursive (notmuch_database_t *notmuch,
\r
242 entry = fs_entries[i];
\r
244 + /* Ignore files & directories user has configured to be ignored */
\r
245 + if (_entry_in_ignore_list (entry->d_name, state))
\r
248 /* Check if we've walked past any names in db_files or
\r
249 * db_subdirs. If so, these have been deleted. */
\r
250 while (notmuch_filenames_valid (db_files) &&
\r
251 @@ -648,7 +668,7 @@ add_files (notmuch_database_t *notmuch,
\r
252 * initialized to zero by the top-level caller before calling
\r
255 -count_files (const char *path, int *count)
\r
256 +count_files (const char *path, int *count, add_files_state_t *state)
\r
258 struct dirent *entry = NULL;
\r
260 @@ -670,13 +690,13 @@ count_files (const char *path, int *count)
\r
261 entry = fs_entries[i++];
\r
263 /* Ignore special directories to avoid infinite recursion.
\r
264 - * Also ignore the .notmuch directory.
\r
265 + * Also ignore the .notmuch directory and files/directories
\r
266 + * the user has configured to be ignored.
\r
268 - /* XXX: Eventually we'll want more sophistication to let the
\r
269 - * user specify files to be ignored. */
\r
270 if (strcmp (entry->d_name, ".") == 0 ||
\r
271 strcmp (entry->d_name, "..") == 0 ||
\r
272 - strcmp (entry->d_name, ".notmuch") == 0)
\r
273 + strcmp (entry->d_name, ".notmuch") == 0 ||
\r
274 + _entry_in_ignore_list (entry->d_name, state))
\r
278 @@ -697,7 +717,7 @@ count_files (const char *path, int *count)
\r
281 } else if (S_ISDIR (st.st_mode)) {
\r
282 - count_files (next, count);
\r
283 + count_files (next, count, state);
\r
287 @@ -837,6 +857,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
\r
290 add_files_state.new_tags = notmuch_config_get_new_tags (config, &add_files_state.new_tags_length);
\r
291 + add_files_state.new_ignore = notmuch_config_get_new_ignore (config, &add_files_state.new_ignore_length);
\r
292 add_files_state.synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);
\r
293 db_path = notmuch_config_get_database_path (config);
\r
295 @@ -852,7 +873,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
\r
299 - count_files (db_path, &count);
\r
300 + count_files (db_path, &count, &add_files_state);
\r
304 diff --git a/test/new b/test/new
\r
305 index 740ba05..b616dec 100755
\r
308 @@ -166,7 +166,6 @@ Note: Ignoring non-mail file: ${MAIL_DIR}/ignored_file
\r
309 Added 1 new message to the database."
\r
311 test_begin_subtest "Ignore files and directories specified in new.ignore"
\r
312 -test_subtest_known_broken
\r
314 notmuch config set new.ignore .git ignored_file .ignored_hidden_file
\r
315 mkdir -p "${MAIL_DIR}"/.git && touch "${MAIL_DIR}"/.git/config
\r