1 Return-Path: <dominik@with-h.at>
\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 1FA52431FC3
\r
6 for <notmuch@notmuchmail.org>; Mon, 16 Jul 2012 23:04:47 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]
\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 3kmB97ShtoIg for <notmuch@notmuchmail.org>;
\r
16 Mon, 16 Jul 2012 23:04:45 -0700 (PDT)
\r
17 X-Greylist: delayed 1617 seconds by postgrey-1.32 at olra;
\r
18 Mon, 16 Jul 2012 23:04:45 PDT
\r
19 Received: from www73.your-server.de (www73.your-server.de [213.133.104.73])
\r
20 (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
\r
21 (No client certificate requested)
\r
22 by olra.theworths.org (Postfix) with ESMTPS id 2371A431FBC
\r
23 for <notmuch@notmuchmail.org>; Mon, 16 Jul 2012 23:04:45 -0700 (PDT)
\r
24 Received: from [78.46.5.204] (helo=sslproxy02.your-server.de)
\r
25 by www73.your-server.de with esmtpsa (TLSv1:AES256-SHA:256)
\r
26 (Exim 4.74) (envelope-from <dominik@with-h.at>)
\r
27 id 1Sr0Tf-00010u-Ig; Tue, 17 Jul 2012 07:37:43 +0200
\r
28 Received: from [188.194.53.208] (helo=localhost.localdomain)
\r
29 by sslproxy02.your-server.de with esmtpsa
\r
30 (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.72)
\r
31 (envelope-from <dominik@with-h.at>)
\r
32 id 1Sr0Te-0001dT-16; Tue, 17 Jul 2012 07:37:42 +0200
\r
33 From: Dominik Peteler <dominik@with-h.at>
\r
34 To: notmuch@notmuchmail.org
\r
35 Subject: [PATCH] cli: Hooks for tag-command
\r
36 Date: Tue, 17 Jul 2012 07:36:13 +0200
\r
37 Message-Id: <1342503373-16979-1-git-send-email-dominik@with-h.at>
\r
38 X-Mailer: git-send-email 1.7.11.2
\r
39 X-Authenticated-Sender: dude@with-h.at
\r
40 X-Virus-Scanned: Clear (ClamAV 0.97.3/15142/Tue Jul 17 04:44:44 2012)
\r
41 X-Mailman-Approved-At: Tue, 17 Jul 2012 14:24:57 -0700
\r
42 Cc: Dominik Peteler <dominik@with-h.at>
\r
43 X-BeenThere: notmuch@notmuchmail.org
\r
44 X-Mailman-Version: 2.1.13
\r
46 List-Id: "Use and development of the notmuch mail system."
\r
47 <notmuch.notmuchmail.org>
\r
48 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
49 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
50 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
51 List-Post: <mailto:notmuch@notmuchmail.org>
\r
52 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
53 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
54 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
55 X-List-Received-Date: Tue, 17 Jul 2012 06:04:47 -0000
\r
59 I attached some modifications which I made to notmuch. Comes with man pages and test.
\r
67 There are two hooks:
\r
68 * pre-tag: Run before tagging
\r
69 * post-tag: Run after
\r
71 This allows users to react on changes of tags. For example,
\r
72 you might want to move a message to a special Maildir
\r
73 depending on its notmuch tags.
\r
75 man/man1/notmuch-tag.1 | 17 +++++++++++++++++
\r
76 man/man5/notmuch-hooks.5 | 23 +++++++++++++++++++++++
\r
77 notmuch-tag.c | 25 +++++++++++++++++++++----
\r
78 test/hooks | 36 ++++++++++++++++++++++++++++++++++++
\r
79 4 files changed, 97 insertions(+), 4 deletions(-)
\r
81 diff --git a/man/man1/notmuch-tag.1 b/man/man1/notmuch-tag.1
\r
82 index d810e1b..8d8b7b2 100644
\r
83 --- a/man/man1/notmuch-tag.1
\r
84 +++ b/man/man1/notmuch-tag.1
\r
85 @@ -4,6 +4,7 @@ notmuch-tag \- add/remove tags for all messages matching the search terms
\r
89 +.RB "[" --no-hooks "]"
\r
90 .RI "+<" tag> "|\-<" tag "> [...] [\-\-] <" search-term ">..."
\r
93 @@ -29,6 +30,22 @@ updates the maildir flags according to tag changes if the
\r
94 configuration option is enabled. See \fBnotmuch-config\fR(1) for
\r
99 +command supports hooks. See \fBnotmuch-hooks(5)\fR
\r
100 +for more details on hooks.
\r
102 +Supported options for
\r
109 +Prevents hooks from being run.
\r
115 \fBnotmuch\fR(1), \fBnotmuch-config\fR(1), \fBnotmuch-count\fR(1),
\r
116 diff --git a/man/man5/notmuch-hooks.5 b/man/man5/notmuch-hooks.5
\r
117 index b914a29..7399627 100644
\r
118 --- a/man/man5/notmuch-hooks.5
\r
119 +++ b/man/man5/notmuch-hooks.5
\r
120 @@ -38,6 +38,29 @@ the scan or import.
\r
121 Typically this hook is used to perform additional query\-based tagging on the
\r
127 +This hook is invoked by the
\r
129 +command before tagging messages. If this
\r
130 +hook exits with a non-zero status, notmuch will abort further processing of the
\r
134 +Typically this hook is used for syncing the Maildir with notmuch tags.
\r
139 +This hook is invoked by the
\r
141 +command after messages have been tagged. The hook will not be run if there have been any errors during
\r
144 +Typically this hook is used for syncing the Maildir with notmuch tags.
\r
150 diff --git a/notmuch-tag.c b/notmuch-tag.c
\r
151 index 7d18639..e98d3a0 100644
\r
152 --- a/notmuch-tag.c
\r
153 +++ b/notmuch-tag.c
\r
154 @@ -174,9 +174,11 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])
\r
155 int tag_ops_count = 0;
\r
156 char *query_string;
\r
157 notmuch_config_t *config;
\r
158 + const char *db_path;
\r
159 notmuch_database_t *notmuch;
\r
160 struct sigaction action;
\r
161 notmuch_bool_t synchronize_flags;
\r
162 + notmuch_bool_t run_hooks = TRUE;
\r
166 @@ -198,11 +200,12 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])
\r
169 for (i = 0; i < argc; i++) {
\r
170 - if (strcmp (argv[i], "--") == 0) {
\r
171 + if (strcmp (argv[i], "--no-hooks") == 0) {
\r
172 + run_hooks = FALSE;
\r
173 + } else if (strcmp (argv[i], "--") == 0) {
\r
177 - if (argv[i][0] == '+' || argv[i][0] == '-') {
\r
178 + } else if (argv[i][0] == '+' || argv[i][0] == '-') {
\r
179 tag_ops[tag_ops_count].tag = argv[i] + 1;
\r
180 tag_ops[tag_ops_count].remove = (argv[i][0] == '-');
\r
182 @@ -229,7 +232,15 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])
\r
183 if (config == NULL)
\r
186 - if (notmuch_database_open (notmuch_config_get_database_path (config),
\r
187 + db_path = notmuch_config_get_database_path (config);
\r
190 + ret = notmuch_run_hook (db_path, "pre-tag");
\r
195 + if (notmuch_database_open (db_path,
\r
196 NOTMUCH_DATABASE_MODE_READ_WRITE, ¬much))
\r
199 @@ -239,5 +250,11 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])
\r
201 notmuch_database_destroy (notmuch);
\r
204 + ret = notmuch_run_hook (db_path, "post-tag");
\r
211 diff --git a/test/hooks b/test/hooks
\r
212 index 77e8569..ae857cc 100755
\r
215 @@ -31,6 +31,7 @@ rm_hooks () {
\r
216 # add a message to generate mail dir and database
\r
219 +# {pre,post}-new hooks
\r
220 test_begin_subtest "pre-new is run"
\r
223 @@ -101,4 +102,39 @@ EOF
\r
224 chmod +x "${HOOK_DIR}/pre-new"
\r
225 test_expect_code 1 "hook execution failure" "notmuch new"
\r
229 +# {pre,post}-tag hooks
\r
230 +test_begin_subtest "pre-tag is run"
\r
233 +create_echo_hook "pre-tag" expected output
\r
234 +notmuch tag +foo -- '*' > /dev/null
\r
235 +test_expect_equal_file expected output
\r
237 +test_begin_subtest "post-tag is run"
\r
240 +create_echo_hook "post-tag" expected output
\r
241 +notmuch tag +foo -- '*' > /dev/null
\r
242 +test_expect_equal_file expected output
\r
244 +test_begin_subtest "pre-tag is run before post-new"
\r
247 +create_echo_hook "pre-tag" pre-tag.expected pre-tag.output
\r
248 +create_echo_hook "post-tag" post-tag.expected post-tag.output
\r
249 +notmuch tag +foo -- '*' > /dev/null
\r
250 +test_expect_equal_file post-tag.expected post-tag.output
\r
252 +test_begin_subtest "pre-tag non-zero exit status (hook status)"
\r
255 +create_failing_hook "pre-tag"
\r
256 +output=`notmuch tag +foo -- '*' 2>&1`
\r
257 +test_expect_equal "$output" "Error: pre-tag hook failed with status 13"
\r
259 +# depends on the previous subtest leaving broken hook behind
\r
260 +test_expect_code 1 "pre-tag non-zero exit status (notmuch status)" "notmuch tag +foo -- '*'"
\r