Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 2c / 1bb2cd8fcad888c5a681e166b8a8ad65d6628e
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
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         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 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
45 Precedence: list\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
56 \r
57 hello,\r
58 \r
59 I attached some modifications which I made to notmuch. Comes with man pages and test.\r
60 \r
61 regards\r
62 \r
63 dominik\r
64 \r
65 \r
66 \r
67 There are two hooks:\r
68  * pre-tag: Run before tagging\r
69  * post-tag: Run after\r
70 \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
74 ---\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
80 \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
86  \r
87  .SH SYNOPSIS\r
88  .B notmuch tag\r
89 +.RB "[" --no-hooks "]"\r
90  .RI  "+<" tag> "|\-<" tag "> [...] [\-\-] <" search-term ">..."\r
91  \r
92  .SH DESCRIPTION\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
95  details.\r
96  \r
97 +The\r
98 +.B tag\r
99 +command supports hooks. See  \fBnotmuch-hooks(5)\fR\r
100 +for more details on hooks.\r
101 +\r
102 +Supported options for\r
103 +.B tag\r
104 +include\r
105 +.RS 4\r
106 +.TP 4\r
107 +.BR \-\-no\-hooks\r
108 +\r
109 +Prevents hooks from being run.\r
110 +.RE\r
111 +.RE\r
112 +\r
113  .SH SEE ALSO\r
114  \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
122  imported messages.\r
123  .RE\r
124 +.RS 4\r
125 +.TP 4\r
126 +.B pre\-tag\r
127 +This hook is invoked by the\r
128 +.B tag\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
131 +.B tag\r
132 +command.\r
133 +\r
134 +Typically this hook is used for syncing the Maildir with notmuch tags.\r
135 +.RE\r
136 +.RS 4\r
137 +.TP 4\r
138 +.B post\-tag\r
139 +This hook is invoked by the\r
140 +.B tag\r
141 +command after messages have been tagged. The hook will not be run if there have been any errors during\r
142 +the tagging.\r
143 +\r
144 +Typically this hook is used for syncing the Maildir with notmuch tags.\r
145 +.RE\r
146 +\r
147  \r
148  .SH SEE ALSO\r
149  \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
163      int i;\r
164      int ret;\r
165  \r
166 @@ -198,11 +200,12 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])\r
167      }\r
168  \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
174             i++;\r
175             break;\r
176 -       }\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
181             tag_ops_count++;\r
182 @@ -229,7 +232,15 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])\r
183      if (config == NULL)\r
184         return 1;\r
185  \r
186 -    if (notmuch_database_open (notmuch_config_get_database_path (config),\r
187 +    db_path = notmuch_config_get_database_path (config);\r
188 +\r
189 +    if (run_hooks) {\r
190 +       ret = notmuch_run_hook (db_path, "pre-tag");\r
191 +       if (ret)\r
192 +           return ret;\r
193 +    }\r
194 +\r
195 +    if (notmuch_database_open (db_path,\r
196                                NOTMUCH_DATABASE_MODE_READ_WRITE, &notmuch))\r
197         return 1;\r
198  \r
199 @@ -239,5 +250,11 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])\r
200  \r
201      notmuch_database_destroy (notmuch);\r
202  \r
203 +    if (run_hooks) {\r
204 +       ret = notmuch_run_hook (db_path, "post-tag");\r
205 +       if (ret)\r
206 +           return ret;\r
207 +    }\r
208 +\r
209      return ret;\r
210  }\r
211 diff --git a/test/hooks b/test/hooks\r
212 index 77e8569..ae857cc 100755\r
213 --- a/test/hooks\r
214 +++ b/test/hooks\r
215 @@ -31,6 +31,7 @@ rm_hooks () {\r
216  # add a message to generate mail dir and database\r
217  add_message\r
218  \r
219 +# {pre,post}-new hooks\r
220  test_begin_subtest "pre-new is run"\r
221  rm_hooks\r
222  generate_message\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
226  \r
227 +\r
228 +\r
229 +# {pre,post}-tag hooks\r
230 +test_begin_subtest "pre-tag is run"\r
231 +rm_hooks\r
232 +generate_message\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
236 +\r
237 +test_begin_subtest "post-tag is run"\r
238 +rm_hooks\r
239 +generate_message\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
243 +\r
244 +test_begin_subtest "pre-tag is run before post-new"\r
245 +rm_hooks\r
246 +generate_message\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
251 +\r
252 +test_begin_subtest "pre-tag non-zero exit status (hook status)"\r
253 +rm_hooks\r
254 +generate_message\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
258 +\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
261 +\r
262  test_done\r
263 -- \r
264 1.7.11.2\r
265 \r