aboutsummaryrefslogtreecommitdiff
path: root/notmuch-new.c
diff options
context:
space:
mode:
authorJani Nikula <jani@nikula.org>2011-12-09 00:48:30 +0200
committerDavid Bremner <bremner@debian.org>2011-12-11 13:58:15 -0400
commit69bb7f35b6e59fd3a3b1fb2d0f0367f7016cba80 (patch)
tree0e92645d33017b082c28a3de6e82f73213300f74 /notmuch-new.c
parentd399b6b909fe6e2c6073464006061382c8bb31d5 (diff)
cli: add support for pre and post notmuch new hooks
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>
Diffstat (limited to 'notmuch-new.c')
-rw-r--r--notmuch-new.c12
1 files changed, 12 insertions, 0 deletions
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;
}