[PATCH 2/9] lib: private string map (associative array) API
[notmuch-archives.git] / 1f / 71b62fe95f593257a8f23ebd64f55f7531051b
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 AB951429E26\r
6         for <notmuch@notmuchmail.org>; Sat,  3 Dec 2011 15:16:58 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"\r
9 X-Spam-Flag: NO\r
10 X-Spam-Score: -0.7\r
11 X-Spam-Level: \r
12 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
13         tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
14 Received: from olra.theworths.org ([127.0.0.1])\r
15         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
16         with ESMTP id uIBM-oH53Pye for <notmuch@notmuchmail.org>;\r
17         Sat,  3 Dec 2011 15:16:58 -0800 (PST)\r
18 Received: from mail-ww0-f45.google.com (mail-ww0-f45.google.com\r
19  [74.125.82.45])        (using TLSv1 with cipher RC4-SHA (128/128 bits))        (No client\r
20  certificate requested) by olra.theworths.org (Postfix) with ESMTPS id\r
21  CA89A429E25    for <notmuch@notmuchmail.org>; Sat,  3 Dec 2011 15:16:57 -0800\r
22  (PST)\r
23 Received: by mail-ww0-f45.google.com with SMTP id ds13so3394124wgb.2\r
24         for <notmuch@notmuchmail.org>; Sat, 03 Dec 2011 15:16:57 -0800 (PST)\r
25 Received: by 10.227.205.197 with SMTP id fr5mr10797322wbb.3.1322954217527;\r
26         Sat, 03 Dec 2011 15:16:57 -0800 (PST)\r
27 Received: from localhost (dsl-hkibrasgw4-fe5cdc00-23.dhcp.inet.fi.\r
28         [80.220.92.23])\r
29         by mx.google.com with ESMTPS id dd4sm6904421wib.1.2011.12.03.15.16.55\r
30         (version=SSLv3 cipher=OTHER); Sat, 03 Dec 2011 15:16:56 -0800 (PST)\r
31 From: Jani Nikula <jani@nikula.org>\r
32 To: notmuch@notmuchmail.org\r
33 Subject: [PATCH v2 2/2] cli: add support for pre and post notmuch new hooks\r
34 Date: Sun,  4 Dec 2011 01:16:49 +0200\r
35 Message-Id:\r
36  <6ccaa31da55b0dfc9e339780e43e24e1489235e8.1322953841.git.jani@nikula.org>\r
37 X-Mailer: git-send-email 1.7.5.4\r
38 In-Reply-To:\r
39  <6688b09fffa2a66b496af78008102f88ab4e9450.1322953841.git.jani@nikula.org>\r
40 References:\r
41  <7fbe6befcf31881a9bca672f55b93501249a220c.1322859389.git.jani@nikula.org>\r
42         <6688b09fffa2a66b496af78008102f88ab4e9450.1322953841.git.jani@nikula.org>\r
43 In-Reply-To:\r
44  <6688b09fffa2a66b496af78008102f88ab4e9450.1322953841.git.jani@nikula.org>\r
45 References:\r
46  <6688b09fffa2a66b496af78008102f88ab4e9450.1322953841.git.jani@nikula.org>\r
47 X-BeenThere: notmuch@notmuchmail.org\r
48 X-Mailman-Version: 2.1.13\r
49 Precedence: list\r
50 List-Id: "Use and development of the notmuch mail system."\r
51         <notmuch.notmuchmail.org>\r
52 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
53         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
54 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
55 List-Post: <mailto:notmuch@notmuchmail.org>\r
56 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
57 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
58         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
59 X-List-Received-Date: Sat, 03 Dec 2011 23:16:58 -0000\r
60 \r
61 Run notmuch new pre and post hooks, named "pre-new" and "post-new", if\r
62 present in the notmuch hooks directory. The hooks will be run before and\r
63 after incorporating new messages to the database.\r
64 \r
65 Typical use cases for pre-new and post-new hooks are fetching or delivering\r
66 new mail to the maildir, and custom tagging of the mail incorporated to the\r
67 database.\r
68 \r
69 Also add command line option --no-hooks to notmuch new to bypass the hooks.\r
70 \r
71 Signed-off-by: Jani Nikula <jani@nikula.org>\r
72 ---\r
73  notmuch-new.c |   12 ++++++++++++\r
74  notmuch.1     |   50 +++++++++++++++++++++++++++++++++++++++++++++++++-\r
75  2 files changed, 61 insertions(+), 1 deletions(-)\r
76 \r
77 diff --git a/notmuch-new.c b/notmuch-new.c\r
78 index 81a9350..27dde0c 100644\r
79 --- a/notmuch-new.c\r
80 +++ b/notmuch-new.c\r
81 @@ -811,6 +811,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
82      _filename_node_t *f;\r
83      int i;\r
84      notmuch_bool_t timer_is_active = FALSE;\r
85 +    int run_hooks = 1;\r
86  \r
87      add_files_state.verbose = 0;\r
88      add_files_state.output_is_a_tty = isatty (fileno (stdout));\r
89 @@ -820,6 +821,8 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
90      for (i = 0; i < argc && argv[i][0] == '-'; i++) {\r
91         if (STRNCMP_LITERAL (argv[i], "--verbose") == 0) {\r
92             add_files_state.verbose = 1;\r
93 +       } else if (STRNCMP_LITERAL (argv[i], "--no-hooks") == 0) {\r
94 +           run_hooks = 0;\r
95         } else {\r
96             fprintf (stderr, "Unrecognized option: %s\n", argv[i]);\r
97             return 1;\r
98 @@ -833,6 +836,12 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
99      add_files_state.synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);\r
100      db_path = notmuch_config_get_database_path (config);\r
101  \r
102 +    if (run_hooks) {\r
103 +       ret = notmuch_run_hook (db_path, "pre-new");\r
104 +       if (ret)\r
105 +           return ret;\r
106 +    }\r
107 +\r
108      dot_notmuch_path = talloc_asprintf (ctx, "%s/%s", db_path, ".notmuch");\r
109  \r
110      if (stat (dot_notmuch_path, &st)) {\r
111 @@ -981,5 +990,8 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
112  \r
113      notmuch_database_close (notmuch);\r
114  \r
115 +    if (run_hooks && !ret && !interrupted)\r
116 +       ret = notmuch_run_hook (db_path, "post-new");\r
117 +\r
118      return ret || interrupted;\r
119  }\r
120 diff --git a/notmuch.1 b/notmuch.1\r
121 index 92931d7..66f82e9 100644\r
122 --- a/notmuch.1\r
123 +++ b/notmuch.1\r
124 @@ -85,7 +85,7 @@ The\r
125  command is used to incorporate new mail into the notmuch database.\r
126  .RS 4\r
127  .TP 4\r
128 -.B new\r
129 +.BR new " [options...]"\r
130  \r
131  Find and import any new messages to the database.\r
132  \r
133 @@ -118,6 +118,22 @@ if\r
134  has previously been completed, but\r
135  .B "notmuch new"\r
136  has not previously been run.\r
137 +\r
138 +The\r
139 +.B new\r
140 +command supports hooks. See the\r
141 +.B "HOOKS"\r
142 +section below for more details on hooks.\r
143 +\r
144 +Supported options for\r
145 +.B new\r
146 +include\r
147 +.RS 4\r
148 +.TP 4\r
149 +.BR \-\-no\-hooks\r
150 +\r
151 +Prevents hooks from being run.\r
152 +.RE\r
153  .RE\r
154  \r
155  Several of the notmuch commands accept search terms with a common\r
156 @@ -705,6 +721,38 @@ specify a date range to return messages from 2009\-10\-01 until the\r
157  current time:\r
158  \r
159         $(date +%s \-d 2009\-10\-01)..$(date +%s)\r
160 +.SH HOOKS\r
161 +Hooks are scripts (or arbitrary executables or symlinks to such) you can place\r
162 +in the notmuch hooks directory to trigger action at certain points. The hooks\r
163 +directory is .notmuch/hooks within the database directory. The user must have\r
164 +executable permission set on the scripts.\r
165 +\r
166 +The currently available hooks are described below.\r
167 +.RS 4\r
168 +.TP 4\r
169 +.B pre\-new\r
170 +This hook is invoked by the\r
171 +.B new\r
172 +command before scanning or importing new messages into the database. Any errors\r
173 +in running the hook will abort further processing of the\r
174 +.B new\r
175 +command.\r
176 +\r
177 +Typical use case for this hook is fetching or delivering new mail to be imported\r
178 +into the database.\r
179 +.RE\r
180 +.RS 4\r
181 +.TP 4\r
182 +.B post\-new\r
183 +This hook is invoked by the\r
184 +.B new\r
185 +command after new messages have been imported into the database and initial tags\r
186 +have been applied. The hook will not be run if there have been any errors during\r
187 +the scan or import.\r
188 +\r
189 +Typical use case for this hook is performing additional query based tagging on\r
190 +the imported messages.\r
191 +.RE\r
192  .SH ENVIRONMENT\r
193  The following environment variables can be used to control the\r
194  behavior of notmuch.\r
195 -- \r
196 1.7.5.4\r
197 \r