1 Return-Path: <jani@nikula.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 3F01A429E43
\r
6 for <notmuch@notmuchmail.org>; Tue, 6 Dec 2011 05:22:55 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
8 X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"
\r
12 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5
\r
13 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled
\r
14 Received: from olra.theworths.org ([127.0.0.1])
\r
15 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
16 with ESMTP id J3YUBQJepI0F for <notmuch@notmuchmail.org>;
\r
17 Tue, 6 Dec 2011 05:22:52 -0800 (PST)
\r
18 Received: from mail-bw0-f53.google.com (mail-bw0-f53.google.com
\r
19 [209.85.214.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))
\r
20 (No client certificate requested)
\r
21 by olra.theworths.org (Postfix) with ESMTPS id CBABB429E34
\r
22 for <notmuch@notmuchmail.org>; Tue, 6 Dec 2011 05:22:50 -0800 (PST)
\r
23 Received: by mail-bw0-f53.google.com with SMTP id zu5so7357457bkb.26
\r
24 for <notmuch@notmuchmail.org>; Tue, 06 Dec 2011 05:22:50 -0800 (PST)
\r
25 Received: by 10.180.77.42 with SMTP id p10mr17525280wiw.66.1323177770222;
\r
26 Tue, 06 Dec 2011 05:22:50 -0800 (PST)
\r
27 Received: from localhost (dsl-hkibrasgw4-fe5cdc00-23.dhcp.inet.fi.
\r
28 [80.220.92.23]) by mx.google.com with ESMTPS id
\r
29 fy13sm33509491wbb.18.2011.12.06.05.22.47
\r
30 (version=SSLv3 cipher=OTHER); Tue, 06 Dec 2011 05:22:49 -0800 (PST)
\r
31 From: Jani Nikula <jani@nikula.org>
\r
32 To: notmuch@notmuchmail.org
\r
33 Subject: [PATCH v3 2/2] cli: add support for pre and post notmuch new hooks
\r
34 Date: Tue, 6 Dec 2011 15:22:38 +0200
\r
36 <90e2aa893a4d03b0094614f423c4c308115ac0d5.1323176771.git.jani@nikula.org>
\r
37 X-Mailer: git-send-email 1.7.5.4
\r
38 In-Reply-To: <cover.1323176771.git.jani@nikula.org>
\r
40 <7fbe6befcf31881a9bca672f55b93501249a220c.1322859389.git.jani@nikula.org>
\r
41 <cover.1323176771.git.jani@nikula.org>
\r
42 In-Reply-To: <cover.1323176771.git.jani@nikula.org>
\r
43 References: <cover.1323176771.git.jani@nikula.org>
\r
44 X-BeenThere: notmuch@notmuchmail.org
\r
45 X-Mailman-Version: 2.1.13
\r
47 List-Id: "Use and development of the notmuch mail system."
\r
48 <notmuch.notmuchmail.org>
\r
49 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
50 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
51 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
52 List-Post: <mailto:notmuch@notmuchmail.org>
\r
53 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
54 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
55 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
56 X-List-Received-Date: Tue, 06 Dec 2011 13:22:55 -0000
\r
58 Run notmuch new pre and post hooks, named "pre-new" and "post-new", if
\r
59 present in the notmuch hooks directory. The hooks will be run before and
\r
60 after incorporating new messages to the database.
\r
62 Typical use cases for pre-new and post-new hooks are fetching or delivering
\r
63 new mail to the maildir, and custom tagging of the mail incorporated to the
\r
66 Also add command line option --no-hooks to notmuch new to bypass the hooks.
\r
68 Signed-off-by: Jani Nikula <jani@nikula.org>
\r
70 NEWS | 10 ++++++++++
\r
71 notmuch-new.c | 12 ++++++++++++
\r
72 notmuch.1 | 50 +++++++++++++++++++++++++++++++++++++++++++++++++-
\r
73 notmuch.c | 39 ++++++++++++++++++++++++++++++++++++++-
\r
74 4 files changed, 109 insertions(+), 2 deletions(-)
\r
76 diff --git a/NEWS b/NEWS
\r
77 index 2b2f08a..a7c13a8 100644
\r
81 Notmuch 0.11 (201x-xx-xx)
\r
82 =========================
\r
84 +New command-line features
\r
85 +-------------------------
\r
89 + Hooks have been introduced to notmuch. Hooks are scripts that notmuch
\r
90 + invokes before and after certain actions. Initially, "notmuch new"
\r
91 + supports "pre-new" and "post-new" hooks that are run before and after
\r
92 + importing new messages into the database.
\r
97 diff --git a/notmuch-new.c b/notmuch-new.c
\r
98 index 81a9350..bfb4600 100644
\r
100 +++ b/notmuch-new.c
\r
101 @@ -811,6 +811,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
\r
102 _filename_node_t *f;
\r
104 notmuch_bool_t timer_is_active = FALSE;
\r
105 + notmuch_bool_t run_hooks = TRUE;
\r
107 add_files_state.verbose = 0;
\r
108 add_files_state.output_is_a_tty = isatty (fileno (stdout));
\r
109 @@ -820,6 +821,8 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
\r
110 for (i = 0; i < argc && argv[i][0] == '-'; i++) {
\r
111 if (STRNCMP_LITERAL (argv[i], "--verbose") == 0) {
\r
112 add_files_state.verbose = 1;
\r
113 + } else if (strcmp (argv[i], "--no-hooks") == 0) {
\r
114 + run_hooks = FALSE;
\r
116 fprintf (stderr, "Unrecognized option: %s\n", argv[i]);
\r
118 @@ -833,6 +836,12 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
\r
119 add_files_state.synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);
\r
120 db_path = notmuch_config_get_database_path (config);
\r
123 + ret = notmuch_run_hook (db_path, "pre-new");
\r
128 dot_notmuch_path = talloc_asprintf (ctx, "%s/%s", db_path, ".notmuch");
\r
130 if (stat (dot_notmuch_path, &st)) {
\r
131 @@ -981,5 +990,8 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
\r
133 notmuch_database_close (notmuch);
\r
135 + if (run_hooks && !ret && !interrupted)
\r
136 + ret = notmuch_run_hook (db_path, "post-new");
\r
138 return ret || interrupted;
\r
140 diff --git a/notmuch.1 b/notmuch.1
\r
141 index 92931d7..f631a5e 100644
\r
144 @@ -85,7 +85,7 @@ The
\r
145 command is used to incorporate new mail into the notmuch database.
\r
149 +.BR new " [options...]"
\r
151 Find and import any new messages to the database.
\r
153 @@ -118,6 +118,22 @@ if
\r
154 has previously been completed, but
\r
156 has not previously been run.
\r
160 +command supports hooks. See the
\r
162 +section below for more details on hooks.
\r
164 +Supported options for
\r
171 +Prevents hooks from being run.
\r
175 Several of the notmuch commands accept search terms with a common
\r
176 @@ -705,6 +721,38 @@ specify a date range to return messages from 2009\-10\-01 until the
\r
179 $(date +%s \-d 2009\-10\-01)..$(date +%s)
\r
181 +Hooks are scripts (or arbitrary executables or symlinks to such) that notmuch
\r
182 +invokes before and after certain actions. These scripts reside in
\r
183 +the .notmuch/hooks directory within the database directory and must have
\r
184 +executable permissions.
\r
186 +The currently available hooks are described below.
\r
190 +This hook is invoked by the
\r
192 +command before scanning or importing new messages into the database. If this
\r
193 +hook exits with a non-zero status, notmuch will abort further processing of the
\r
197 +Typically this hook is used for fetching or delivering new mail to be imported
\r
198 +into the database.
\r
203 +This hook is invoked by the
\r
205 +command after new messages have been imported into the database and initial tags
\r
206 +have been applied. The hook will not be run if there have been any errors during
\r
207 +the scan or import.
\r
209 +Typically this hook is used to perform additional query\-based tagging on the
\r
210 +imported messages.
\r
213 The following environment variables can be used to control the
\r
214 behavior of notmuch.
\r
215 diff --git a/notmuch.c b/notmuch.c
\r
216 index d44ce9a..c0ce026 100644
\r
219 @@ -127,6 +127,32 @@ static const char search_terms_help[] =
\r
221 "\t\t$(date +%%s -d 2009-10-01)..$(date +%%s)\n\n";
\r
223 +static const char hooks_help[] =
\r
224 + "\tHooks are scripts (or arbitrary executables or symlinks to such) that\n"
\r
225 + "\tnotmuch invokes before and after certain actions. These scripts reside\n"
\r
226 + "\tin the .notmuch/hooks directory within the database directory and must\n"
\r
227 + "\thave executable permissions.\n"
\r
229 + "\tThe currently available hooks are described below.\n"
\r
232 + "\t\tThis hook is invoked by the new command before scanning or\n"
\r
233 + "\t\timporting new messages into the database. If this hook exits\n"
\r
234 + "\t\twith a non-zero status, notmuch will abort further processing\n"
\r
235 + "\t\tof the new command.\n"
\r
237 + "\t\tTypically this hook is used for fetching or delivering new\n"
\r
238 + "\t\tmail to be imported into the database.\n"
\r
241 + "\t\tThis hook is invoked by the new command after new messages\n"
\r
242 + "\t\thave been imported into the database and initial tags have\n"
\r
243 + "\t\tbeen applied. The hook will not be run if there have been any\n"
\r
244 + "\t\terrors during the scan or import.\n"
\r
246 + "\t\tTypically this hook is used to perform additional query-based\n"
\r
247 + "\t\ttagging on the imported messages.\n\n";
\r
249 static command_t commands[] = {
\r
250 { "setup", notmuch_setup_command,
\r
252 @@ -144,7 +170,7 @@ static command_t commands[] = {
\r
253 "\tInvoking notmuch with no command argument will run setup if\n"
\r
254 "\tthe setup command has not previously been completed." },
\r
255 { "new", notmuch_new_command,
\r
258 "Find and import new messages to the notmuch database.",
\r
259 "\tScans all sub-directories of the mail directory, performing\n"
\r
260 "\tfull-text indexing on new messages that are found. Each new\n"
\r
261 @@ -159,8 +185,15 @@ static command_t commands[] = {
\r
262 "\tis delivered and you wish to incorporate it into the database.\n"
\r
263 "\tThese subsequent runs will be much quicker than the initial run.\n"
\r
265 + "\tThe new command supports hooks. See \"notmuch help hooks\" for\n"
\r
266 + "\tmore details on hooks.\n"
\r
268 "\tSupported options for new include:\n"
\r
272 + "\t\tPrevent hooks from being run.\n"
\r
276 "\t\tVerbose operation. Shows paths of message files as\n"
\r
277 @@ -529,6 +562,10 @@ notmuch_help_command (unused (void *ctx), int argc, char *argv[])
\r
279 printf (search_terms_help);
\r
281 + } else if (strcmp (argv[0], "hooks") == 0) {
\r
282 + printf ("Help for <%s>\n\n", argv[0]);
\r
283 + printf (hooks_help);
\r