--- /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 68721429E38\r
+ for <notmuch@notmuchmail.org>; Fri, 2 Dec 2011 13:00:19 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\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 9ENq-8aRYdgR for <notmuch@notmuchmail.org>;\r
+ Fri, 2 Dec 2011 13:00:18 -0800 (PST)\r
+Received: from mail-ww0-f45.google.com (mail-ww0-f45.google.com\r
+ [74.125.82.45]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client\r
+ certificate requested) by olra.theworths.org (Postfix) with ESMTPS id\r
+ 33515429E21 for <notmuch@notmuchmail.org>; Fri, 2 Dec 2011 13:00:18 -0800\r
+ (PST)\r
+Received: by wgbds13 with SMTP id ds13so1494749wgb.2\r
+ for <notmuch@notmuchmail.org>; Fri, 02 Dec 2011 13:00:15 -0800 (PST)\r
+Received: by 10.227.204.197 with SMTP id fn5mr7330144wbb.15.1322859612529;\r
+ Fri, 02 Dec 2011 13:00:12 -0800 (PST)\r
+Received: from localhost (dsl-hkibrasgw4-fe5cdc00-23.dhcp.inet.fi.\r
+ [80.220.92.23])\r
+ by mx.google.com with ESMTPS id 28sm9183237wby.3.2011.12.02.13.00.07\r
+ (version=SSLv3 cipher=OTHER); Fri, 02 Dec 2011 13:00:08 -0800 (PST)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 1/2] cli: add mechanism for running user configurable hooks\r
+Date: Fri, 2 Dec 2011 23:00:05 +0200\r
+Message-Id:\r
+ <7fbe6befcf31881a9bca672f55b93501249a220c.1322859389.git.jani@nikula.org>\r
+X-Mailer: git-send-email 1.7.5.4\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: Fri, 02 Dec 2011 21:00:19 -0000\r
+\r
+Add support functions for running hooks configurable in the notmuch config\r
+file. The hooks will be run using system(1).\r
+\r
+TODO:\r
+\r
+* Move notmuch_run_hook() out of notmuch-new.c. It's there and static only\r
+ because the first user will be there.\r
+\r
+* Consider merging this with the following patch, as this is slightly\r
+ artificial as it is.\r
+\r
+Signed-off-by: Jani Nikula <jani@nikula.org>\r
+---\r
+ notmuch-client.h | 7 +++++++\r
+ notmuch-config.c | 21 +++++++++++++++++++++\r
+ notmuch-new.c | 25 +++++++++++++++++++++++++\r
+ 3 files changed, 53 insertions(+), 0 deletions(-)\r
+\r
+diff --git a/notmuch-client.h b/notmuch-client.h\r
+index b50cb38..5e2fed2 100644\r
+--- a/notmuch-client.h\r
++++ b/notmuch-client.h\r
+@@ -87,6 +87,10 @@ typedef struct notmuch_show_params {\r
+ int decrypt;\r
+ } notmuch_show_params_t;\r
+ \r
++typedef enum {\r
++ NOTMUCH_HOOK_PLACEHOLDER,\r
++} notmuch_hook_t;\r
++\r
+ /* There's no point in continuing when we've detected that we've done\r
+ * something wrong internally (as opposed to the user passing in a\r
+ * bogus value).\r
+@@ -235,6 +239,9 @@ void\r
+ notmuch_config_set_maildir_synchronize_flags (notmuch_config_t *config,\r
+ notmuch_bool_t synchronize_flags);\r
+ \r
++const char *\r
++notmuch_config_get_hook (notmuch_config_t *config, notmuch_hook_t hook);\r
++\r
+ notmuch_bool_t\r
+ debugger_is_active (void);\r
+ \r
+diff --git a/notmuch-config.c b/notmuch-config.c\r
+index 1a7ed58..8f1a038 100644\r
+--- a/notmuch-config.c\r
++++ b/notmuch-config.c\r
+@@ -608,6 +608,27 @@ notmuch_config_set_new_tags (notmuch_config_t *config,\r
+ config->new_tags = NULL;\r
+ }\r
+ \r
++const char *\r
++notmuch_config_get_hook (notmuch_config_t *config, notmuch_hook_t hook)\r
++{\r
++ char *command;\r
++ const char *group, *key;\r
++\r
++ switch (hook) {\r
++ default:\r
++ INTERNAL_ERROR ("Unknown hook %d\n.", hook);\r
++ }\r
++\r
++ command = g_key_file_get_string (config->key_file, group, key, NULL);\r
++ if (command) {\r
++ char *p = command;\r
++ command = talloc_strdup (config, command);\r
++ free (p);\r
++ }\r
++\r
++ return command;\r
++}\r
++\r
+ /* Given a configuration item of the form <group>.<key> return the\r
+ * component group and key. If any error occurs, print a message on\r
+ * stderr and return 1. Otherwise, return 0.\r
+diff --git a/notmuch-new.c b/notmuch-new.c\r
+index 81a9350..0c70e64 100644\r
+--- a/notmuch-new.c\r
++++ b/notmuch-new.c\r
+@@ -795,6 +795,31 @@ _remove_directory (void *ctx,\r
+ notmuch_directory_destroy (directory);\r
+ }\r
+ \r
++static int\r
++notmuch_run_hook (notmuch_config_t *config, notmuch_hook_t hook)\r
++{\r
++ const char *command;\r
++ int r;\r
++\r
++ command = notmuch_config_get_hook (config, hook);\r
++ if (!command)\r
++ return NOTMUCH_STATUS_SUCCESS; /* It's okay not to have a hook */\r
++\r
++ r = system(command);\r
++ if (r) {\r
++ if (WIFSIGNALED(r))\r
++ fprintf(stderr, "hook '%s' terminated with signal %d\n",\r
++ command, WTERMSIG(r));\r
++ else\r
++ fprintf(stderr, "hook '%s' failed with status %d\n",\r
++ command, WEXITSTATUS(r));\r
++\r
++ r = NOTMUCH_STATUS_FILE_ERROR; /* FIXME */\r
++ }\r
++\r
++ return r;\r
++}\r
++\r
+ int\r
+ notmuch_new_command (void *ctx, int argc, char *argv[])\r
+ {\r
+-- \r
+1.7.5.4\r
+\r