1 Return-Path: <jani@nikula.org>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id 68721429E38
\r
6 for <notmuch@notmuchmail.org>; Fri, 2 Dec 2011 13:00:19 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5
\r
12 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id 9ENq-8aRYdgR for <notmuch@notmuchmail.org>;
\r
16 Fri, 2 Dec 2011 13:00:18 -0800 (PST)
\r
17 Received: from mail-ww0-f45.google.com (mail-ww0-f45.google.com
\r
18 [74.125.82.45]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client
\r
19 certificate requested) by olra.theworths.org (Postfix) with ESMTPS id
\r
20 33515429E21 for <notmuch@notmuchmail.org>; Fri, 2 Dec 2011 13:00:18 -0800
\r
22 Received: by wgbds13 with SMTP id ds13so1494749wgb.2
\r
23 for <notmuch@notmuchmail.org>; Fri, 02 Dec 2011 13:00:15 -0800 (PST)
\r
24 Received: by 10.227.204.197 with SMTP id fn5mr7330144wbb.15.1322859612529;
\r
25 Fri, 02 Dec 2011 13:00:12 -0800 (PST)
\r
26 Received: from localhost (dsl-hkibrasgw4-fe5cdc00-23.dhcp.inet.fi.
\r
28 by mx.google.com with ESMTPS id 28sm9183237wby.3.2011.12.02.13.00.07
\r
29 (version=SSLv3 cipher=OTHER); Fri, 02 Dec 2011 13:00:08 -0800 (PST)
\r
30 From: Jani Nikula <jani@nikula.org>
\r
31 To: notmuch@notmuchmail.org
\r
32 Subject: [PATCH 1/2] cli: add mechanism for running user configurable hooks
\r
33 Date: Fri, 2 Dec 2011 23:00:05 +0200
\r
35 <7fbe6befcf31881a9bca672f55b93501249a220c.1322859389.git.jani@nikula.org>
\r
36 X-Mailer: git-send-email 1.7.5.4
\r
37 X-BeenThere: notmuch@notmuchmail.org
\r
38 X-Mailman-Version: 2.1.13
\r
40 List-Id: "Use and development of the notmuch mail system."
\r
41 <notmuch.notmuchmail.org>
\r
42 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
43 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
44 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
45 List-Post: <mailto:notmuch@notmuchmail.org>
\r
46 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
47 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
48 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
49 X-List-Received-Date: Fri, 02 Dec 2011 21:00:19 -0000
\r
51 Add support functions for running hooks configurable in the notmuch config
\r
52 file. The hooks will be run using system(1).
\r
56 * Move notmuch_run_hook() out of notmuch-new.c. It's there and static only
\r
57 because the first user will be there.
\r
59 * Consider merging this with the following patch, as this is slightly
\r
60 artificial as it is.
\r
62 Signed-off-by: Jani Nikula <jani@nikula.org>
\r
64 notmuch-client.h | 7 +++++++
\r
65 notmuch-config.c | 21 +++++++++++++++++++++
\r
66 notmuch-new.c | 25 +++++++++++++++++++++++++
\r
67 3 files changed, 53 insertions(+), 0 deletions(-)
\r
69 diff --git a/notmuch-client.h b/notmuch-client.h
\r
70 index b50cb38..5e2fed2 100644
\r
71 --- a/notmuch-client.h
\r
72 +++ b/notmuch-client.h
\r
73 @@ -87,6 +87,10 @@ typedef struct notmuch_show_params {
\r
75 } notmuch_show_params_t;
\r
78 + NOTMUCH_HOOK_PLACEHOLDER,
\r
81 /* There's no point in continuing when we've detected that we've done
\r
82 * something wrong internally (as opposed to the user passing in a
\r
84 @@ -235,6 +239,9 @@ void
\r
85 notmuch_config_set_maildir_synchronize_flags (notmuch_config_t *config,
\r
86 notmuch_bool_t synchronize_flags);
\r
89 +notmuch_config_get_hook (notmuch_config_t *config, notmuch_hook_t hook);
\r
92 debugger_is_active (void);
\r
94 diff --git a/notmuch-config.c b/notmuch-config.c
\r
95 index 1a7ed58..8f1a038 100644
\r
96 --- a/notmuch-config.c
\r
97 +++ b/notmuch-config.c
\r
98 @@ -608,6 +608,27 @@ notmuch_config_set_new_tags (notmuch_config_t *config,
\r
99 config->new_tags = NULL;
\r
103 +notmuch_config_get_hook (notmuch_config_t *config, notmuch_hook_t hook)
\r
106 + const char *group, *key;
\r
110 + INTERNAL_ERROR ("Unknown hook %d\n.", hook);
\r
113 + command = g_key_file_get_string (config->key_file, group, key, NULL);
\r
115 + char *p = command;
\r
116 + command = talloc_strdup (config, command);
\r
123 /* Given a configuration item of the form <group>.<key> return the
\r
124 * component group and key. If any error occurs, print a message on
\r
125 * stderr and return 1. Otherwise, return 0.
\r
126 diff --git a/notmuch-new.c b/notmuch-new.c
\r
127 index 81a9350..0c70e64 100644
\r
128 --- a/notmuch-new.c
\r
129 +++ b/notmuch-new.c
\r
130 @@ -795,6 +795,31 @@ _remove_directory (void *ctx,
\r
131 notmuch_directory_destroy (directory);
\r
135 +notmuch_run_hook (notmuch_config_t *config, notmuch_hook_t hook)
\r
137 + const char *command;
\r
140 + command = notmuch_config_get_hook (config, hook);
\r
142 + return NOTMUCH_STATUS_SUCCESS; /* It's okay not to have a hook */
\r
144 + r = system(command);
\r
146 + if (WIFSIGNALED(r))
\r
147 + fprintf(stderr, "hook '%s' terminated with signal %d\n",
\r
148 + command, WTERMSIG(r));
\r
150 + fprintf(stderr, "hook '%s' failed with status %d\n",
\r
151 + command, WEXITSTATUS(r));
\r
153 + r = NOTMUCH_STATUS_FILE_ERROR; /* FIXME */
\r
160 notmuch_new_command (void *ctx, int argc, char *argv[])
\r