--- /dev/null
+Return-Path: <jani@nikula.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 45168431FC2\r
+ for <notmuch@notmuchmail.org>; Sun, 28 Sep 2014 07:41:28 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+ tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id S4KCSe1y-5Et for <notmuch@notmuchmail.org>;\r
+ Sun, 28 Sep 2014 07:41:24 -0700 (PDT)\r
+Received: from mail-we0-f169.google.com (mail-we0-f169.google.com\r
+ [74.125.82.169]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id AA5CE431FCF\r
+ for <notmuch@notmuchmail.org>; Sun, 28 Sep 2014 07:41:17 -0700 (PDT)\r
+Received: by mail-we0-f169.google.com with SMTP id k48so11672073wev.14\r
+ for <notmuch@notmuchmail.org>; Sun, 28 Sep 2014 07:41:16 -0700 (PDT)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+ d=1e100.net; s=20130820;\r
+ h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\r
+ :references:in-reply-to:references;\r
+ bh=uXHyNvzC1EKNVDpwXmY8mTyWGcVtfmKQExXaUgnePFs=;\r
+ b=jdQjN4n8w1TSzvloB+Fazzvcuk0tQk4NzZ7PknGGyhKo6V91RS3IBUxjXySxt0xytM\r
+ mgiKT9sKRNkREtBzeRoM5yerL83vXl2tFLc2h4bJYJZSAJ6NBXZ9g28IQSXZFeIjllkj\r
+ EziE6nq843rmmRbzHE39WCYXJDSVC7CTkqniR5848DHBEVFU5w8fbDA5HSRAekz+xb4+\r
+ hYG513HxkRXP+T9pnZ6cn3P0jDHQOR7p9WBHQG+oSsI2Ul+wkwyYseorNm2kcYhfJpsj\r
+ dcUjAxFxRr8jLp9V0Jq5M1L0dgIqeqEdthqyHa/nxIzsvmMpPJ8XR93Kz4nTumX00nOq\r
+ uxmA==\r
+X-Gm-Message-State:\r
+ ALoCoQmZfnnG8FPiChrzepwBNRmfq9Soo4AG8D/XUkYXv9d5I91gkiXrab8wGk8uiUvwepoTSuYi\r
+X-Received: by 10.180.231.9 with SMTP id tc9mr38535943wic.58.1411915276495;\r
+ Sun, 28 Sep 2014 07:41:16 -0700 (PDT)\r
+Received: from localhost (dsl-hkibrasgw2-58c36c-245.dhcp.inet.fi.\r
+ [88.195.108.245])\r
+ by mx.google.com with ESMTPSA id mx5sm8702900wic.0.2014.09.28.07.41.15\r
+ for <multiple recipients>\r
+ (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
+ Sun, 28 Sep 2014 07:41:15 -0700 (PDT)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v2 3/3] cli/insert: add post-insert hook\r
+Date: Sun, 28 Sep 2014 17:40:59 +0300\r
+Message-Id:\r
+ <27c7ada91f96deda6e51732e0397bffd2ef2ab42.1411914914.git.jani@nikula.org>\r
+X-Mailer: git-send-email 2.1.0\r
+In-Reply-To: <cover.1411914914.git.jani@nikula.org>\r
+References: <cover.1411914914.git.jani@nikula.org>\r
+In-Reply-To: <cover.1411914914.git.jani@nikula.org>\r
+References: <cover.1411914914.git.jani@nikula.org>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sun, 28 Sep 2014 14:41:28 -0000\r
+\r
+The post-new hook might no longer be needed or run very often if\r
+notmuch insert is being used. Therefore a post-insert hook is needed\r
+(arguably pre-insert not so much, so don't add one). Also add the\r
+--no-hooks option to skip hooks.\r
+---\r
+ doc/man1/notmuch-insert.rst | 9 +++++++++\r
+ doc/man5/notmuch-hooks.rst | 11 +++++++++++\r
+ notmuch-insert.c | 7 +++++++\r
+ 3 files changed, 27 insertions(+)\r
+\r
+diff --git a/doc/man1/notmuch-insert.rst b/doc/man1/notmuch-insert.rst\r
+index e396f6cf2279..2c9c0d02c251 100644\r
+--- a/doc/man1/notmuch-insert.rst\r
++++ b/doc/man1/notmuch-insert.rst\r
+@@ -25,6 +25,9 @@ If the new message is a duplicate of an existing message in the database\r
+ (it has same Message-ID), it will be added to the maildir folder and\r
+ notmuch database, but the tags will not be changed.\r
+ \r
++The **insert** command supports hooks. See **notmuch-hooks(5)** for\r
++more details on hooks.\r
++\r
+ Option arguments must appear before any tag operation arguments.\r
+ Supported options for **insert** include\r
+ \r
+@@ -44,6 +47,9 @@ Supported options for **insert** include\r
+ fails. Ignore these errors and return exit status 0 to\r
+ indicate succesful mail delivery.\r
+ \r
++ ``--no-hooks``\r
++ Prevent hooks from being run.\r
++\r
+ EXIT STATUS\r
+ ===========\r
+ \r
+@@ -54,6 +60,9 @@ indexing to Notmuch database, changing tags, and synchronizing tags to\r
+ maildir flags. The ``--keep`` option may be used to settle for\r
+ successful message file delivery.\r
+ \r
++The exit status of the **post-insert** hook does not affect the exit\r
++status of the **insert** command.\r
++\r
+ SEE ALSO\r
+ ========\r
+ \r
+diff --git a/doc/man5/notmuch-hooks.rst b/doc/man5/notmuch-hooks.rst\r
+index 493abf20f003..f1c2528c5666 100644\r
+--- a/doc/man5/notmuch-hooks.rst\r
++++ b/doc/man5/notmuch-hooks.rst\r
+@@ -35,6 +35,17 @@ The currently available hooks are described below.\r
+ Typically this hook is used to perform additional query-based\r
+ tagging on the imported messages.\r
+ \r
++ **post-insert**\r
++\r
++ This hook is invoked by the **insert** command after the\r
++ message has been delivered, added to the database, and initial\r
++ tags have been applied. The hook will not be run if there have\r
++ been any errors during the message delivery; what is regarded\r
++ as succesful delivery depends on the ``--keep`` option.\r
++\r
++ Typically this hook is used to perform additional query-based\r
++ tagging on the delivered messages.\r
++\r
+ SEE ALSO\r
+ ========\r
+ \r
+diff --git a/notmuch-insert.c b/notmuch-insert.c\r
+index 7074077ca699..e9d71efa1fb6 100644\r
+--- a/notmuch-insert.c\r
++++ b/notmuch-insert.c\r
+@@ -454,6 +454,7 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])\r
+ const char *folder = NULL;\r
+ notmuch_bool_t create_folder = FALSE;\r
+ notmuch_bool_t keep = FALSE;\r
++ notmuch_bool_t no_hooks = FALSE;\r
+ notmuch_bool_t synchronize_flags;\r
+ const char *maildir;\r
+ char *newpath;\r
+@@ -464,6 +465,7 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])\r
+ { NOTMUCH_OPT_STRING, &folder, "folder", 0, 0 },\r
+ { NOTMUCH_OPT_BOOLEAN, &create_folder, "create-folder", 0, 0 },\r
+ { NOTMUCH_OPT_BOOLEAN, &keep, "keep", 0, 0 },\r
++ { NOTMUCH_OPT_BOOLEAN, &no_hooks, "no-hooks", 'n', 0 },\r
+ { NOTMUCH_OPT_END, 0, 0, 0, 0 }\r
+ };\r
+ \r
+@@ -565,5 +567,10 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])\r
+ }\r
+ }\r
+ \r
++ if (! no_hooks && status == NOTMUCH_STATUS_SUCCESS) {\r
++ /* Ignore hook failures. */\r
++ notmuch_run_hook (db_path, "post-insert");\r
++ }\r
++\r
+ return status ? EXIT_FAILURE : EXIT_SUCCESS;\r
+ }\r
+-- \r
+2.1.0\r
+\r