Re: [PATCH] STYLE: Initial draft of coding style document
[notmuch-archives.git] / 55 / dda9467b7425926bac4192eca9d7cae72d166d
1 Return-Path: <amdragon@mit.edu>\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 2A90F429E26\r
6         for <notmuch@notmuchmail.org>; Sat,  3 Dec 2011 19:59:03 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.7\r
10 X-Spam-Level: \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 Kt35X75cZCdz for <notmuch@notmuchmail.org>;\r
16         Sat,  3 Dec 2011 19:59:02 -0800 (PST)\r
17 Received: from dmz-mailsec-scanner-6.mit.edu (DMZ-MAILSEC-SCANNER-6.MIT.EDU\r
18         [18.7.68.35])\r
19         by olra.theworths.org (Postfix) with ESMTP id 1F743429E25\r
20         for <notmuch@notmuchmail.org>; Sat,  3 Dec 2011 19:59:02 -0800 (PST)\r
21 X-AuditID: 12074423-b7f266d0000008b8-70-4edaf005b67a\r
22 Received: from mailhub-auth-3.mit.edu ( [18.9.21.43])\r
23         by dmz-mailsec-scanner-6.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id 6F.4E.02232.500FADE4; Sat,  3 Dec 2011 22:59:01 -0500 (EST)\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
26         by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id pB43x0BM006725; \r
27         Sat, 3 Dec 2011 22:59:01 -0500\r
28 Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91])\r
29         (authenticated bits=0)\r
30         (User authenticated as amdragon@ATHENA.MIT.EDU)\r
31         by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id pB43wxGS011624\r
32         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
33         Sat, 3 Dec 2011 22:59:00 -0500 (EST)\r
34 Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77)\r
35         (envelope-from <amdragon@mit.edu>)\r
36         id 1RX3Fw-0004R8-0G; Sat, 03 Dec 2011 23:00:48 -0500\r
37 Date: Sat, 3 Dec 2011 23:00:47 -0500\r
38 From: Austin Clements <amdragon@MIT.EDU>\r
39 To: Jani Nikula <jani@nikula.org>\r
40 Subject: Re: [PATCH v2 2/2] cli: add support for pre and post notmuch new\r
41  hooks\r
42 Message-ID: <20111204040047.GB16405@mit.edu>\r
43 References:\r
44  <6688b09fffa2a66b496af78008102f88ab4e9450.1322953841.git.jani@nikula.org>\r
45         <6ccaa31da55b0dfc9e339780e43e24e1489235e8.1322953841.git.jani@nikula.org>\r
46 MIME-Version: 1.0\r
47 Content-Type: text/plain; charset=us-ascii\r
48 Content-Disposition: inline\r
49 In-Reply-To:\r
50  <6ccaa31da55b0dfc9e339780e43e24e1489235e8.1322953841.git.jani@nikula.org>\r
51 User-Agent: Mutt/1.5.21 (2010-09-15)\r
52 X-Brightmail-Tracker:\r
53  H4sIAAAAAAAAA+NgFmpkleLIzCtJLcpLzFFi42IR4hTV1mX9cMvP4NIHdYum6c4W12/OZHZg\r
54         8rh1/zW7x7NVt5gDmKK4bFJSczLLUov07RK4MrZOuc1W8Em74sYD0wbGPqUuRk4OCQETiRsb\r
55         WxkhbDGJC/fWs3UxcnEICexjlHh7djojhLOeUeLof4gqIYETTBKLF1tDJJYwSqw508IGkmAR\r
56         UJE4ve8WK4jNJqAhsW3/crAGEQFFic0n94PZzALSEt9+NzOB2MICgRI32xuB4hwcvAI6Ekv2\r
57         c0DMXMgosenlPLCZvAKCEidnPmGB6NWSuPHvJRNIPcic5f84QMKcAmESCza8ARsvCnTClJPb\r
58         2CYwCs1C0j0LSfcshO4FjMyrGGVTcqt0cxMzc4pTk3WLkxPz8lKLdM30cjNL9FJTSjcxgkKa\r
59         3UV5B+Ofg0qHGAU4GJV4eDNP3PITYk0sK67MPcQoycGkJMr77DVQiC8pP6UyI7E4I76oNCe1\r
60         +BCjBAezkghv10OgHG9KYmVValE+TEqag0VJnFdmp4OfkEB6YklqdmpqQWoRTFaGg0NJgrf8\r
61         PVCjYFFqempFWmZOCUKaiYMTZDgP0PBMkBre4oLE3OLMdIj8KUZFKXFeW5CEAEgiozQPrheW\r
62         cl4xigO9IsybDlLFA0xXcN2vgAYzAQ1WbLwBMrgkESEl1cAYqHV5fc1Tt2sb2xiuXUgrnzth\r
63         KtfdGY5Req/2qb1rX7JzoXBT1bYnyTuY/bb9drCO/OYr+HZnp8FRDw3nJfW+c0/x/P/GsfPX\r
64         zI01O5a9OHLtjtmiWRwX7D9wxu1LyJu14mb9pm3XVO5sfdf33kBEVe9uP9u6eVMPP3a4cv1a\r
65         zjafaTMXPb6p1anEUpyRaKjFXFScCABqzkPcFAMAAA==\r
66 Cc: notmuch@notmuchmail.org\r
67 X-BeenThere: notmuch@notmuchmail.org\r
68 X-Mailman-Version: 2.1.13\r
69 Precedence: list\r
70 List-Id: "Use and development of the notmuch mail system."\r
71         <notmuch.notmuchmail.org>\r
72 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
73         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
74 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
75 List-Post: <mailto:notmuch@notmuchmail.org>\r
76 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
77 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
78         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
79 X-List-Received-Date: Sun, 04 Dec 2011 03:59:03 -0000\r
80 \r
81 Quoth Jani Nikula on Dec 04 at  1:16 am:\r
82 > Run notmuch new pre and post hooks, named "pre-new" and "post-new", if\r
83 > present in the notmuch hooks directory. The hooks will be run before and\r
84 > after incorporating new messages to the database.\r
85\r
86 > Typical use cases for pre-new and post-new hooks are fetching or delivering\r
87 > new mail to the maildir, and custom tagging of the mail incorporated to the\r
88 > database.\r
89\r
90 > Also add command line option --no-hooks to notmuch new to bypass the hooks.\r
91\r
92 > Signed-off-by: Jani Nikula <jani@nikula.org>\r
93 > ---\r
94 >  notmuch-new.c |   12 ++++++++++++\r
95 >  notmuch.1     |   50 +++++++++++++++++++++++++++++++++++++++++++++++++-\r
96 >  2 files changed, 61 insertions(+), 1 deletions(-)\r
97\r
98 > diff --git a/notmuch-new.c b/notmuch-new.c\r
99 > index 81a9350..27dde0c 100644\r
100 > --- a/notmuch-new.c\r
101 > +++ b/notmuch-new.c\r
102 > @@ -811,6 +811,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
103 >      _filename_node_t *f;\r
104 >      int i;\r
105 >      notmuch_bool_t timer_is_active = FALSE;\r
106 > +    int run_hooks = 1;\r
107 \r
108 notmuch_bool_t?\r
109 \r
110 >  \r
111 >      add_files_state.verbose = 0;\r
112 >      add_files_state.output_is_a_tty = isatty (fileno (stdout));\r
113 > @@ -820,6 +821,8 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
114 >      for (i = 0; i < argc && argv[i][0] == '-'; i++) {\r
115 >       if (STRNCMP_LITERAL (argv[i], "--verbose") == 0) {\r
116 >           add_files_state.verbose = 1;\r
117 > +     } else if (STRNCMP_LITERAL (argv[i], "--no-hooks") == 0) {\r
118 \r
119 I see this mistake all over notmuch, so maybe it's better to\r
120 perpetuate it here and fix it everywhere in another patch, but this\r
121 should be strcmp, not STRNCMP_LITERAL.  STRNCMP_LITERAL is the right\r
122 thing for options that take values, but for boolean options like this,\r
123 it will accept\r
124   notmuch new --no-hooks-just-kidding\r
125 \r
126 > +         run_hooks = 0;\r
127 >       } else {\r
128 >           fprintf (stderr, "Unrecognized option: %s\n", argv[i]);\r
129 >           return 1;\r
130 > @@ -833,6 +836,12 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
131 >      add_files_state.synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);\r
132 >      db_path = notmuch_config_get_database_path (config);\r
133 >  \r
134 > +    if (run_hooks) {\r
135 > +     ret = notmuch_run_hook (db_path, "pre-new");\r
136 > +     if (ret)\r
137 > +         return ret;\r
138 > +    }\r
139 > +\r
140 >      dot_notmuch_path = talloc_asprintf (ctx, "%s/%s", db_path, ".notmuch");\r
141 >  \r
142 >      if (stat (dot_notmuch_path, &st)) {\r
143 > @@ -981,5 +990,8 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
144 >  \r
145 >      notmuch_database_close (notmuch);\r
146 >  \r
147 > +    if (run_hooks && !ret && !interrupted)\r
148 > +     ret = notmuch_run_hook (db_path, "post-new");\r
149 \r
150 Does it matter at this point if the hook fails?  I'm not sure.\r
151 \r
152 > +\r
153 >      return ret || interrupted;\r
154 >  }\r
155 > diff --git a/notmuch.1 b/notmuch.1\r
156 > index 92931d7..66f82e9 100644\r
157 > --- a/notmuch.1\r
158 > +++ b/notmuch.1\r
159 \r
160 I am willfully ignorant of nroff, so somebody else will have to\r
161 comment if any of the nroff code/formatting is wrong.\r
162 \r
163 > @@ -85,7 +85,7 @@ The\r
164 >  command is used to incorporate new mail into the notmuch database.\r
165 >  .RS 4\r
166 >  .TP 4\r
167 > -.B new\r
168 > +.BR new " [options...]"\r
169 >  \r
170 >  Find and import any new messages to the database.\r
171 >  \r
172 > @@ -118,6 +118,22 @@ if\r
173 >  has previously been completed, but\r
174 >  .B "notmuch new"\r
175 >  has not previously been run.\r
176 > +\r
177 > +The\r
178 > +.B new\r
179 > +command supports hooks. See the\r
180 > +.B "HOOKS"\r
181 > +section below for more details on hooks.\r
182 > +\r
183 > +Supported options for\r
184 > +.B new\r
185 > +include\r
186 > +.RS 4\r
187 > +.TP 4\r
188 > +.BR \-\-no\-hooks\r
189 > +\r
190 > +Prevents hooks from being run.\r
191 > +.RE\r
192 >  .RE\r
193 >  \r
194 >  Several of the notmuch commands accept search terms with a common\r
195 > @@ -705,6 +721,38 @@ specify a date range to return messages from 2009\-10\-01 until the\r
196 >  current time:\r
197 >  \r
198 >       $(date +%s \-d 2009\-10\-01)..$(date +%s)\r
199 > +.SH HOOKS\r
200 > +Hooks are scripts (or arbitrary executables or symlinks to such) you can place\r
201 > +in the notmuch hooks directory to trigger action at certain points. The hooks\r
202 > +directory is .notmuch/hooks within the database directory. The user must have\r
203 > +executable permission set on the scripts.\r
204 \r
205 Could be more concise.  Maybe something like "Hooks are scripts (or\r
206 arbitrary executables or symlinks to such) that notmuch invokes before\r
207 and after certain actions.  These scripts reside in the .notmuch/hooks\r
208 directory within the database directory and must have executable\r
209 permissions."\r
210 \r
211 > +\r
212 > +The currently available hooks are described below.\r
213 > +.RS 4\r
214 > +.TP 4\r
215 > +.B pre\-new\r
216 > +This hook is invoked by the\r
217 > +.B new\r
218 > +command before scanning or importing new messages into the database. Any errors\r
219 > +in running the hook will abort further processing of the\r
220 \r
221 "If this script exits with a non-zero status, notmuch will abort ..."?\r
222 \r
223 > +.B new\r
224 > +command.\r
225 > +\r
226 > +Typical use case for this hook is fetching or delivering new mail to be imported\r
227 > +into the database.\r
228 \r
229 Perhaps "Typically this hook is used for ..."?\r
230 \r
231 > +.RE\r
232 > +.RS 4\r
233 > +.TP 4\r
234 > +.B post\-new\r
235 > +This hook is invoked by the\r
236 > +.B new\r
237 > +command after new messages have been imported into the database and initial tags\r
238 > +have been applied. The hook will not be run if there have been any errors during\r
239 > +the scan or import.\r
240 > +\r
241 > +Typical use case for this hook is performing additional query based tagging on\r
242 > +the imported messages.\r
243 \r
244 Same thing.  "Typically this hook is used to perform ..."?  Also,\r
245 "query-based".\r
246 \r
247 > +.RE\r
248 >  .SH ENVIRONMENT\r
249 >  The following environment variables can be used to control the\r
250 >  behavior of notmuch.\r