Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 61 / c96e1d786b25a40fbe5a3d50f2ed1efe4ec846
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 7EE61429E21\r
6         for <notmuch@notmuchmail.org>; Fri,  2 Dec 2011 13:00:19 -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 fr+YZLJRn6MS for <notmuch@notmuchmail.org>;\r
17         Fri,  2 Dec 2011 13:00:18 -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  3A42B429E34    for <notmuch@notmuchmail.org>; Fri,  2 Dec 2011 13:00:18 -0800\r
22  (PST)\r
23 Received: by wgbds13 with SMTP id ds13so1494759wgb.2\r
24         for <notmuch@notmuchmail.org>; Fri, 02 Dec 2011 13:00:16 -0800 (PST)\r
25 Received: by 10.216.137.137 with SMTP id y9mr803861wei.112.1322859616200;\r
26         Fri, 02 Dec 2011 13:00:16 -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 em4sm12046848wbb.20.2011.12.02.13.00.14\r
30         (version=SSLv3 cipher=OTHER); Fri, 02 Dec 2011 13:00:14 -0800 (PST)\r
31 From: Jani Nikula <jani@nikula.org>\r
32 To: notmuch@notmuchmail.org\r
33 Subject: [PATCH 2/2] cli: add support for running notmuch new pre and post\r
34         hooks\r
35 Date: Fri,  2 Dec 2011 23:00:06 +0200\r
36 Message-Id:\r
37  <716da00e176e1dc6af0ba248caee40acee733120.1322859389.git.jani@nikula.org>\r
38 X-Mailer: git-send-email 1.7.5.4\r
39 In-Reply-To:\r
40  <7fbe6befcf31881a9bca672f55b93501249a220c.1322859389.git.jani@nikula.org>\r
41 References:\r
42  <7fbe6befcf31881a9bca672f55b93501249a220c.1322859389.git.jani@nikula.org>\r
43 In-Reply-To:\r
44  <7fbe6befcf31881a9bca672f55b93501249a220c.1322859389.git.jani@nikula.org>\r
45 References:\r
46  <7fbe6befcf31881a9bca672f55b93501249a220c.1322859389.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: Fri, 02 Dec 2011 21:00:19 -0000\r
60 \r
61 Run notmuch new pre and post hooks if specified in the notmuch config\r
62 file. The hooks will be run before and after incorporating new messages to\r
63 the database. Also add command line option --no-hooks to notmuch new to\r
64 bypass the hooks.\r
65 \r
66 With this patch, you can add hooks in your config, for example:\r
67 \r
68 [new]\r
69 prehook=offlineimap\r
70 posthook=my-tagging-script\r
71 \r
72 As the value is passed to system(1), you can actually have multiple\r
73 commands, redirections, pipes, etc. in there. If the tagging is simple\r
74 enough, you can just add the tagging in-line without a script.\r
75 \r
76 TODO:\r
77 \r
78 * Tests.\r
79 \r
80 * Documentation (manpage and help).\r
81 \r
82 Signed-off-by: Jani Nikula <jani@nikula.org>\r
83 ---\r
84  notmuch-client.h |    3 ++-\r
85  notmuch-config.c |   16 +++++++++++++++-\r
86  notmuch-new.c    |    9 +++++++++\r
87  3 files changed, 26 insertions(+), 2 deletions(-)\r
88 \r
89 diff --git a/notmuch-client.h b/notmuch-client.h\r
90 index 5e2fed2..d2ebc73 100644\r
91 --- a/notmuch-client.h\r
92 +++ b/notmuch-client.h\r
93 @@ -88,7 +88,8 @@ typedef struct notmuch_show_params {\r
94  } notmuch_show_params_t;\r
95  \r
96  typedef enum {\r
97 -    NOTMUCH_HOOK_PLACEHOLDER,\r
98 +    NOTMUCH_HOOK_PRE_NEW,\r
99 +    NOTMUCH_HOOK_POST_NEW,\r
100  } notmuch_hook_t;\r
101  \r
102  /* There's no point in continuing when we've detected that we've done\r
103 diff --git a/notmuch-config.c b/notmuch-config.c\r
104 index 8f1a038..277f197 100644\r
105 --- a/notmuch-config.c\r
106 +++ b/notmuch-config.c\r
107 @@ -43,7 +43,13 @@ static const char new_config_comment[] =\r
108      " The following options are supported here:\n"\r
109      "\n"\r
110      "\ttags    A list (separated by ';') of the tags that will be\n"\r
111 -    "\t        added to all messages incorporated by \"notmuch new\".\n";\r
112 +    "\t        added to all messages incorporated by \"notmuch new\".\n"\r
113 +    "\tprehook A command to be executed before \"notmuch new\" starts\n"\r
114 +    "\t        incorporating new messages. For example, this could be used to fetch\n"\r
115 +    "\t        and deliver new messages to the mail directory.\n"\r
116 +    "\tposthook        A command to be executed after \"notmuch new\" has\n"\r
117 +    "\t        incorporated and tagged all new messages. For example, this could\n"\r
118 +    "\t        be used to perform further tagging on new messages.\n";\r
119  \r
120  static const char user_config_comment[] =\r
121      " User configuration\n"\r
122 @@ -615,6 +621,14 @@ notmuch_config_get_hook (notmuch_config_t *config, notmuch_hook_t hook)\r
123      const char *group, *key;\r
124  \r
125      switch (hook) {\r
126 +    case NOTMUCH_HOOK_PRE_NEW:\r
127 +       group = "new";\r
128 +       key = "prehook";\r
129 +       break;\r
130 +    case NOTMUCH_HOOK_POST_NEW:\r
131 +       group = "new";\r
132 +       key = "posthook";\r
133 +       break;\r
134      default:\r
135         INTERNAL_ERROR ("Unknown hook %d\n.", hook);\r
136      }\r
137 diff --git a/notmuch-new.c b/notmuch-new.c\r
138 index 0c70e64..09cc3f2 100644\r
139 --- a/notmuch-new.c\r
140 +++ b/notmuch-new.c\r
141 @@ -836,6 +836,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
142      _filename_node_t *f;\r
143      int i;\r
144      notmuch_bool_t timer_is_active = FALSE;\r
145 +    int run_hooks = 1;\r
146  \r
147      add_files_state.verbose = 0;\r
148      add_files_state.output_is_a_tty = isatty (fileno (stdout));\r
149 @@ -845,6 +846,8 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
150      for (i = 0; i < argc && argv[i][0] == '-'; i++) {\r
151         if (STRNCMP_LITERAL (argv[i], "--verbose") == 0) {\r
152             add_files_state.verbose = 1;\r
153 +       } else if (STRNCMP_LITERAL (argv[i], "--no-hooks") == 0) {\r
154 +           run_hooks = 0;\r
155         } else {\r
156             fprintf (stderr, "Unrecognized option: %s\n", argv[i]);\r
157             return 1;\r
158 @@ -854,6 +857,9 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
159      if (config == NULL)\r
160         return 1;\r
161  \r
162 +    if (run_hooks && notmuch_run_hook (config, NOTMUCH_HOOK_PRE_NEW))\r
163 +       return 1;\r
164 +\r
165      add_files_state.new_tags = notmuch_config_get_new_tags (config, &add_files_state.new_tags_length);\r
166      add_files_state.synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);\r
167      db_path = notmuch_config_get_database_path (config);\r
168 @@ -1006,5 +1012,8 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
169  \r
170      notmuch_database_close (notmuch);\r
171  \r
172 +    if (run_hooks && !interrupted)\r
173 +       ret |= notmuch_run_hook (config, NOTMUCH_HOOK_POST_NEW);\r
174 +\r
175      return ret || interrupted;\r
176  }\r
177 -- \r
178 1.7.5.4\r
179 \r