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 B99C8431FAF
\r
6 for <notmuch@notmuchmail.org>; Mon, 6 Feb 2012 01:28:26 -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 DtzXO9tiwWkV for <notmuch@notmuchmail.org>;
\r
16 Mon, 6 Feb 2012 01:28:25 -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 1E460431FAE
\r
19 for <notmuch@notmuchmail.org>; Mon, 6 Feb 2012 01:28:25 -0800 (PST)
\r
20 Received: by guru.guru-group.fi (Postfix, from userid 501)
\r
21 id 3837B68056; Mon, 6 Feb 2012 11:28:27 +0200 (EET)
\r
22 From: Tomi Ollila <tomi.ollila@iki.fi>
\r
23 To: notmuch@notmuchmail.org
\r
24 Subject: [PATCH v6 2/3] add support for user-specified files & directories to
\r
26 Date: Mon, 6 Feb 2012 11:28:24 +0200
\r
27 Message-Id: <1328520505-26382-2-git-send-email-tomi.ollila@iki.fi>
\r
28 X-Mailer: git-send-email 1.7.6.1
\r
29 In-Reply-To: <1328520505-26382-1-git-send-email-tomi.ollila@iki.fi>
\r
30 References: <1315949524-4948-1-git-send-email-tomi.ollila@iki.fi>
\r
31 <1328520505-26382-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: Mon, 06 Feb 2012 09:28:26 -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
52 This work merges my previous attempts and Andreas Amann's work
\r
53 in id:"ylp7hi23mw8.fsf@tyndall.ie"
\r
55 notmuch-client.h | 9 +++++++++
\r
56 notmuch-config.c | 30 +++++++++++++++++++++++++++++-
\r
57 notmuch-new.c | 45 +++++++++++++++++++++++++++++++++------------
\r
59 4 files changed, 71 insertions(+), 14 deletions(-)
\r
61 diff --git a/notmuch-client.h b/notmuch-client.h
\r
62 index e0eb594..f1762ae 100644
\r
63 --- a/notmuch-client.h
\r
64 +++ b/notmuch-client.h
\r
65 @@ -250,6 +250,15 @@ notmuch_config_set_new_tags (notmuch_config_t *config,
\r
66 const char *new_tags[],
\r
70 +notmuch_config_get_new_ignore (notmuch_config_t *config,
\r
74 +notmuch_config_set_new_ignore (notmuch_config_t *config,
\r
75 + const char *new_ignore[],
\r
79 notmuch_config_get_maildir_synchronize_flags (notmuch_config_t *config);
\r
81 diff --git a/notmuch-config.c b/notmuch-config.c
\r
82 index a124e34..1f01128 100644
\r
83 --- a/notmuch-config.c
\r
84 +++ b/notmuch-config.c
\r
85 @@ -44,7 +44,10 @@ static const char new_config_comment[] =
\r
86 " The following options are supported here:\n"
\r
88 "\ttags A list (separated by ';') of the tags that will be\n"
\r
89 - "\t added to all messages incorporated by \"notmuch new\".\n";
\r
90 + "\t added to all messages incorporated by \"notmuch new\".\n"
\r
92 + "\tignore A list (separated by ';') of file and directory names\n"
\r
93 + "\t that will not be searched for messages by \"notmuch new\".\n";
\r
95 static const char user_config_comment[] =
\r
96 " User configuration\n"
\r
97 @@ -105,6 +108,8 @@ struct _notmuch_config {
\r
98 size_t user_other_email_length;
\r
99 const char **new_tags;
\r
100 size_t new_tags_length;
\r
101 + const char **new_ignore;
\r
102 + size_t new_ignore_length;
\r
103 notmuch_bool_t maildir_synchronize_flags;
\r
104 const char **search_exclude_tags;
\r
105 size_t search_exclude_tags_length;
\r
106 @@ -264,6 +269,8 @@ notmuch_config_open (void *ctx,
\r
107 config->user_other_email_length = 0;
\r
108 config->new_tags = NULL;
\r
109 config->new_tags_length = 0;
\r
110 + config->new_ignore = NULL;
\r
111 + config->new_ignore_length = 0;
\r
112 config->maildir_synchronize_flags = TRUE;
\r
113 config->search_exclude_tags = NULL;
\r
114 config->search_exclude_tags_length = 0;
\r
115 @@ -361,6 +368,10 @@ notmuch_config_open (void *ctx,
\r
116 notmuch_config_set_new_tags (config, tags, 2);
\r
119 + if (notmuch_config_get_new_ignore (config, &tmp) == NULL) {
\r
120 + notmuch_config_set_new_ignore (config, NULL, 0);
\r
123 if (notmuch_config_get_search_exclude_tags (config, &tmp) == NULL) {
\r
125 const char *tags[] = { "deleted", "spam" };
\r
126 @@ -609,6 +620,14 @@ notmuch_config_get_new_tags (notmuch_config_t *config, size_t *length)
\r
127 &(config->new_tags_length), length);
\r
131 +notmuch_config_get_new_ignore (notmuch_config_t *config, size_t *length)
\r
133 + return _config_get_list (config, "new", "ignore",
\r
134 + &(config->new_ignore),
\r
135 + &(config->new_ignore_length), length);
\r
139 notmuch_config_set_user_other_email (notmuch_config_t *config,
\r
140 const char *list[],
\r
141 @@ -627,6 +646,15 @@ notmuch_config_set_new_tags (notmuch_config_t *config,
\r
142 &(config->new_tags));
\r
146 +notmuch_config_set_new_ignore (notmuch_config_t *config,
\r
147 + const char *list[],
\r
150 + _config_set_list (config, "new", "ignore", list, length,
\r
151 + &(config->new_ignore));
\r
155 notmuch_config_get_search_exclude_tags (notmuch_config_t *config, size_t *length)
\r
157 diff --git a/notmuch-new.c b/notmuch-new.c
\r
158 index a569a54..8a615e6 100644
\r
159 --- a/notmuch-new.c
\r
160 +++ b/notmuch-new.c
\r
161 @@ -39,6 +39,8 @@ typedef struct {
\r
163 const char **new_tags;
\r
164 size_t new_tags_length;
\r
165 + const char **new_ignore;
\r
166 + size_t new_ignore_length;
\r
169 int processed_files;
\r
170 @@ -181,6 +183,20 @@ _entries_resemble_maildir (struct dirent **entries, int count)
\r
174 +/* Test if the file/directory is to be ignored.
\r
176 +static notmuch_bool_t
\r
177 +_entry_in_ignore_list (const char *entry, add_files_state_t *state)
\r
181 + for (i = 0; i < state->new_ignore_length; i++)
\r
182 + if (strcmp (entry, state->new_ignore[i]) == 0)
\r
188 /* Examine 'path' recursively as follows:
\r
190 * o Ask the filesystem for the mtime of 'path' (fs_mtime)
\r
191 @@ -320,15 +336,15 @@ add_files_recursive (notmuch_database_t *notmuch,
\r
194 /* Ignore special directories to avoid infinite recursion.
\r
195 - * Also ignore the .notmuch directory and any "tmp" directory
\r
196 - * that appears within a maildir.
\r
197 + * Also ignore the .notmuch directory, any "tmp" directory
\r
198 + * that appears within a maildir and files/directories
\r
199 + * the user has configured to be ignored.
\r
201 - /* XXX: Eventually we'll want more sophistication to let the
\r
202 - * user specify files to be ignored. */
\r
203 if (strcmp (entry->d_name, ".") == 0 ||
\r
204 strcmp (entry->d_name, "..") == 0 ||
\r
205 (is_maildir && strcmp (entry->d_name, "tmp") == 0) ||
\r
206 - strcmp (entry->d_name, ".notmuch") ==0)
\r
207 + strcmp (entry->d_name, ".notmuch") == 0 ||
\r
208 + _entry_in_ignore_list (entry->d_name, state))
\r
212 @@ -369,6 +385,10 @@ add_files_recursive (notmuch_database_t *notmuch,
\r
214 entry = fs_entries[i];
\r
216 + /* Ignore files & directories user has configured to be ignored */
\r
217 + if (_entry_in_ignore_list (entry->d_name, state))
\r
220 /* Check if we've walked past any names in db_files or
\r
221 * db_subdirs. If so, these have been deleted. */
\r
222 while (notmuch_filenames_valid (db_files) &&
\r
223 @@ -648,7 +668,7 @@ add_files (notmuch_database_t *notmuch,
\r
224 * initialized to zero by the top-level caller before calling
\r
227 -count_files (const char *path, int *count)
\r
228 +count_files (const char *path, int *count, add_files_state_t *state)
\r
230 struct dirent *entry = NULL;
\r
232 @@ -670,13 +690,13 @@ count_files (const char *path, int *count)
\r
233 entry = fs_entries[i++];
\r
235 /* Ignore special directories to avoid infinite recursion.
\r
236 - * Also ignore the .notmuch directory.
\r
237 + * Also ignore the .notmuch directory and files/directories
\r
238 + * the user has configured to be ignored.
\r
240 - /* XXX: Eventually we'll want more sophistication to let the
\r
241 - * user specify files to be ignored. */
\r
242 if (strcmp (entry->d_name, ".") == 0 ||
\r
243 strcmp (entry->d_name, "..") == 0 ||
\r
244 - strcmp (entry->d_name, ".notmuch") == 0)
\r
245 + strcmp (entry->d_name, ".notmuch") == 0 ||
\r
246 + _entry_in_ignore_list (entry->d_name, state))
\r
250 @@ -697,7 +717,7 @@ count_files (const char *path, int *count)
\r
253 } else if (S_ISDIR (st.st_mode)) {
\r
254 - count_files (next, count);
\r
255 + count_files (next, count, state);
\r
259 @@ -837,6 +857,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
\r
262 add_files_state.new_tags = notmuch_config_get_new_tags (config, &add_files_state.new_tags_length);
\r
263 + add_files_state.new_ignore = notmuch_config_get_new_ignore (config, &add_files_state.new_ignore_length);
\r
264 add_files_state.synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);
\r
265 db_path = notmuch_config_get_database_path (config);
\r
267 @@ -852,7 +873,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
\r
271 - count_files (db_path, &count);
\r
272 + count_files (db_path, &count, &add_files_state);
\r
276 diff --git a/test/new b/test/new
\r
277 index 5ce8811..2af63a1 100755
\r
280 @@ -167,7 +167,6 @@ Note: Ignoring non-mail file: ${MAIL_DIR}/ignored_file
\r
281 Added 1 new message to the database."
\r
283 test_begin_subtest "Ignore files and directories specified in new.ignore"
\r
284 -test_subtest_known_broken
\r
286 notmuch config set new.ignore .git ignored_file .ignored_hidden_file
\r
287 touch "${MAIL_DIR}"/.git # change .git's mtime for notmuch new to rescan.
\r