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 B6919431FBC
\r
6 for <notmuch@notmuchmail.org>; Mon, 22 Feb 2010 12:27:37 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-0.384 tagged_above=-999 required=5
\r
12 tests=[AWL=-0.385, 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 W7Eq1ewMlHVw for <notmuch@notmuchmail.org>;
\r
16 Mon, 22 Feb 2010 12:27:34 -0800 (PST)
\r
17 X-Greylist: delayed 1415 seconds by postgrey-1.32 at olra;
\r
18 Mon, 22 Feb 2010 12:27:33 PST
\r
19 Received: from po8.org (po8.org [69.168.48.167])
\r
20 by olra.theworths.org (Postfix) with ESMTP id EE889431FAE
\r
21 for <notmuch@notmuchmail.org>; Mon, 22 Feb 2010 12:27:33 -0800 (PST)
\r
22 Received: from po8.org ([127.0.0.1]) by po8.org with esmtp (Exim 4.69)
\r
23 (envelope-from <bart@po8.org>) id 1NjeZ1-0001qw-HZ
\r
24 for notmuch@notmuchmail.org; Mon, 22 Feb 2010 12:07:34 -0800
\r
25 To: Notmuch Mail <notmuch@notmuchmail.org>
\r
26 From: Bart Massey <bart@po8.org>
\r
27 Date: Mon, 22 Feb 2010 12:07:31 -0800
\r
28 Sender: bart@po8.org
\r
29 Message-Id: <E1NjeZ1-0001qw-HZ@po8.org>
\r
30 Subject: [notmuch] [PATCH] Added mail directory filename pattern support.
\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: Mon, 22 Feb 2010 20:27:38 -0000
\r
45 Typically, the filenames in a mail directory that actually
\r
46 contain mail obey some specific format. For example, in my
\r
47 MH email directory, all mail filenames consist only of
\r
50 This patch adds support for a config file variable
\r
51 "filename_pattern" which maybe set to a regex used to filter
\r
52 only valid mail filenames when scanning. Effective use of
\r
53 filename_pattern cuts down on the noise from notmuch, and
\r
54 may speed it up in some cases.
\r
56 Signed-off-by: Bart Massey <bart@cs.pdx.edu>
\r
58 notmuch-client.h | 7 +++++++
\r
59 notmuch-config.c | 47 +++++++++++++++++++++++++++++++++++++++++++++--
\r
60 notmuch-new.c | 35 +++++++++++++++++++++++++++++++----
\r
61 3 files changed, 83 insertions(+), 6 deletions(-)
\r
63 diff --git a/notmuch-client.h b/notmuch-client.h
\r
64 index 77766de..191988c 100644
\r
65 --- a/notmuch-client.h
\r
66 +++ b/notmuch-client.h
\r
67 @@ -146,6 +146,13 @@ notmuch_config_set_database_path (notmuch_config_t *config,
\r
68 const char *database_path);
\r
71 +notmuch_config_get_filename_regex (notmuch_config_t *config);
\r
74 +notmuch_config_set_filename_regex (notmuch_config_t *config,
\r
75 + const char *filename_regex);
\r
78 notmuch_config_get_user_name (notmuch_config_t *config);
\r
81 diff --git a/notmuch-config.c b/notmuch-config.c
\r
82 index 95430db..4189f03 100644
\r
83 --- a/notmuch-config.c
\r
84 +++ b/notmuch-config.c
\r
85 @@ -31,11 +31,22 @@ static const char toplevel_config_comment[] =
\r
86 static const char database_config_comment[] =
\r
87 " Database configuration\n"
\r
89 - " The only value supported here is 'path' which should be the top-level\n"
\r
90 + " The value 'path' should be the top-level\n"
\r
91 " directory where your mail currently exists and to where mail will be\n"
\r
92 " delivered in the future. Files should be individual email messages.\n"
\r
93 " Notmuch will store its database within a sub-directory of the path\n"
\r
94 - " configured here named \".notmuch\".\n";
\r
95 + " configured here named \".notmuch\".\n"
\r
97 + " The optional value 'filename_pattern' should be\n"
\r
98 + " a POSIX regular expression matching only those\n"
\r
99 + " filenames that will be checked for email\n"
\r
100 + " messages. The match is against the last\n"
\r
101 + " component of the pathname only. Anchors may be\n"
\r
102 + " used, and probably should be. Typically, this\n"
\r
103 + " is used to match only files whose name is a\n"
\r
104 + " number ala MH, or to match only files in\n"
\r
105 + " standard maildir format. The default pattern\n"
\r
106 + " matches anything.\n";
\r
108 static const char user_config_comment[] =
\r
109 " User configuration\n"
\r
110 @@ -58,6 +69,7 @@ struct _notmuch_config {
\r
111 GKeyFile *key_file;
\r
113 char *database_path;
\r
114 + char *filename_regex;
\r
116 char *user_primary_email;
\r
117 char **user_other_email;
\r
118 @@ -151,6 +163,8 @@ get_username_from_passwd_file (void *ctx)
\r
120 * database_path: $HOME/mail
\r
122 + * filename_pattern: .*
\r
124 * user_name: From /etc/passwd
\r
126 * user_primary_mail: $EMAIL variable if set, otherwise
\r
127 @@ -195,6 +209,7 @@ notmuch_config_open (void *ctx,
\r
128 config->key_file = g_key_file_new ();
\r
130 config->database_path = NULL;
\r
131 + config->filename_regex = NULL;
\r
132 config->user_name = NULL;
\r
133 config->user_primary_email = NULL;
\r
134 config->user_other_email = NULL;
\r
135 @@ -354,6 +369,34 @@ notmuch_config_set_database_path (notmuch_config_t *config,
\r
139 +notmuch_config_get_filename_regex (notmuch_config_t *config)
\r
143 + if (config->filename_regex == NULL) {
\r
144 + regex = g_key_file_get_string (config->key_file,
\r
145 + "database", "filename_pattern", NULL);
\r
147 + config->filename_regex = talloc_strdup (config, regex);
\r
152 + return config->filename_regex;
\r
156 +notmuch_config_set_filename_regex (notmuch_config_t *config,
\r
157 + const char *filename_regex)
\r
159 + g_key_file_set_string (config->key_file,
\r
160 + "database", "filename_pattern", filename_regex);
\r
162 + talloc_free (config->filename_regex);
\r
163 + config->filename_regex = NULL;
\r
167 notmuch_config_get_user_name (notmuch_config_t *config)
\r
170 diff --git a/notmuch-new.c b/notmuch-new.c
\r
171 index f25c71f..531f9a3 100644
\r
172 --- a/notmuch-new.c
\r
173 +++ b/notmuch-new.c
\r
175 #include "notmuch-client.h"
\r
177 #include <unistd.h>
\r
178 +#include <sys/types.h>
\r
179 +#include <regex.h>
\r
181 typedef struct _filename_node {
\r
183 @@ -207,6 +209,7 @@ _entries_resemble_maildir (struct dirent **entries, int count)
\r
184 static notmuch_status_t
\r
185 add_files_recursive (notmuch_database_t *notmuch,
\r
187 + const regex_t *maybe_regex,
\r
188 add_files_state_t *state)
\r
191 @@ -302,7 +305,7 @@ add_files_recursive (notmuch_database_t *notmuch,
\r
194 next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name);
\r
195 - status = add_files_recursive (notmuch, next, state);
\r
196 + status = add_files_recursive (notmuch, next, maybe_regex, state);
\r
197 if (status && ret == NOTMUCH_STATUS_SUCCESS)
\r
199 talloc_free (next);
\r
200 @@ -389,7 +392,7 @@ add_files_recursive (notmuch_database_t *notmuch,
\r
203 /* We're now looking at a regular file that doesn't yet exist
\r
204 - * in the database, so add it. */
\r
205 + * in the database. */
\r
206 next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name);
\r
208 state->processed_files++;
\r
209 @@ -407,6 +410,14 @@ add_files_recursive (notmuch_database_t *notmuch,
\r
213 + /* Check against the regex (if any) for valid mail
\r
214 + * file names and bail on failure */
\r
215 + if (maybe_regex) {
\r
216 + status = regexec(maybe_regex, entry->d_name, 0, 0, 0);
\r
221 status = notmuch_database_add_message (notmuch, next, &message);
\r
224 @@ -445,6 +456,7 @@ add_files_recursive (notmuch_database_t *notmuch,
\r
229 if (do_add_files_print_progress) {
\r
230 do_add_files_print_progress = 0;
\r
231 add_files_print_progress (state);
\r
232 @@ -509,6 +521,7 @@ add_files_recursive (notmuch_database_t *notmuch,
\r
233 static notmuch_status_t
\r
234 add_files (notmuch_database_t *notmuch,
\r
236 + const regex_t *maybe_regex,
\r
237 add_files_state_t *state)
\r
239 notmuch_status_t status;
\r
240 @@ -546,7 +559,7 @@ add_files (notmuch_database_t *notmuch,
\r
241 return NOTMUCH_STATUS_FILE_ERROR;
\r
244 - status = add_files_recursive (notmuch, path, state);
\r
245 + status = add_files_recursive (notmuch, path, maybe_regex, state);
\r
247 if (timer_is_active) {
\r
248 /* Now stop the timer. */
\r
249 @@ -713,6 +726,9 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
\r
252 const char *db_path;
\r
253 + const char *filename_regex;
\r
255 + const regex_t *maybe_regex = 0;
\r
256 char *dot_notmuch_path;
\r
257 struct sigaction action;
\r
258 _filename_node_t *f;
\r
259 @@ -738,6 +754,17 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
\r
261 db_path = notmuch_config_get_database_path (config);
\r
263 + filename_regex = notmuch_config_get_filename_regex (config);
\r
264 + if (filename_regex) {
\r
265 + status = regcomp(®ex, filename_regex, REG_EXTENDED | REG_NOSUB);
\r
267 + fprintf (stderr, "Note: Ignoring bad filename_pattern "
\r
268 + "in config file: %s\n", filename_regex);
\r
270 + maybe_regex = ®ex;
\r
274 dot_notmuch_path = talloc_asprintf (ctx, "%s/%s", db_path, ".notmuch");
\r
276 if (stat (dot_notmuch_path, &st)) {
\r
277 @@ -791,7 +818,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
\r
278 add_files_state.removed_files = _filename_list_create (ctx);
\r
279 add_files_state.removed_directories = _filename_list_create (ctx);
\r
281 - ret = add_files (notmuch, db_path, &add_files_state);
\r
282 + ret = add_files (notmuch, db_path, maybe_regex, &add_files_state);
\r