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 63293429E26
\r
6 for <notmuch@notmuchmail.org>; Sat, 3 Dec 2011 15:16:57 -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 Abxu6SG2Cjho for <notmuch@notmuchmail.org>;
\r
16 Sat, 3 Dec 2011 15:16:55 -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 62529429E25 for <notmuch@notmuchmail.org>; Sat, 3 Dec 2011 15:16:55 -0800
\r
22 Received: by wgbds13 with SMTP id ds13so3394124wgb.2
\r
23 for <notmuch@notmuchmail.org>; Sat, 03 Dec 2011 15:16:54 -0800 (PST)
\r
24 Received: by 10.227.203.70 with SMTP id fh6mr3431301wbb.12.1322954214076;
\r
25 Sat, 03 Dec 2011 15:16:54 -0800 (PST)
\r
26 Received: from localhost (dsl-hkibrasgw4-fe5cdc00-23.dhcp.inet.fi.
\r
27 [80.220.92.23]) by mx.google.com with ESMTPS id
\r
28 ep16sm18738849wbb.21.2011.12.03.15.16.51
\r
29 (version=SSLv3 cipher=OTHER); Sat, 03 Dec 2011 15:16:52 -0800 (PST)
\r
30 From: Jani Nikula <jani@nikula.org>
\r
31 To: notmuch@notmuchmail.org
\r
32 Subject: [PATCH v2 1/2] cli: introduce the concept of user defined hooks
\r
33 Date: Sun, 4 Dec 2011 01:16:48 +0200
\r
35 <6688b09fffa2a66b496af78008102f88ab4e9450.1322953841.git.jani@nikula.org>
\r
36 X-Mailer: git-send-email 1.7.5.4
\r
38 <7fbe6befcf31881a9bca672f55b93501249a220c.1322859389.git.jani@nikula.org>
\r
40 <7fbe6befcf31881a9bca672f55b93501249a220c.1322859389.git.jani@nikula.org>
\r
42 Content-Type: text/plain; charset=UTF-8
\r
43 Content-Transfer-Encoding: 8bit
\r
44 X-BeenThere: notmuch@notmuchmail.org
\r
45 X-Mailman-Version: 2.1.13
\r
47 List-Id: "Use and development of the notmuch mail system."
\r
48 <notmuch.notmuchmail.org>
\r
49 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
50 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
51 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
52 List-Post: <mailto:notmuch@notmuchmail.org>
\r
53 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
54 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
55 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
56 X-List-Received-Date: Sat, 03 Dec 2011 23:16:57 -0000
\r
58 Add mechanism for running user defined hooks. Hooks are executables or
\r
59 symlinks to executables stored under the new notmuch hooks directory,
\r
60 <database-path>/.notmuch/hooks.
\r
62 No hooks are introduced here, but adding support for a hook is now a simple
\r
63 matter of calling the new notmuch_run_hook() function at an appropriate
\r
64 location with the hook name.
\r
66 Signed-off-by: Jani Nikula <jani@nikula.org>
\r
70 v2: Switch to git style hooks in a hook directory as suggested by Austin
\r
71 Clements in IRC. Update manpage and add polish.
\r
73 Makefile.local | 1 +
\r
74 notmuch-client.h | 3 ++
\r
75 notmuch-hook.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
\r
76 3 files changed, 67 insertions(+), 0 deletions(-)
\r
77 create mode 100644 notmuch-hook.c
\r
79 diff --git a/Makefile.local b/Makefile.local
\r
80 index c94402b..a1665e1 100644
\r
81 --- a/Makefile.local
\r
82 +++ b/Makefile.local
\r
83 @@ -302,6 +302,7 @@ notmuch_client_srcs = \
\r
91 diff --git a/notmuch-client.h b/notmuch-client.h
\r
92 index b50cb38..a91ad6c 100644
\r
93 --- a/notmuch-client.h
\r
94 +++ b/notmuch-client.h
\r
95 @@ -235,6 +235,9 @@ void
\r
96 notmuch_config_set_maildir_synchronize_flags (notmuch_config_t *config,
\r
97 notmuch_bool_t synchronize_flags);
\r
100 +notmuch_run_hook (const char *db_path, const char *hook);
\r
103 debugger_is_active (void);
\r
105 diff --git a/notmuch-hook.c b/notmuch-hook.c
\r
106 new file mode 100644
\r
107 index 0000000..fc32044
\r
109 +++ b/notmuch-hook.c
\r
111 +/* notmuch - Not much of an email program, (just index and search)
\r
113 + * This file is part of notmuch.
\r
115 + * Copyright © 2011 Jani Nikula
\r
117 + * This program is free software: you can redistribute it and/or modify
\r
118 + * it under the terms of the GNU General Public License as published by
\r
119 + * the Free Software Foundation, either version 3 of the License, or
\r
120 + * (at your option) any later version.
\r
122 + * This program is distributed in the hope that it will be useful,
\r
123 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
124 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
125 + * GNU General Public License for more details.
\r
127 + * You should have received a copy of the GNU General Public License
\r
128 + * along with this program. If not, see http://www.gnu.org/licenses/ .
\r
130 + * Author: Jani Nikula <jani@nikula.org>
\r
133 +#include "notmuch-client.h"
\r
136 +notmuch_run_hook (const char *db_path, const char *hook)
\r
141 + if (asprintf (&hook_path, "%s/%s/%s/%s", db_path, ".notmuch", "hooks",
\r
143 + return NOTMUCH_STATUS_OUT_OF_MEMORY;
\r
145 + if (access (hook_path, X_OK) == -1) {
\r
146 + /* Ignore ENOENT. It's okay not to have a hook, hook dir, or even
\r
147 + * notmuch dir. Dangling symbolic links also result in ENOENT, but
\r
148 + * we'll ignore that too for simplicity. */
\r
149 + if (errno != ENOENT) {
\r
150 + fprintf (stderr, "Error: %s hook access failed: %s\n", hook,
\r
151 + strerror (errno));
\r
152 + status = NOTMUCH_STATUS_FILE_ERROR;
\r
157 + status = system (hook_path);
\r
159 + if (WIFSIGNALED(status))
\r
160 + fprintf(stderr, "Error: %s hook terminated with signal %d\n", hook,
\r
161 + WTERMSIG(status));
\r
163 + fprintf(stderr, "Error: %s hook failed with status %d\n", hook,
\r
164 + WEXITSTATUS(status));
\r
166 + status = NOTMUCH_STATUS_FILE_ERROR; /* Close enough */
\r
170 + free (hook_path);
\r