]> git.notmuchmail.org Git - notmuch/commitdiff
cli/insert: add post-insert hook
authorJani Nikula <jani@nikula.org>
Sun, 28 Sep 2014 14:40:59 +0000 (17:40 +0300)
committerDavid Bremner <david@tethera.net>
Tue, 28 Oct 2014 18:19:30 +0000 (19:19 +0100)
The post-new hook might no longer be needed or run very often if
notmuch insert is being used. Therefore a post-insert hook is needed
(arguably pre-insert not so much, so don't add one). Also add the
--no-hooks option to skip hooks.

doc/man1/notmuch-insert.rst
doc/man5/notmuch-hooks.rst
notmuch-insert.c

index e396f6cf2279402ea0425ab48dbf6970868093db..2c9c0d02c25190fa891f4cd417fb58d06128cb82 100644 (file)
@@ -25,6 +25,9 @@ If the new message is a duplicate of an existing message in the database
 (it has same Message-ID), it will be added to the maildir folder and
 notmuch database, but the tags will not be changed.
 
 (it has same Message-ID), it will be added to the maildir folder and
 notmuch database, but the tags will not be changed.
 
+The **insert** command supports hooks. See **notmuch-hooks(5)** for
+more details on hooks.
+
 Option arguments must appear before any tag operation arguments.
 Supported options for **insert** include
 
 Option arguments must appear before any tag operation arguments.
 Supported options for **insert** include
 
@@ -44,6 +47,9 @@ Supported options for **insert** include
         fails. Ignore these errors and return exit status 0 to
         indicate succesful mail delivery.
 
         fails. Ignore these errors and return exit status 0 to
         indicate succesful mail delivery.
 
+    ``--no-hooks``
+        Prevent hooks from being run.
+
 EXIT STATUS
 ===========
 
 EXIT STATUS
 ===========
 
@@ -54,6 +60,9 @@ indexing to Notmuch database, changing tags, and synchronizing tags to
 maildir flags. The ``--keep`` option may be used to settle for
 successful message file delivery.
 
 maildir flags. The ``--keep`` option may be used to settle for
 successful message file delivery.
 
+The exit status of the **post-insert** hook does not affect the exit
+status of the **insert** command.
+
 SEE ALSO
 ========
 
 SEE ALSO
 ========
 
index 493abf20f0039a62e17355e5dc1fe757579f40be..f1c2528c5666b2dbd4e8ce1c5ae8f43b44f174de 100644 (file)
@@ -35,6 +35,17 @@ The currently available hooks are described below.
         Typically this hook is used to perform additional query-based
         tagging on the imported messages.
 
         Typically this hook is used to perform additional query-based
         tagging on the imported messages.
 
+    **post-insert**
+
+        This hook is invoked by the **insert** command after the
+        message has been delivered, added to the database, and initial
+        tags have been applied. The hook will not be run if there have
+        been any errors during the message delivery; what is regarded
+        as succesful delivery depends on the ``--keep`` option.
+
+        Typically this hook is used to perform additional query-based
+        tagging on the delivered messages.
+
 SEE ALSO
 ========
 
 SEE ALSO
 ========
 
index 0d2d810a35740f6edead0523ddb9352c05548383..90fe3bad2bfb7291d3d81e6deafb50e6b62d913e 100644 (file)
@@ -454,6 +454,7 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])
     const char *folder = NULL;
     notmuch_bool_t create_folder = FALSE;
     notmuch_bool_t keep = FALSE;
     const char *folder = NULL;
     notmuch_bool_t create_folder = FALSE;
     notmuch_bool_t keep = FALSE;
+    notmuch_bool_t no_hooks = FALSE;
     notmuch_bool_t synchronize_flags;
     const char *maildir;
     char *newpath;
     notmuch_bool_t synchronize_flags;
     const char *maildir;
     char *newpath;
@@ -464,6 +465,7 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])
        { NOTMUCH_OPT_STRING, &folder, "folder", 0, 0 },
        { NOTMUCH_OPT_BOOLEAN, &create_folder, "create-folder", 0, 0 },
        { NOTMUCH_OPT_BOOLEAN, &keep, "keep", 0, 0 },
        { NOTMUCH_OPT_STRING, &folder, "folder", 0, 0 },
        { NOTMUCH_OPT_BOOLEAN, &create_folder, "create-folder", 0, 0 },
        { NOTMUCH_OPT_BOOLEAN, &keep, "keep", 0, 0 },
+       { NOTMUCH_OPT_BOOLEAN,  &no_hooks, "no-hooks", 'n', 0 },
        { NOTMUCH_OPT_END, 0, 0, 0, 0 }
     };
 
        { NOTMUCH_OPT_END, 0, 0, 0, 0 }
     };
 
@@ -565,5 +567,10 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])
        }
     }
 
        }
     }
 
+    if (! no_hooks && status == NOTMUCH_STATUS_SUCCESS) {
+       /* Ignore hook failures. */
+       notmuch_run_hook (db_path, "post-insert");
+    }
+
     return status ? EXIT_FAILURE : EXIT_SUCCESS;
 }
     return status ? EXIT_FAILURE : EXIT_SUCCESS;
 }