1 Return-Path: <bart@po8.org>
\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 EEF80431FBC
\r
6 for <notmuch@notmuchmail.org>; Sun, 17 Jan 2010 17:25:27 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=0.001 tagged_above=-999 required=5
\r
12 tests=[BAYES_50=0.001] autolearn=ham
\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 maL95tqVy7iq for <notmuch@notmuchmail.org>;
\r
16 Sun, 17 Jan 2010 17:25:27 -0800 (PST)
\r
17 Received: from mout.perfora.net (mout.perfora.net [74.208.4.194])
\r
18 by olra.theworths.org (Postfix) with ESMTP id EFCCA431FAE
\r
19 for <notmuch@notmuchmail.org>; Sun, 17 Jan 2010 17:25:26 -0800 (PST)
\r
20 Received: from po8.org (po8.org [69.168.48.167])
\r
21 by mx.perfora.net (node=mxus2) with ESMTP (Nemesis)
\r
22 id 0LlCbW-1O6IZH1pJe-00b4ZE for notmuch@notmuchmail.org;
\r
23 Sun, 17 Jan 2010 20:25:26 -0500
\r
24 Received: from po8.org ([127.0.0.1]) by po8.org with esmtp (Exim 4.69)
\r
25 (envelope-from <bart@po8.org>) id 1NWgMo-0001qb-Vn
\r
26 for notmuch@notmuchmail.org; Sun, 17 Jan 2010 17:25:23 -0800
\r
27 To: notmuch@notmuchmail.org
\r
28 From: Bart Massey <bart@po8.org>
\r
30 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
\r
31 Content-ID: <7050.1263777618.0@po8.org>
\r
32 Date: Sun, 17 Jan 2010 17:25:18 -0800
\r
33 Sender: bart@po8.org
\r
34 Message-Id: <E1NWgMo-0001qb-Vn@po8.org>
\r
35 Subject: [notmuch] [PATCH] notmuch new: support for filename pattern
\r
37 X-BeenThere: notmuch@notmuchmail.org
\r
38 X-Mailman-Version: 2.1.13
\r
40 List-Id: "Use and development of the notmuch mail system."
\r
41 <notmuch.notmuchmail.org>
\r
42 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
43 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
44 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
45 List-Post: <mailto:notmuch@notmuchmail.org>
\r
46 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
47 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
48 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
49 X-List-Received-Date: Mon, 18 Jan 2010 01:25:28 -0000
\r
51 ------- =_aaaaaaaaaa0
\r
52 Content-Type: text/plain; charset="us-ascii"
\r
53 Content-ID: <7050.1263777618.1@po8.org>
\r
55 Together with the new support for message deletion (thank
\r
56 you!) this patch lets me use notmuch in parallel with MH
\r
57 pretty successfully.
\r
62 ------- =_aaaaaaaaaa0
\r
63 Content-Type: text/x-csrc;
\r
64 name="0001-notmuch-new-support-for-filename-pattern-filtering.patch";
\r
66 Content-ID: <7050.1263777618.2@po8.org>
\r
68 >From 9418781ad8f1efed5e0866d351ce9d5baf584500 Mon Sep 17 00:00:00 2001
\r
69 From: Bart Massey <bart@po8.org>
\r
70 Date: Sun, 17 Jan 2010 17:00:47 -0800
\r
71 Subject: [PATCH] notmuch new: support for filename pattern filtering
\r
73 In most maildir formats, only filenames consisting only of
\r
74 digits should be candidate emails. We add a new option
\r
75 "filename_pattern" in the "database" section of the config
\r
76 file that takes a regexp to filter candidate filenames
\r
77 against. By setting this string to "^[0-9]+$" only files
\r
78 that match this pattern will even be considered. This will
\r
79 inhibit bogus "Notice: non-mail" messages, and may also
\r
80 noticeably improve the efficiency of the tool if, for
\r
81 example, large mbox files are left lying around in the
\r
84 Signed-off-by: Bart Massey <bart@po8.org>
\r
86 notmuch-client.h | 7 +++++++
\r
87 notmuch-config.c | 46 ++++++++++++++++++++++++++++++++++++++++++++--
\r
88 notmuch-new.c | 35 +++++++++++++++++++++++++++++++----
\r
89 3 files changed, 82 insertions(+), 6 deletions(-)
\r
91 diff --git a/notmuch-client.h b/notmuch-client.h
\r
92 index 77766de..191988c 100644
\r
93 --- a/notmuch-client.h
\r
94 +++ b/notmuch-client.h
\r
95 @@ -146,6 +146,13 @@ notmuch_config_set_database_path (notmuch_config_t *config,
\r
96 const char *database_path);
\r
99 +notmuch_config_get_filename_regex (notmuch_config_t *config);
\r
102 +notmuch_config_set_filename_regex (notmuch_config_t *config,
\r
103 + const char *filename_regex);
\r
106 notmuch_config_get_user_name (notmuch_config_t *config);
\r
109 diff --git a/notmuch-config.c b/notmuch-config.c
\r
110 index 95430db..edfb4a6 100644
\r
111 --- a/notmuch-config.c
\r
112 +++ b/notmuch-config.c
\r
113 @@ -31,11 +31,21 @@ static const char toplevel_config_comment[] =
\r
114 static const char database_config_comment[] =
\r
115 " Database configuration\n"
\r
117 - " The only value supported here is 'path' which should be the top-level\n"
\r
118 + " The value 'path' should be the top-level\n"
\r
119 " directory where your mail currently exists and to where mail will be\n"
\r
120 " delivered in the future. Files should be individual email messages.\n"
\r
121 " Notmuch will store its database within a sub-directory of the path\n"
\r
122 - " configured here named \".notmuch\".\n";
\r
123 + " configured here named \".notmuch\".\n"
\r
125 + " The optional value 'filename_pattern' should be a POSIX"
\r
126 + " regular expression\n"
\r
127 + " matching only those filenames that will be checked for email\n"
\r
128 + " messages. The match is against the last component of the pathname\n"
\r
129 + " only. Anchors may be used, and probably should be.\n"
\r
130 + " Typically, this is used to match only\n"
\r
131 + " files whose name is a number in standard maildir format. The\n"
\r
132 + " default pattern matches anything.\n" ;
\r
135 static const char user_config_comment[] =
\r
136 " User configuration\n"
\r
137 @@ -58,6 +68,7 @@ struct _notmuch_config {
\r
138 GKeyFile *key_file;
\r
140 char *database_path;
\r
141 + char *filename_regex;
\r
143 char *user_primary_email;
\r
144 char **user_other_email;
\r
145 @@ -151,6 +162,8 @@ get_username_from_passwd_file (void *ctx)
\r
147 * database_path: $HOME/mail
\r
149 + * filename_pattern: .*
\r
151 * user_name: From /etc/passwd
\r
153 * user_primary_mail: $EMAIL variable if set, otherwise
\r
154 @@ -195,6 +208,7 @@ notmuch_config_open (void *ctx,
\r
155 config->key_file = g_key_file_new ();
\r
157 config->database_path = NULL;
\r
158 + config->filename_regex = NULL;
\r
159 config->user_name = NULL;
\r
160 config->user_primary_email = NULL;
\r
161 config->user_other_email = NULL;
\r
162 @@ -354,6 +368,34 @@ notmuch_config_set_database_path (notmuch_config_t *config,
\r
166 +notmuch_config_get_filename_regex (notmuch_config_t *config)
\r
170 + if (config->filename_regex == NULL) {
\r
171 + regex = g_key_file_get_string (config->key_file,
\r
172 + "database", "filename_pattern", NULL);
\r
174 + config->filename_regex = talloc_strdup (config, regex);
\r
179 + return config->filename_regex;
\r
183 +notmuch_config_set_filename_regex (notmuch_config_t *config,
\r
184 + const char *filename_regex)
\r
186 + g_key_file_set_string (config->key_file,
\r
187 + "database", "filename_pattern", filename_regex);
\r
189 + talloc_free (config->filename_regex);
\r
190 + config->filename_regex = NULL;
\r
194 notmuch_config_get_user_name (notmuch_config_t *config)
\r
197 diff --git a/notmuch-new.c b/notmuch-new.c
\r
198 index b740ee2..ab7ef9e 100644
\r
199 --- a/notmuch-new.c
\r
200 +++ b/notmuch-new.c
\r
202 #include "notmuch-client.h"
\r
204 #include <unistd.h>
\r
205 +#include <sys/types.h>
\r
206 +#include <regex.h>
\r
208 typedef struct _filename_node {
\r
210 @@ -207,6 +209,7 @@ _entries_resemble_maildir (struct dirent **entries, int count)
\r
211 static notmuch_status_t
\r
212 add_files_recursive (notmuch_database_t *notmuch,
\r
214 + const regex_t *maybe_regex,
\r
215 add_files_state_t *state)
\r
218 @@ -291,7 +294,7 @@ add_files_recursive (notmuch_database_t *notmuch,
\r
221 next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name);
\r
222 - status = add_files_recursive (notmuch, next, state);
\r
223 + status = add_files_recursive (notmuch, next, maybe_regex, state);
\r
224 if (status && ret == NOTMUCH_STATUS_SUCCESS)
\r
226 talloc_free (next);
\r
227 @@ -372,7 +375,7 @@ add_files_recursive (notmuch_database_t *notmuch,
\r
230 /* We're now looking at a regular file that doesn't yet exist
\r
231 - * in the database, so add it. */
\r
232 + * in the database. */
\r
233 next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name);
\r
235 state->processed_files++;
\r
236 @@ -390,6 +393,14 @@ add_files_recursive (notmuch_database_t *notmuch,
\r
240 + /* Check against the regex (if any) for valid mail
\r
241 + * file names and bail on failure */
\r
242 + if (maybe_regex) {
\r
243 + status = regexec(maybe_regex, entry->d_name, 0, 0, 0);
\r
248 status = notmuch_database_add_message (notmuch, next, &message);
\r
251 @@ -428,6 +439,7 @@ add_files_recursive (notmuch_database_t *notmuch,
\r
256 if (do_add_files_print_progress) {
\r
257 do_add_files_print_progress = 0;
\r
258 add_files_print_progress (state);
\r
259 @@ -492,6 +504,7 @@ add_files_recursive (notmuch_database_t *notmuch,
\r
260 static notmuch_status_t
\r
261 add_files (notmuch_database_t *notmuch,
\r
263 + const regex_t *maybe_regex,
\r
264 add_files_state_t *state)
\r
266 notmuch_status_t status;
\r
267 @@ -529,7 +542,7 @@ add_files (notmuch_database_t *notmuch,
\r
268 return NOTMUCH_STATUS_FILE_ERROR;
\r
271 - status = add_files_recursive (notmuch, path, state);
\r
272 + status = add_files_recursive (notmuch, path, maybe_regex, state);
\r
274 if (timer_is_active) {
\r
275 /* Now stop the timer. */
\r
276 @@ -696,6 +709,9 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
\r
279 const char *db_path;
\r
280 + const char *filename_regex;
\r
282 + const regex_t *maybe_regex = 0;
\r
283 char *dot_notmuch_path;
\r
284 struct sigaction action;
\r
285 _filename_node_t *f;
\r
286 @@ -721,6 +737,17 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
\r
288 db_path = notmuch_config_get_database_path (config);
\r
290 + filename_regex = notmuch_config_get_filename_regex (config);
\r
291 + if (filename_regex) {
\r
292 + status = regcomp(®ex, filename_regex, REG_EXTENDED | REG_NOSUB);
\r
294 + fprintf (stderr, "Note: Ignoring bad filename_pattern "
\r
295 + "in config file: %s\n", filename_regex);
\r
297 + maybe_regex = ®ex;
\r
301 dot_notmuch_path = talloc_asprintf (ctx, "%s/%s", db_path, ".notmuch");
\r
303 if (stat (dot_notmuch_path, &st)) {
\r
304 @@ -774,7 +801,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
\r
305 add_files_state.removed_files = _filename_list_create (ctx);
\r
306 add_files_state.removed_directories = _filename_list_create (ctx);
\r
308 - ret = add_files (notmuch, db_path, &add_files_state);
\r
309 + ret = add_files (notmuch, db_path, maybe_regex, &add_files_state);
\r
316 ------- =_aaaaaaaaaa0--
\r