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 91108429E5B
\r
6 for <notmuch@notmuchmail.org>; Tue, 31 Jan 2012 08:28:08 -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 5WTTv+6Lj69i for <notmuch@notmuchmail.org>;
\r
16 Tue, 31 Jan 2012 08:28:07 -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 E6D9F429E25
\r
19 for <notmuch@notmuchmail.org>; Tue, 31 Jan 2012 08:28:06 -0800 (PST)
\r
20 Received: by guru.guru-group.fi (Postfix, from userid 501)
\r
21 id 0720768055; Tue, 31 Jan 2012 18:28:06 +0200 (EET)
\r
22 From: Tomi Ollila <tomi.ollila@iki.fi>
\r
23 To: notmuch@notmuchmail.org
\r
24 Subject: [PATCH] added support for user-specified files & directories to
\r
26 Date: Tue, 31 Jan 2012 18:28:04 +0200
\r
27 Message-Id: <20120131-new-ignore-1-git-send-email-too@iki.fi>
\r
28 X-Mailer: git-send-email 1.7.6.1
\r
29 In-Reply-To: <1315949524-4948-1-git-send-email-tomi.ollila@iki.fi>
\r
30 References: <1315949524-4948-1-git-send-email-tomi.ollila@iki.fi>
\r
31 Cc: Tomi Ollila <tomi.ollila@iki.fi>
\r
32 X-BeenThere: notmuch@notmuchmail.org
\r
33 X-Mailman-Version: 2.1.13
\r
35 List-Id: "Use and development of the notmuch mail system."
\r
36 <notmuch.notmuchmail.org>
\r
37 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
38 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
39 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
40 List-Post: <mailto:notmuch@notmuchmail.org>
\r
41 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
42 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
43 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
44 X-List-Received-Date: Tue, 31 Jan 2012 16:28:08 -0000
\r
46 A new configuration key 'new.ignore' is used to determine which
\r
47 files and directories user wants not to be scanned as new mails.
\r
49 This work merges my previous attempts and Andreas Amann's work
\r
50 in id:"ylp7hi23mw8.fsf@tyndall.ie"
\r
52 See notes in id:"20120131-new-ignore-1-git-send-email-too@iki.fi"
\r
56 1) Currently there is comment for new.ignore in newly created configuration
\r
57 file but as the list is initially empty there will be not tag in place.
\r
59 2) Whenever some already existing directory is added to the exclude list
\r
60 and the parent directory timestamp has not changed, notmuch new will not
\r
61 notice the directory has gone (as it still is there), user needs to 'touch'
\r
62 the parent directory before next 'notmuch new' no make notmuch notice.
\r
64 2012-01-26: could notmuch track mtime of the configuration file and if
\r
65 that changes, ignore mail directory timestamps ?
\r
68 3) in id:"1327572718-13411-2-git-send-email-tomi.ollila@iki.fi" dropped...
\r
70 notmuch-client.h | 8 ++++++++
\r
71 notmuch-config.c | 35 +++++++++++++++++++++++++++++++++--
\r
72 notmuch-new.c | 45 +++++++++++++++++++++++++++++++++------------
\r
73 3 files changed, 74 insertions(+), 14 deletions(-)
\r
75 diff --git a/notmuch-client.h b/notmuch-client.h
\r
76 index e0eb594..c62ce78 100644
\r
77 --- a/notmuch-client.h
\r
78 +++ b/notmuch-client.h
\r
79 @@ -250,6 +250,14 @@ notmuch_config_set_new_tags (notmuch_config_t *config,
\r
80 const char *new_tags[],
\r
84 +notmuch_config_get_new_ignore (notmuch_config_t *config,
\r
87 +notmuch_config_set_new_ignore (notmuch_config_t *config,
\r
88 + const char *new_ignore[],
\r
92 notmuch_config_get_maildir_synchronize_flags (notmuch_config_t *config);
\r
94 diff --git a/notmuch-config.c b/notmuch-config.c
\r
95 index a124e34..f1cc5c2 100644
\r
96 --- a/notmuch-config.c
\r
97 +++ b/notmuch-config.c
\r
98 @@ -44,7 +44,10 @@ static const char new_config_comment[] =
\r
99 " The following options are supported here:\n"
\r
101 "\ttags A list (separated by ';') of the tags that will be\n"
\r
102 - "\t added to all messages incorporated by \"notmuch new\".\n";
\r
103 + "\t added to all messages incorporated by \"notmuch new\".\n"
\r
105 + "\tignore A list (separated by ';') of files and directories that"
\r
106 + "\t will not be searched for messages by \"notmuch new\".\n";
\r
108 static const char user_config_comment[] =
\r
109 " User configuration\n"
\r
110 @@ -105,6 +108,8 @@ struct _notmuch_config {
\r
111 size_t user_other_email_length;
\r
112 const char **new_tags;
\r
113 size_t new_tags_length;
\r
114 + const char **new_ignore;
\r
115 + size_t new_ignore_length;
\r
116 notmuch_bool_t maildir_synchronize_flags;
\r
117 const char **search_exclude_tags;
\r
118 size_t search_exclude_tags_length;
\r
119 @@ -264,6 +269,8 @@ notmuch_config_open (void *ctx,
\r
120 config->user_other_email_length = 0;
\r
121 config->new_tags = NULL;
\r
122 config->new_tags_length = 0;
\r
123 + config->new_ignore = NULL;
\r
124 + config->new_ignore_length = 0;
\r
125 config->maildir_synchronize_flags = TRUE;
\r
126 config->search_exclude_tags = NULL;
\r
127 config->search_exclude_tags_length = 0;
\r
128 @@ -360,7 +367,11 @@ notmuch_config_open (void *ctx,
\r
129 const char *tags[] = { "unread", "inbox" };
\r
130 notmuch_config_set_new_tags (config, tags, 2);
\r
133 +#if 0 /* No point setting empty list -- it's not written */
\r
134 + if (notmuch_config_get_new_ignore (config, &tmp) == NULL) {
\r
135 + notmuch_config_set_new_ignore (config, NULL, 0);
\r
138 if (notmuch_config_get_search_exclude_tags (config, &tmp) == NULL) {
\r
140 const char *tags[] = { "deleted", "spam" };
\r
141 @@ -609,6 +620,15 @@ notmuch_config_get_new_tags (notmuch_config_t *config, size_t *length)
\r
142 &(config->new_tags_length), length);
\r
146 +notmuch_config_get_new_ignore (notmuch_config_t *config, size_t *length)
\r
148 + return _config_get_list (config, "new", "ignore",
\r
149 + &(config->new_ignore),
\r
150 + &(config->new_ignore_length), length);
\r
155 notmuch_config_set_user_other_email (notmuch_config_t *config,
\r
156 const char *list[],
\r
157 @@ -627,6 +647,17 @@ notmuch_config_set_new_tags (notmuch_config_t *config,
\r
158 &(config->new_tags));
\r
161 +#if 0 /* UNNEEDED SO FAR */
\r
163 +notmuch_config_set_new_ignore (notmuch_config_t *config,
\r
164 + const char *list[],
\r
167 + _config_set_list (config, "new", "ignore", list, length,
\r
168 + &(config->new_ignore));
\r
173 notmuch_config_get_search_exclude_tags (notmuch_config_t *config, size_t *length)
\r
175 diff --git a/notmuch-new.c b/notmuch-new.c
\r
176 index a569a54..36d5c5d 100644
\r
177 --- a/notmuch-new.c
\r
178 +++ b/notmuch-new.c
\r
179 @@ -39,6 +39,8 @@ typedef struct {
\r
181 const char **new_tags;
\r
182 size_t new_tags_length;
\r
183 + const char **new_ignore;
\r
184 + size_t new_ignore_length;
\r
187 int processed_files;
\r
188 @@ -181,6 +183,20 @@ _entries_resemble_maildir (struct dirent **entries, int count)
\r
192 +/* Check if user asked to ignore these files/directories */
\r
195 +_entry_in_ignore_list (const char *entry, add_files_state_t *state)
\r
197 + size_t i, ignore_length = state->new_ignore_length;
\r
199 + for (i = 0; i < ignore_length; i++)
\r
200 + if (strcmp (entry, state->new_ignore[i]) == 0)
\r
206 /* Examine 'path' recursively as follows:
\r
208 * o Ask the filesystem for the mtime of 'path' (fs_mtime)
\r
209 @@ -320,15 +336,15 @@ add_files_recursive (notmuch_database_t *notmuch,
\r
212 /* Ignore special directories to avoid infinite recursion.
\r
213 - * Also ignore the .notmuch directory and any "tmp" directory
\r
214 - * that appears within a maildir.
\r
215 + * Also ignore the .notmuch directory, any "tmp" directory
\r
216 + * that appears within a maildir and files/directories
\r
217 + * user have configured to be ignored.
\r
219 - /* XXX: Eventually we'll want more sophistication to let the
\r
220 - * user specify files to be ignored. */
\r
221 if (strcmp (entry->d_name, ".") == 0 ||
\r
222 strcmp (entry->d_name, "..") == 0 ||
\r
223 (is_maildir && strcmp (entry->d_name, "tmp") == 0) ||
\r
224 - strcmp (entry->d_name, ".notmuch") ==0)
\r
225 + strcmp (entry->d_name, ".notmuch") == 0 ||
\r
226 + _entry_in_ignore_list (entry->d_name, state))
\r
230 @@ -369,6 +385,10 @@ add_files_recursive (notmuch_database_t *notmuch,
\r
232 entry = fs_entries[i];
\r
234 + /* Ignore files & directories user has configured to be ignored */
\r
235 + if (_entry_in_ignore_list (entry->d_name, state))
\r
238 /* Check if we've walked past any names in db_files or
\r
239 * db_subdirs. If so, these have been deleted. */
\r
240 while (notmuch_filenames_valid (db_files) &&
\r
241 @@ -648,7 +668,7 @@ add_files (notmuch_database_t *notmuch,
\r
242 * initialized to zero by the top-level caller before calling
\r
245 -count_files (const char *path, int *count)
\r
246 +count_files (const char *path, int *count, add_files_state_t *state)
\r
248 struct dirent *entry = NULL;
\r
250 @@ -670,13 +690,13 @@ count_files (const char *path, int *count)
\r
251 entry = fs_entries[i++];
\r
253 /* Ignore special directories to avoid infinite recursion.
\r
254 - * Also ignore the .notmuch directory.
\r
255 + * Also ignore the .notmuch directory and files/directories
\r
256 + * user have configured to be ignored.
\r
258 - /* XXX: Eventually we'll want more sophistication to let the
\r
259 - * user specify files to be ignored. */
\r
260 if (strcmp (entry->d_name, ".") == 0 ||
\r
261 strcmp (entry->d_name, "..") == 0 ||
\r
262 - strcmp (entry->d_name, ".notmuch") == 0)
\r
263 + strcmp (entry->d_name, ".notmuch") == 0 ||
\r
264 + _entry_in_ignore_list (entry->d_name, state))
\r
268 @@ -697,7 +717,7 @@ count_files (const char *path, int *count)
\r
271 } else if (S_ISDIR (st.st_mode)) {
\r
272 - count_files (next, count);
\r
273 + count_files (next, count, state);
\r
277 @@ -837,6 +857,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
\r
280 add_files_state.new_tags = notmuch_config_get_new_tags (config, &add_files_state.new_tags_length);
\r
281 + add_files_state.new_ignore = notmuch_config_get_new_ignore (config, &add_files_state.new_ignore_length);
\r
282 add_files_state.synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);
\r
283 db_path = notmuch_config_get_database_path (config);
\r
285 @@ -852,7 +873,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
\r
289 - count_files (db_path, &count);
\r
290 + count_files (db_path, &count, &add_files_state);
\r