From: Jani Nikula <jani@nikula.org>
To: notmuch@notmuchmail.org
Subject: [PATCH v3 2/2] cli: add support for pre and post notmuch new hooks
Date: Tue, 6 Dec 2011 15:22:38 +0200 [thread overview]
Message-ID: <90e2aa893a4d03b0094614f423c4c308115ac0d5.1323176771.git.jani@nikula.org> (raw)
In-Reply-To: <cover.1323176771.git.jani@nikula.org>
In-Reply-To: <cover.1323176771.git.jani@nikula.org>
Run notmuch new pre and post hooks, named "pre-new" and "post-new", if
present in the notmuch hooks directory. The hooks will be run before and
after incorporating new messages to the database.
Typical use cases for pre-new and post-new hooks are fetching or delivering
new mail to the maildir, and custom tagging of the mail incorporated to the
database.
Also add command line option --no-hooks to notmuch new to bypass the hooks.
Signed-off-by: Jani Nikula <jani@nikula.org>
---
NEWS | 10 ++++++++++
notmuch-new.c | 12 ++++++++++++
notmuch.1 | 50 +++++++++++++++++++++++++++++++++++++++++++++++++-
notmuch.c | 39 ++++++++++++++++++++++++++++++++++++++-
4 files changed, 109 insertions(+), 2 deletions(-)
diff --git a/NEWS b/NEWS
index 2b2f08a..a7c13a8 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,16 @@
Notmuch 0.11 (201x-xx-xx)
=========================
+New command-line features
+-------------------------
+
+Hooks
+
+ Hooks have been introduced to notmuch. Hooks are scripts that notmuch
+ invokes before and after certain actions. Initially, "notmuch new"
+ supports "pre-new" and "post-new" hooks that are run before and after
+ importing new messages into the database.
+
Performance
-----------
diff --git a/notmuch-new.c b/notmuch-new.c
index 81a9350..bfb4600 100644
--- a/notmuch-new.c
+++ b/notmuch-new.c
@@ -811,6 +811,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
_filename_node_t *f;
int i;
notmuch_bool_t timer_is_active = FALSE;
+ notmuch_bool_t run_hooks = TRUE;
add_files_state.verbose = 0;
add_files_state.output_is_a_tty = isatty (fileno (stdout));
@@ -820,6 +821,8 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
for (i = 0; i < argc && argv[i][0] == '-'; i++) {
if (STRNCMP_LITERAL (argv[i], "--verbose") == 0) {
add_files_state.verbose = 1;
+ } else if (strcmp (argv[i], "--no-hooks") == 0) {
+ run_hooks = FALSE;
} else {
fprintf (stderr, "Unrecognized option: %s\n", argv[i]);
return 1;
@@ -833,6 +836,12 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
add_files_state.synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);
db_path = notmuch_config_get_database_path (config);
+ if (run_hooks) {
+ ret = notmuch_run_hook (db_path, "pre-new");
+ if (ret)
+ return ret;
+ }
+
dot_notmuch_path = talloc_asprintf (ctx, "%s/%s", db_path, ".notmuch");
if (stat (dot_notmuch_path, &st)) {
@@ -981,5 +990,8 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
notmuch_database_close (notmuch);
+ if (run_hooks && !ret && !interrupted)
+ ret = notmuch_run_hook (db_path, "post-new");
+
return ret || interrupted;
}
diff --git a/notmuch.1 b/notmuch.1
index 92931d7..f631a5e 100644
--- a/notmuch.1
+++ b/notmuch.1
@@ -85,7 +85,7 @@ The
command is used to incorporate new mail into the notmuch database.
.RS 4
.TP 4
-.B new
+.BR new " [options...]"
Find and import any new messages to the database.
@@ -118,6 +118,22 @@ if
has previously been completed, but
.B "notmuch new"
has not previously been run.
+
+The
+.B new
+command supports hooks. See the
+.B "HOOKS"
+section below for more details on hooks.
+
+Supported options for
+.B new
+include
+.RS 4
+.TP 4
+.BR \-\-no\-hooks
+
+Prevents hooks from being run.
+.RE
.RE
Several of the notmuch commands accept search terms with a common
@@ -705,6 +721,38 @@ specify a date range to return messages from 2009\-10\-01 until the
current time:
$(date +%s \-d 2009\-10\-01)..$(date +%s)
+.SH HOOKS
+Hooks are scripts (or arbitrary executables or symlinks to such) that notmuch
+invokes before and after certain actions. These scripts reside in
+the .notmuch/hooks directory within the database directory and must have
+executable permissions.
+
+The currently available hooks are described below.
+.RS 4
+.TP 4
+.B pre\-new
+This hook is invoked by the
+.B new
+command before scanning or importing new messages into the database. If this
+hook exits with a non-zero status, notmuch will abort further processing of the
+.B new
+command.
+
+Typically this hook is used for fetching or delivering new mail to be imported
+into the database.
+.RE
+.RS 4
+.TP 4
+.B post\-new
+This hook is invoked by the
+.B new
+command after new messages have been imported into the database and initial tags
+have been applied. The hook will not be run if there have been any errors during
+the scan or import.
+
+Typically this hook is used to perform additional query\-based tagging on the
+imported messages.
+.RE
.SH ENVIRONMENT
The following environment variables can be used to control the
behavior of notmuch.
diff --git a/notmuch.c b/notmuch.c
index d44ce9a..c0ce026 100644
--- a/notmuch.c
+++ b/notmuch.c
@@ -127,6 +127,32 @@ static const char search_terms_help[] =
"\n"
"\t\t$(date +%%s -d 2009-10-01)..$(date +%%s)\n\n";
+static const char hooks_help[] =
+ "\tHooks are scripts (or arbitrary executables or symlinks to such) that\n"
+ "\tnotmuch invokes before and after certain actions. These scripts reside\n"
+ "\tin the .notmuch/hooks directory within the database directory and must\n"
+ "\thave executable permissions.\n"
+ "\n"
+ "\tThe currently available hooks are described below.\n"
+ "\n"
+ "\tpre-new\n"
+ "\t\tThis hook is invoked by the new command before scanning or\n"
+ "\t\timporting new messages into the database. If this hook exits\n"
+ "\t\twith a non-zero status, notmuch will abort further processing\n"
+ "\t\tof the new command.\n"
+ "\n"
+ "\t\tTypically this hook is used for fetching or delivering new\n"
+ "\t\tmail to be imported into the database.\n"
+ "\n"
+ "\tpost-new\n"
+ "\t\tThis hook is invoked by the new command after new messages\n"
+ "\t\thave been imported into the database and initial tags have\n"
+ "\t\tbeen applied. The hook will not be run if there have been any\n"
+ "\t\terrors during the scan or import.\n"
+ "\n"
+ "\t\tTypically this hook is used to perform additional query-based\n"
+ "\t\ttagging on the imported messages.\n\n";
+
static command_t commands[] = {
{ "setup", notmuch_setup_command,
NULL,
@@ -144,7 +170,7 @@ static command_t commands[] = {
"\tInvoking notmuch with no command argument will run setup if\n"
"\tthe setup command has not previously been completed." },
{ "new", notmuch_new_command,
- "[--verbose]",
+ "[options...]",
"Find and import new messages to the notmuch database.",
"\tScans all sub-directories of the mail directory, performing\n"
"\tfull-text indexing on new messages that are found. Each new\n"
@@ -159,8 +185,15 @@ static command_t commands[] = {
"\tis delivered and you wish to incorporate it into the database.\n"
"\tThese subsequent runs will be much quicker than the initial run.\n"
"\n"
+ "\tThe new command supports hooks. See \"notmuch help hooks\" for\n"
+ "\tmore details on hooks.\n"
+ "\n"
"\tSupported options for new include:\n"
"\n"
+ "\t--no-hooks\n"
+ "\n"
+ "\t\tPrevent hooks from being run.\n"
+ "\n"
"\t--verbose\n"
"\n"
"\t\tVerbose operation. Shows paths of message files as\n"
@@ -529,6 +562,10 @@ notmuch_help_command (unused (void *ctx), int argc, char *argv[])
printf ("\n");
printf (search_terms_help);
return 0;
+ } else if (strcmp (argv[0], "hooks") == 0) {
+ printf ("Help for <%s>\n\n", argv[0]);
+ printf (hooks_help);
+ return 0;
}
fprintf (stderr,
--
1.7.5.4
next prev parent reply other threads:[~2011-12-06 13:22 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-02 21:00 [PATCH 1/2] cli: add mechanism for running user configurable hooks Jani Nikula
2011-12-02 21:00 ` [PATCH 2/2] cli: add support for running notmuch new pre and post hooks Jani Nikula
2011-12-02 21:05 ` [PATCH 1/2] cli: add mechanism for running user configurable hooks Jani Nikula
2011-12-03 23:16 ` [PATCH v2 1/2] cli: introduce the concept of user defined hooks Jani Nikula
2011-12-03 23:16 ` [PATCH v2 2/2] cli: add support for pre and post notmuch new hooks Jani Nikula
2011-12-04 4:00 ` Austin Clements
2011-12-04 19:36 ` Jani Nikula
2011-12-04 19:54 ` Tom Prince
2011-12-04 16:46 ` Tom Prince
2011-12-04 19:56 ` Jani Nikula
2011-12-04 3:42 ` [PATCH v2 1/2] cli: introduce the concept of user defined hooks Austin Clements
2011-12-04 12:35 ` Jani Nikula
2011-12-04 16:41 ` Austin Clements
2011-12-06 13:22 ` [PATCH v3 0/2] notmuch hooks Jani Nikula
2011-12-06 13:22 ` [PATCH v3 1/2] cli: introduce the concept of user defined hooks Jani Nikula
2011-12-06 13:30 ` Jani Nikula
2011-12-06 13:22 ` Jani Nikula [this message]
2011-12-07 2:27 ` [PATCH v3 0/2] notmuch hooks Jameson Graef Rollins
2011-12-07 19:42 ` Jani Nikula
2011-12-07 22:13 ` Jameson Graef Rollins
2011-12-08 8:49 ` Tomi Ollila
2011-12-08 16:29 ` Jameson Graef Rollins
2011-12-07 2:47 ` Jameson Graef Rollins
2011-12-07 3:16 ` Tom Prince
2011-12-07 18:05 ` Jani Nikula
2011-12-07 18:10 ` Jameson Graef Rollins
2011-12-07 20:11 ` Austin Clements
2011-12-08 22:48 ` [PATCH v4 0/3] " Jani Nikula
2011-12-08 22:48 ` [PATCH v4 1/3] cli: introduce the concept of user defined hooks Jani Nikula
2011-12-08 23:34 ` Austin Clements
2011-12-09 13:55 ` Jani Nikula
2011-12-09 15:59 ` Austin Clements
2011-12-08 22:48 ` [PATCH v4 2/3] cli: add support for pre and post notmuch new hooks Jani Nikula
2011-12-08 22:48 ` [PATCH v4 3/3] test: add tests for hooks Jani Nikula
2011-12-10 22:04 ` [PATCH v4 0/3] notmuch hooks Jameson Graef Rollins
2011-12-11 18:29 ` David Bremner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=90e2aa893a4d03b0094614f423c4c308115ac0d5.1323176771.git.jani@nikula.org \
--to=jani@nikula.org \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).