"snoozing" with notmuch?
[notmuch-archives.git] / 0b / 23f73efe2af110b4a1b515246032185702cb80
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 918F640BFD3\r
6         for <notmuch@notmuchmail.org>; Wed, 13 Oct 2010 16:16:26 -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 ndB0ckcgaiCS for <notmuch@notmuchmail.org>;\r
16         Wed, 13 Oct 2010 16:16:15 -0700 (PDT)\r
17 Received: from mail2.tyndall.ie (tyndall.ucc.ie [143.239.64.1])\r
18         by olra.theworths.org (Postfix) with ESMTP id B9C6540BFD5\r
19         for <notmuch@notmuchmail.org>; Wed, 13 Oct 2010 16:16:14 -0700 (PDT)\r
20 Received: from localhost (localhost [127.0.0.1])\r
21         by mail2.tyndall.ie (Postfix) with ESMTP id 29C08B216F;\r
22         Thu, 14 Oct 2010 00:16:13 +0100 (IST)\r
23 X-Virus-Scanned: Debian amavisd-new at mail.tyndall.ie\r
24 Received: from mail2.tyndall.ie ([127.0.0.1])\r
25         by localhost (bastion2.tyndall.ie [127.0.0.1]) (amavisd-new, port 10024)\r
26         with ESMTP id uvIXBwdIb7+2; Thu, 14 Oct 2010 00:16:13 +0100 (IST)\r
27 Received: from unixmail.tyndall.ie (unknown [10.1.64.22])\r
28         by mail2.tyndall.ie (Postfix) with ESMTP id 0E2ACB216A;\r
29         Thu, 14 Oct 2010 00:16:13 +0100 (IST)\r
30 Received: from localhost (localhost [127.0.0.1])\r
31         by unixmail.tyndall.ie (Postfix) with ESMTP id 0AD6594DC1;\r
32         Thu, 14 Oct 2010 00:16:13 +0100 (IST)\r
33 X-Virus-Scanned: amavisd-new at tyndall.ie\r
34 Received: from unixmail.tyndall.ie ([127.0.0.1])\r
35         by localhost (unixmail.tyndall.ie [127.0.0.1]) (amavisd-new, port 10024)\r
36         with ESMTP id dOiHSlnk0hxH; Thu, 14 Oct 2010 00:16:11 +0100 (IST)\r
37 Received: from localhost6.localdomain6 (lnx0015f24b24c7.nmrc.ucc.ie\r
38         [10.1.65.106])\r
39         by unixmail.tyndall.ie (Postfix) with ESMTP id A8CBE94DBB;\r
40         Thu, 14 Oct 2010 00:16:11 +0100 (IST)\r
41 Received: from localhost6.localdomain6 (localhost.localdomain [127.0.0.1])\r
42         by localhost6.localdomain6 (8.14.4/8.14.3) with ESMTP id o9DND3ve011055;\r
43         Thu, 14 Oct 2010 00:13:03 +0100\r
44 Received: (from aamann@localhost)\r
45         by localhost6.localdomain6 (8.14.4/8.14.4/Submit) id o9DNCvTX011053;\r
46         Thu, 14 Oct 2010 00:12:57 +0100\r
47 X-Authentication-Warning: localhost6.localdomain6: aamann set sender to\r
48         andreas.amann@tyndall.ie using -f\r
49 From: Andreas Amann <andreas.amann@tyndall.ie>\r
50 To: Michal Sojka <sojkam1@fel.cvut.cz>, notmuch@notmuchmail.org\r
51 Subject: Re: [PATCH] Allow user to specify ignored directories\r
52 In-Reply-To: <87zkui1mtu.fsf@steelpick.2x.cz>\r
53 References: <ylp7hi23mw8.fsf@tyndall.ie> <87zkui1mtu.fsf@steelpick.2x.cz>\r
54 User-Agent: Notmuch/0.3.1-92-g42f7a90 (http://notmuchmail.org) Emacs/24.0.50.1\r
55         (x86_64-unknown-linux-gnu)\r
56 Date: Thu, 14 Oct 2010 00:12:57 +0100\r
57 Message-ID: <ylpaamhn0ue.fsf@tyndall.ie>\r
58 MIME-Version: 1.0\r
59 Content-Type: text/plain\r
60 X-BeenThere: notmuch@notmuchmail.org\r
61 X-Mailman-Version: 2.1.13\r
62 Precedence: list\r
63 List-Id: "Use and development of the notmuch mail system."\r
64         <notmuch.notmuchmail.org>\r
65 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
66         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
67 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
68 List-Post: <mailto:notmuch@notmuchmail.org>\r
69 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
70 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
71         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
72 X-List-Received-Date: Wed, 13 Oct 2010 23:16:26 -0000\r
73 \r
74 On Wed, 13 Oct 2010 11:09:01 +0200, Michal Sojka <sojkam1@fel.cvut.cz> wrote:\r
75 > On Thu, 30 Sep 2010, Andreas Amann wrote:\r
76\r
77 > Hi,\r
78\r
79 > thanks, the patch seems good to me. See the comment bellow.\r
80\r
81\r
82 > > @@ -202,7 +219,8 @@ _entries_resemble_maildir (struct dirent **entries, int count)\r
83 > >  static notmuch_status_t\r
84 > >  add_files_recursive (notmuch_database_t *notmuch,\r
85 > >                      const char *path,\r
86 > > -                    add_files_state_t *state)\r
87 > > +                    add_files_state_t *state,\r
88 > > +                     notmuch_config_t *config)\r
89\r
90 > I would not add additional parameter here. It's IMHO better to add field\r
91 > "ignored_files" to add_files_state_t similarly as it is done for\r
92 > new_tags.\r
93\r
94 \r
95 Thanks for your comment, you are right. Here is an improved version, any comments?\r
96 \r
97 Add functionality to ignore user specified directories during\r
98 recursive search. An "ignore" label in the "new" section of the\r
99 configuration file is added.\r
100 \r
101 Example snippet from ~/.notmuch-config:\r
102 \r
103 [new]\r
104 ignore=.git;.notmuch;\r
105 tags=unread;inbox;\r
106 ---\r
107  notmuch-client.h |    8 +++++++\r
108  notmuch-config.c |   57 +++++++++++++++++++++++++++++++++++++++++++++++++++++-\r
109  notmuch-new.c    |   35 ++++++++++++++++++++++++--------\r
110  3 files changed, 90 insertions(+), 10 deletions(-)\r
111 \r
112 diff --git a/notmuch-client.h b/notmuch-client.h\r
113 index 20be43b..9bc6ef1 100644\r
114 --- a/notmuch-client.h\r
115 +++ b/notmuch-client.h\r
116 @@ -191,6 +191,14 @@ notmuch_config_set_new_tags (notmuch_config_t *config,\r
117                              const char *new_tags[],\r
118                              size_t length);\r
119  \r
120 +const char **\r
121 +notmuch_config_get_new_ignore (notmuch_config_t *config,\r
122 +                               size_t *length);\r
123 +void\r
124 +notmuch_config_set_new_ignore (notmuch_config_t *config,\r
125 +                               const char *new_ignore[],\r
126 +                               size_t length);\r
127 +\r
128  notmuch_bool_t\r
129  debugger_is_active (void);\r
130  \r
131 diff --git a/notmuch-config.c b/notmuch-config.c\r
132 index cf30603..8841eaf 100644\r
133 --- a/notmuch-config.c\r
134 +++ b/notmuch-config.c\r
135 @@ -43,7 +43,10 @@ static const char new_config_comment[] =\r
136      " The following options are supported here:\n"\r
137      "\n"\r
138      "\ttags    A list (separated by ';') of the tags that will be\n"\r
139 -    "\t        added to all messages incorporated by \"notmuch new\".\n";\r
140 +    "\t        added to all messages incorporated by \"notmuch new\".\n"\r
141 +    "\n"\r
142 +    "\tignore  A list (separated by ';') of directories that will not\n"\r
143 +    "\t        be searched for messages  by \"notmuch new\".\n";\r
144  \r
145  static const char user_config_comment[] =\r
146      " User configuration\n"\r
147 @@ -72,6 +75,8 @@ struct _notmuch_config {\r
148      size_t user_other_email_length;\r
149      const char **new_tags;\r
150      size_t new_tags_length;\r
151 +    const char **new_ignore;\r
152 +    size_t new_ignore_length;\r
153  };\r
154  \r
155  static int\r
156 @@ -221,6 +226,8 @@ notmuch_config_open (void *ctx,\r
157      config->user_other_email_length = 0;\r
158      config->new_tags = NULL;\r
159      config->new_tags_length = 0;\r
160 +    config->new_ignore = NULL;\r
161 +    config->new_ignore_length = 0;\r
162  \r
163      if (! g_key_file_load_from_file (config->key_file,\r
164                                      config->filename,\r
165 @@ -313,6 +320,11 @@ notmuch_config_open (void *ctx,\r
166         notmuch_config_set_new_tags (config, tags, 2);\r
167      }\r
168  \r
169 +    if (notmuch_config_get_new_ignore (config, &tmp) == NULL) {\r
170 +        const char *ignore[] = { ".notmuch" };\r
171 +       notmuch_config_set_new_ignore (config, ignore, 2);\r
172 +    }\r
173 +\r
174      /* Whenever we know of configuration sections that don't appear in\r
175       * the configuration file, we add some comments to help the user\r
176       * understand what can be done. */\r
177 @@ -562,3 +574,46 @@ notmuch_config_set_new_tags (notmuch_config_t *config,\r
178      config->new_tags = NULL;\r
179  }\r
180  \r
181 +const char **\r
182 +notmuch_config_get_new_ignore (notmuch_config_t *config,\r
183 +                               size_t *length)\r
184 +{\r
185 +    char **ignore;\r
186 +    size_t ignore_length;\r
187 +    unsigned int i;\r
188 +\r
189 +    if (config->new_ignore == NULL) {\r
190 +       ignore = g_key_file_get_string_list (config->key_file,\r
191 +                                             "new", "ignore",\r
192 +                                             &ignore_length, NULL);\r
193 +       if (ignore) {\r
194 +           config->new_ignore = talloc_size (config,\r
195 +                                              sizeof (char *) *\r
196 +                                              (ignore_length + 1));\r
197 +           for (i = 0; i < ignore_length; i++)\r
198 +               config->new_ignore[i] = talloc_strdup (config->new_ignore,\r
199 +                                                       ignore[i]);\r
200 +           config->new_ignore[i] = NULL;\r
201 +\r
202 +           g_strfreev (ignore);\r
203 +\r
204 +           config->new_ignore_length = ignore_length;\r
205 +       }\r
206 +    }\r
207 +\r
208 +    *length = config->new_ignore_length;\r
209 +    return config->new_ignore;\r
210 +}\r
211 +\r
212 +void\r
213 +notmuch_config_set_new_ignore (notmuch_config_t *config,\r
214 +                               const char *new_ignore[],\r
215 +                               size_t length)\r
216 +{\r
217 +    g_key_file_set_string_list (config->key_file,\r
218 +                               "new", "ignore",\r
219 +                               new_ignore, length);\r
220 +\r
221 +    talloc_free (config->new_ignore);\r
222 +    config->new_ignore = NULL;\r
223 +}\r
224 diff --git a/notmuch-new.c b/notmuch-new.c\r
225 index 8818728..241a74e 100644\r
226 --- a/notmuch-new.c\r
227 +++ b/notmuch-new.c\r
228 @@ -38,6 +38,9 @@ typedef struct {\r
229      const char **new_tags;\r
230      size_t new_tags_length;\r
231  \r
232 +    const char **ignore_list;\r
233 +    size_t ignore_list_length;\r
234 +\r
235      int total_files;\r
236      int processed_files;\r
237      int added_messages;\r
238 @@ -164,6 +167,21 @@ _entries_resemble_maildir (struct dirent **entries, int count)\r
239      return 0;\r
240  }\r
241  \r
242 +/* Check if user asked to ignore these directories */\r
243 +\r
244 +static int\r
245 +_entry_in_ignore_list ( const char *entry, add_files_state_t* state)\r
246 +{\r
247 +    size_t j;\r
248 +    for (j = 0; j<state->ignore_list_length; j++)\r
249 +    {\r
250 +        if (strcmp (entry, state->ignore_list[j]) == 0 )\r
251 +            return 1;\r
252 +    }\r
253 +\r
254 +    return 0;\r
255 +}\r
256 +\r
257  /* Examine 'path' recursively as follows:\r
258   *\r
259   *   o Ask the filesystem for the mtime of 'path' (fs_mtime)\r
260 @@ -287,12 +305,10 @@ add_files_recursive (notmuch_database_t *notmuch,\r
261          * Also ignore the .notmuch directory and any "tmp" directory\r
262          * that appears within a maildir.\r
263          */\r
264 -       /* XXX: Eventually we'll want more sophistication to let the\r
265 -        * user specify files to be ignored. */\r
266         if (strcmp (entry->d_name, ".") == 0 ||\r
267             strcmp (entry->d_name, "..") == 0 ||\r
268             (is_maildir && strcmp (entry->d_name, "tmp") == 0) ||\r
269 -           strcmp (entry->d_name, ".notmuch") ==0)\r
270 +           _entry_in_ignore_list (entry->d_name, state) )\r
271         {\r
272             continue;\r
273         }\r
274 @@ -571,7 +587,7 @@ add_files (notmuch_database_t *notmuch,\r
275   * initialized to zero by the top-level caller before calling\r
276   * count_files). */\r
277  static void\r
278 -count_files (const char *path, int *count)\r
279 +count_files (const char *path, int *count, add_files_state_t *state)\r
280  {\r
281      struct dirent *entry = NULL;\r
282      char *next;\r
283 @@ -595,11 +611,9 @@ count_files (const char *path, int *count)\r
284         /* Ignore special directories to avoid infinite recursion.\r
285          * Also ignore the .notmuch directory.\r
286          */\r
287 -       /* XXX: Eventually we'll want more sophistication to let the\r
288 -        * user specify files to be ignored. */\r
289         if (strcmp (entry->d_name, ".") == 0 ||\r
290             strcmp (entry->d_name, "..") == 0 ||\r
291 -           strcmp (entry->d_name, ".notmuch") == 0)\r
292 +           _entry_in_ignore_list (entry->d_name, state) )\r
293         {\r
294             continue;\r
295         }\r
296 @@ -620,7 +634,7 @@ count_files (const char *path, int *count)\r
297                 fflush (stdout);\r
298             }\r
299         } else if (S_ISDIR (st.st_mode)) {\r
300 -           count_files (next, count);\r
301 +           count_files (next, count, state);\r
302         }\r
303  \r
304         free (next);\r
305 @@ -737,6 +751,9 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
306         return 1;\r
307  \r
308      add_files_state.new_tags = notmuch_config_get_new_tags (config, &add_files_state.new_tags_length);\r
309 +    add_files_state.ignore_list =\r
310 +        notmuch_config_get_new_ignore (config, &add_files_state.ignore_list_length);\r
311 +\r
312      db_path = notmuch_config_get_database_path (config);\r
313  \r
314      dot_notmuch_path = talloc_asprintf (ctx, "%s/%s", db_path, ".notmuch");\r
315 @@ -745,7 +762,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
316         int count;\r
317  \r
318         count = 0;\r
319 -       count_files (db_path, &count);\r
320 +       count_files (db_path, &count, &add_files_state);\r
321         if (interrupted)\r
322             return 1;\r
323  \r
324 -- \r
325 1.7.0.4\r
326 \r