Error when viewing mails.
[notmuch-archives.git] / f2 / 71f11fd5a75ba02f581e1be72c52329d5640b2
1 Return-Path: <andreas.amann@tyndall.ie>\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 88EB940BFD5\r
6         for <notmuch@notmuchmail.org>; Thu, 30 Sep 2010 15:16:24 -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: -4.2\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-4.2 tagged_above=-999 required=5\r
12         tests=[BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3] autolearn=ham\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 UpijZct-RKD7 for <notmuch@notmuchmail.org>;\r
16         Thu, 30 Sep 2010 15:16:13 -0700 (PDT)\r
17 X-Greylist: delayed 475 seconds by postgrey-1.32 at olra;\r
18         Thu, 30 Sep 2010 15:16:12 PDT\r
19 Received: from mail2.tyndall.ie (tyndall.ucc.ie [143.239.64.1])\r
20         by olra.theworths.org (Postfix) with ESMTP id C88F84196F2\r
21         for <notmuch@notmuchmail.org>; Thu, 30 Sep 2010 15:16:12 -0700 (PDT)\r
22 Received: from localhost (localhost [127.0.0.1])\r
23         by mail2.tyndall.ie (Postfix) with ESMTP id 61463B2132\r
24         for <notmuch@notmuchmail.org>; Thu, 30 Sep 2010 23:08:16 +0100 (IST)\r
25 X-Virus-Scanned: Debian amavisd-new at mail.tyndall.ie\r
26 Received: from mail2.tyndall.ie ([127.0.0.1])\r
27         by localhost (bastion2.tyndall.ie [127.0.0.1]) (amavisd-new, port 10024)\r
28         with ESMTP id qZZgLVRAplvL for <notmuch@notmuchmail.org>;\r
29         Thu, 30 Sep 2010 23:08:16 +0100 (IST)\r
30 Received: from unixmail.tyndall.ie (unknown [10.1.64.22])\r
31         by mail2.tyndall.ie (Postfix) with ESMTP id 427D0B2131\r
32         for <notmuch@notmuchmail.org>; Thu, 30 Sep 2010 23:08:16 +0100 (IST)\r
33 Received: from localhost (localhost [127.0.0.1])\r
34         by unixmail.tyndall.ie (Postfix) with ESMTP id 3E6E6865FB\r
35         for <notmuch@notmuchmail.org>; Thu, 30 Sep 2010 23:08:16 +0100 (IST)\r
36 X-Virus-Scanned: amavisd-new at tyndall.ie\r
37 Received: from unixmail.tyndall.ie ([127.0.0.1])\r
38         by localhost (unixmail.tyndall.ie [127.0.0.1]) (amavisd-new, port 10024)\r
39         with ESMTP id nWSsz3ua4MTA for <notmuch@notmuchmail.org>;\r
40         Thu, 30 Sep 2010 23:08:10 +0100 (IST)\r
41 Received: from localhost.localdomain (lnx0015f24b24c7.nmrc.ucc.ie\r
42         [10.1.65.106])\r
43         by unixmail.tyndall.ie (Postfix) with ESMTP id 9B64D865F5\r
44         for <notmuch@notmuchmail.org>; Thu, 30 Sep 2010 23:08:10 +0100 (IST)\r
45 Received: from localhost.localdomain (lnx0015f24b24c7 [127.0.0.1])\r
46         by localhost.localdomain (8.14.4/8.14.3) with ESMTP id o8UM8Ptb032602\r
47         for <notmuch@notmuchmail.org>; Thu, 30 Sep 2010 23:08:25 +0100\r
48 Received: (from aamann@localhost)\r
49         by localhost.localdomain (8.14.4/8.14.4/Submit) id o8UM8NMB032600;\r
50         Thu, 30 Sep 2010 23:08:23 +0100\r
51 X-Authentication-Warning: localhost.localdomain: aamann set sender to\r
52         andreas.amann@tyndall.ie using -f\r
53 From: Andreas Amann <andreas.amann@tyndall.ie>\r
54 To: notmuch@notmuchmail.org\r
55 Subject: [PATCH] Allow user to specify ignored directories\r
56 User-Agent: Notmuch/0.3.1-59-g676d251 (http://notmuchmail.org) Emacs/24.0.50.1\r
57         (x86_64-unknown-linux-gnu)\r
58 Date: Thu, 30 Sep 2010 23:08:23 +0100\r
59 Message-ID: <ylp7hi23mw8.fsf@tyndall.ie>\r
60 MIME-Version: 1.0\r
61 Content-Type: text/plain\r
62 X-Mailman-Approved-At: Tue, 12 Oct 2010 16:01:05 -0700\r
63 X-BeenThere: notmuch@notmuchmail.org\r
64 X-Mailman-Version: 2.1.13\r
65 Precedence: list\r
66 List-Id: "Use and development of the notmuch mail system."\r
67         <notmuch.notmuchmail.org>\r
68 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
69         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
70 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
71 List-Post: <mailto:notmuch@notmuchmail.org>\r
72 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
73 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
74         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
75 X-List-Received-Date: Thu, 30 Sep 2010 22:16:24 -0000\r
76 \r
77 Hi list,\r
78 \r
79 this is my first post. I found notmuch a couple of days ago and it works\r
80 great. However I wanted to be able to ignore certain directories (mostly\r
81 .git in my case) when "notmuch new" is running. \r
82 \r
83 With this patch the user can provide a list of directories which are\r
84 ignored during the recursive search for new messages. An "ignore"\r
85 label in the "new" section of the configuration file is added for this\r
86 purpose to enable for example something like\r
87 \r
88 [new]\r
89 ignore=.git;.notmuch;\r
90 tags=unread;inbox;\r
91 \r
92 in the .notmuch-config file. Feel free to apply if you find it useful. \r
93 \r
94 Andreas\r
95 \r
96 \r
97 \r
98 ---\r
99  notmuch-client.h |    8 +++++++\r
100  notmuch-config.c |   57 +++++++++++++++++++++++++++++++++++++++++++++++++++++-\r
101  notmuch-new.c    |   43 +++++++++++++++++++++++++++-------------\r
102  3 files changed, 93 insertions(+), 15 deletions(-)\r
103 \r
104 diff --git a/notmuch-client.h b/notmuch-client.h\r
105 index 20be43b..9bc6ef1 100644\r
106 --- a/notmuch-client.h\r
107 +++ b/notmuch-client.h\r
108 @@ -191,6 +191,14 @@ notmuch_config_set_new_tags (notmuch_config_t *config,\r
109                              const char *new_tags[],\r
110                              size_t length);\r
111  \r
112 +const char **\r
113 +notmuch_config_get_new_ignore (notmuch_config_t *config,\r
114 +                               size_t *length);\r
115 +void\r
116 +notmuch_config_set_new_ignore (notmuch_config_t *config,\r
117 +                               const char *new_ignore[],\r
118 +                               size_t length);\r
119 +\r
120  notmuch_bool_t\r
121  debugger_is_active (void);\r
122  \r
123 diff --git a/notmuch-config.c b/notmuch-config.c\r
124 index cf30603..8841eaf 100644\r
125 --- a/notmuch-config.c\r
126 +++ b/notmuch-config.c\r
127 @@ -43,7 +43,10 @@ static const char new_config_comment[] =\r
128      " The following options are supported here:\n"\r
129      "\n"\r
130      "\ttags    A list (separated by ';') of the tags that will be\n"\r
131 -    "\t        added to all messages incorporated by \"notmuch new\".\n";\r
132 +    "\t        added to all messages incorporated by \"notmuch new\".\n"\r
133 +    "\n"\r
134 +    "\tignore  A list (separated by ';') of directories that will not\n"\r
135 +    "\t        be searched for messages  by \"notmuch new\".\n";\r
136  \r
137  static const char user_config_comment[] =\r
138      " User configuration\n"\r
139 @@ -72,6 +75,8 @@ struct _notmuch_config {\r
140      size_t user_other_email_length;\r
141      const char **new_tags;\r
142      size_t new_tags_length;\r
143 +    const char **new_ignore;\r
144 +    size_t new_ignore_length;\r
145  };\r
146  \r
147  static int\r
148 @@ -221,6 +226,8 @@ notmuch_config_open (void *ctx,\r
149      config->user_other_email_length = 0;\r
150      config->new_tags = NULL;\r
151      config->new_tags_length = 0;\r
152 +    config->new_ignore = NULL;\r
153 +    config->new_ignore_length = 0;\r
154  \r
155      if (! g_key_file_load_from_file (config->key_file,\r
156                                      config->filename,\r
157 @@ -313,6 +320,11 @@ notmuch_config_open (void *ctx,\r
158         notmuch_config_set_new_tags (config, tags, 2);\r
159      }\r
160  \r
161 +    if (notmuch_config_get_new_ignore (config, &tmp) == NULL) {\r
162 +        const char *ignore[] = { ".notmuch" };\r
163 +       notmuch_config_set_new_ignore (config, ignore, 2);\r
164 +    }\r
165 +\r
166      /* Whenever we know of configuration sections that don't appear in\r
167       * the configuration file, we add some comments to help the user\r
168       * understand what can be done. */\r
169 @@ -562,3 +574,46 @@ notmuch_config_set_new_tags (notmuch_config_t *config,\r
170      config->new_tags = NULL;\r
171  }\r
172  \r
173 +const char **\r
174 +notmuch_config_get_new_ignore (notmuch_config_t *config,\r
175 +                               size_t *length)\r
176 +{\r
177 +    char **ignore;\r
178 +    size_t ignore_length;\r
179 +    unsigned int i;\r
180 +\r
181 +    if (config->new_ignore == NULL) {\r
182 +       ignore = g_key_file_get_string_list (config->key_file,\r
183 +                                             "new", "ignore",\r
184 +                                             &ignore_length, NULL);\r
185 +       if (ignore) {\r
186 +           config->new_ignore = talloc_size (config,\r
187 +                                              sizeof (char *) *\r
188 +                                              (ignore_length + 1));\r
189 +           for (i = 0; i < ignore_length; i++)\r
190 +               config->new_ignore[i] = talloc_strdup (config->new_ignore,\r
191 +                                                       ignore[i]);\r
192 +           config->new_ignore[i] = NULL;\r
193 +\r
194 +           g_strfreev (ignore);\r
195 +\r
196 +           config->new_ignore_length = ignore_length;\r
197 +       }\r
198 +    }\r
199 +\r
200 +    *length = config->new_ignore_length;\r
201 +    return config->new_ignore;\r
202 +}\r
203 +\r
204 +void\r
205 +notmuch_config_set_new_ignore (notmuch_config_t *config,\r
206 +                               const char *new_ignore[],\r
207 +                               size_t length)\r
208 +{\r
209 +    g_key_file_set_string_list (config->key_file,\r
210 +                               "new", "ignore",\r
211 +                               new_ignore, length);\r
212 +\r
213 +    talloc_free (config->new_ignore);\r
214 +    config->new_ignore = NULL;\r
215 +}\r
216 diff --git a/notmuch-new.c b/notmuch-new.c\r
217 index 8818728..0e9c4d7 100644\r
218 --- a/notmuch-new.c\r
219 +++ b/notmuch-new.c\r
220 @@ -164,6 +164,23 @@ _entries_resemble_maildir (struct dirent **entries, int count)\r
221      return 0;\r
222  }\r
223  \r
224 +/* Check if user asked to ignore these directories */\r
225 +\r
226 +static int\r
227 +_entry_in_ignore_list ( const char *entry, notmuch_config_t *config)\r
228 +{\r
229 +    size_t j;\r
230 +    size_t ignore_length;\r
231 +    const char** ignore = notmuch_config_get_new_ignore (config, &ignore_length);\r
232 +    for (j = 0; j<ignore_length; j++)\r
233 +    {\r
234 +        if (strcmp (entry, ignore[j]) == 0 )\r
235 +            return 1;\r
236 +    }\r
237 +\r
238 +    return 0;\r
239 +}\r
240 +\r
241  /* Examine 'path' recursively as follows:\r
242   *\r
243   *   o Ask the filesystem for the mtime of 'path' (fs_mtime)\r
244 @@ -202,7 +219,8 @@ _entries_resemble_maildir (struct dirent **entries, int count)\r
245  static notmuch_status_t\r
246  add_files_recursive (notmuch_database_t *notmuch,\r
247                      const char *path,\r
248 -                    add_files_state_t *state)\r
249 +                    add_files_state_t *state,\r
250 +                     notmuch_config_t *config)\r
251  {\r
252      DIR *dir = NULL;\r
253      struct dirent *entry = NULL;\r
254 @@ -287,18 +305,16 @@ add_files_recursive (notmuch_database_t *notmuch,\r
255          * Also ignore the .notmuch directory and any "tmp" directory\r
256          * that appears within a maildir.\r
257          */\r
258 -       /* XXX: Eventually we'll want more sophistication to let the\r
259 -        * user specify files to be ignored. */\r
260         if (strcmp (entry->d_name, ".") == 0 ||\r
261             strcmp (entry->d_name, "..") == 0 ||\r
262             (is_maildir && strcmp (entry->d_name, "tmp") == 0) ||\r
263 -           strcmp (entry->d_name, ".notmuch") ==0)\r
264 +           _entry_in_ignore_list (entry->d_name, config) )\r
265         {\r
266             continue;\r
267         }\r
268  \r
269         next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name);\r
270 -       status = add_files_recursive (notmuch, next, state);\r
271 +       status = add_files_recursive (notmuch, next, state, config);\r
272         if (status && ret == NOTMUCH_STATUS_SUCCESS)\r
273             ret = status;\r
274         talloc_free (next);\r
275 @@ -509,7 +525,8 @@ add_files_recursive (notmuch_database_t *notmuch,\r
276  static notmuch_status_t\r
277  add_files (notmuch_database_t *notmuch,\r
278            const char *path,\r
279 -          add_files_state_t *state)\r
280 +          add_files_state_t *state,\r
281 +           notmuch_config_t *config)\r
282  {\r
283      notmuch_status_t status;\r
284      struct sigaction action;\r
285 @@ -546,7 +563,7 @@ add_files (notmuch_database_t *notmuch,\r
286         return NOTMUCH_STATUS_FILE_ERROR;\r
287      }\r
288  \r
289 -    status = add_files_recursive (notmuch, path, state);\r
290 +    status = add_files_recursive (notmuch, path, state, config);\r
291  \r
292      if (timer_is_active) {\r
293         /* Now stop the timer. */\r
294 @@ -571,7 +588,7 @@ add_files (notmuch_database_t *notmuch,\r
295   * initialized to zero by the top-level caller before calling\r
296   * count_files). */\r
297  static void\r
298 -count_files (const char *path, int *count)\r
299 +count_files (const char *path, int *count, notmuch_config_t *config)\r
300  {\r
301      struct dirent *entry = NULL;\r
302      char *next;\r
303 @@ -595,11 +612,9 @@ count_files (const char *path, int *count)\r
304         /* Ignore special directories to avoid infinite recursion.\r
305          * Also ignore the .notmuch directory.\r
306          */\r
307 -       /* XXX: Eventually we'll want more sophistication to let the\r
308 -        * user specify files to be ignored. */\r
309         if (strcmp (entry->d_name, ".") == 0 ||\r
310             strcmp (entry->d_name, "..") == 0 ||\r
311 -           strcmp (entry->d_name, ".notmuch") == 0)\r
312 +           _entry_in_ignore_list (entry->d_name, config) )\r
313         {\r
314             continue;\r
315         }\r
316 @@ -620,7 +635,7 @@ count_files (const char *path, int *count)\r
317                 fflush (stdout);\r
318             }\r
319         } else if (S_ISDIR (st.st_mode)) {\r
320 -           count_files (next, count);\r
321 +           count_files (next, count, config);\r
322         }\r
323  \r
324         free (next);\r
325 @@ -745,7 +760,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
326         int count;\r
327  \r
328         count = 0;\r
329 -       count_files (db_path, &count);\r
330 +       count_files (db_path, &count, config);\r
331         if (interrupted)\r
332             return 1;\r
333  \r
334 @@ -792,7 +807,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
335      add_files_state.removed_files = _filename_list_create (ctx);\r
336      add_files_state.removed_directories = _filename_list_create (ctx);\r
337  \r
338 -    ret = add_files (notmuch, db_path, &add_files_state);\r
339 +    ret = add_files (notmuch, db_path, &add_files_state, config);\r
340  \r
341      removed_files = 0;\r
342      renamed_files = 0;\r
343 -- \r
344 1.7.0.4\r
345 \r
346 \r
347 -- \r
348 Dr. Andreas Amann\r
349 Tyndall National Institute \r
350 University College Cork\r
351 Ireland\r
352 \r