From: Jani Nikula Date: Sun, 28 Sep 2014 14:40:59 +0000 (+0300) Subject: [PATCH v2 3/3] cli/insert: add post-insert hook X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=2b7b3ecfeca59b62d6b68b5861a5b49f0c70e769;p=notmuch-archives.git [PATCH v2 3/3] cli/insert: add post-insert hook --- diff --git a/7a/f1a4fb032f3e5440ed8d0576e943c51d1f47b3 b/7a/f1a4fb032f3e5440ed8d0576e943c51d1f47b3 new file mode 100644 index 000000000..f9a799300 --- /dev/null +++ b/7a/f1a4fb032f3e5440ed8d0576e943c51d1f47b3 @@ -0,0 +1,170 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 45168431FC2 + for ; Sun, 28 Sep 2014 07:41:28 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" +X-Spam-Flag: NO +X-Spam-Score: -0.7 +X-Spam-Level: +X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id S4KCSe1y-5Et for ; + Sun, 28 Sep 2014 07:41:24 -0700 (PDT) +Received: from mail-we0-f169.google.com (mail-we0-f169.google.com + [74.125.82.169]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id AA5CE431FCF + for ; Sun, 28 Sep 2014 07:41:17 -0700 (PDT) +Received: by mail-we0-f169.google.com with SMTP id k48so11672073wev.14 + for ; Sun, 28 Sep 2014 07:41:16 -0700 (PDT) +X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; + d=1e100.net; s=20130820; + h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to + :references:in-reply-to:references; + bh=uXHyNvzC1EKNVDpwXmY8mTyWGcVtfmKQExXaUgnePFs=; + b=jdQjN4n8w1TSzvloB+Fazzvcuk0tQk4NzZ7PknGGyhKo6V91RS3IBUxjXySxt0xytM + mgiKT9sKRNkREtBzeRoM5yerL83vXl2tFLc2h4bJYJZSAJ6NBXZ9g28IQSXZFeIjllkj + EziE6nq843rmmRbzHE39WCYXJDSVC7CTkqniR5848DHBEVFU5w8fbDA5HSRAekz+xb4+ + hYG513HxkRXP+T9pnZ6cn3P0jDHQOR7p9WBHQG+oSsI2Ul+wkwyYseorNm2kcYhfJpsj + dcUjAxFxRr8jLp9V0Jq5M1L0dgIqeqEdthqyHa/nxIzsvmMpPJ8XR93Kz4nTumX00nOq + uxmA== +X-Gm-Message-State: + ALoCoQmZfnnG8FPiChrzepwBNRmfq9Soo4AG8D/XUkYXv9d5I91gkiXrab8wGk8uiUvwepoTSuYi +X-Received: by 10.180.231.9 with SMTP id tc9mr38535943wic.58.1411915276495; + Sun, 28 Sep 2014 07:41:16 -0700 (PDT) +Received: from localhost (dsl-hkibrasgw2-58c36c-245.dhcp.inet.fi. + [88.195.108.245]) + by mx.google.com with ESMTPSA id mx5sm8702900wic.0.2014.09.28.07.41.15 + for + (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); + Sun, 28 Sep 2014 07:41:15 -0700 (PDT) +From: Jani Nikula +To: notmuch@notmuchmail.org +Subject: [PATCH v2 3/3] cli/insert: add post-insert hook +Date: Sun, 28 Sep 2014 17:40:59 +0300 +Message-Id: + <27c7ada91f96deda6e51732e0397bffd2ef2ab42.1411914914.git.jani@nikula.org> +X-Mailer: git-send-email 2.1.0 +In-Reply-To: +References: +In-Reply-To: +References: +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Sun, 28 Sep 2014 14:41:28 -0000 + +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 | 9 +++++++++ + doc/man5/notmuch-hooks.rst | 11 +++++++++++ + notmuch-insert.c | 7 +++++++ + 3 files changed, 27 insertions(+) + +diff --git a/doc/man1/notmuch-insert.rst b/doc/man1/notmuch-insert.rst +index e396f6cf2279..2c9c0d02c251 100644 +--- a/doc/man1/notmuch-insert.rst ++++ b/doc/man1/notmuch-insert.rst +@@ -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. + ++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 + +@@ -44,6 +47,9 @@ Supported options for **insert** include + fails. Ignore these errors and return exit status 0 to + indicate succesful mail delivery. + ++ ``--no-hooks`` ++ Prevent hooks from being run. ++ + 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. + ++The exit status of the **post-insert** hook does not affect the exit ++status of the **insert** command. ++ + SEE ALSO + ======== + +diff --git a/doc/man5/notmuch-hooks.rst b/doc/man5/notmuch-hooks.rst +index 493abf20f003..f1c2528c5666 100644 +--- a/doc/man5/notmuch-hooks.rst ++++ b/doc/man5/notmuch-hooks.rst +@@ -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. + ++ **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 + ======== + +diff --git a/notmuch-insert.c b/notmuch-insert.c +index 7074077ca699..e9d71efa1fb6 100644 +--- a/notmuch-insert.c ++++ b/notmuch-insert.c +@@ -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; ++ notmuch_bool_t no_hooks = FALSE; + 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_BOOLEAN, &no_hooks, "no-hooks", 'n', 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; + } +-- +2.1.0 +