Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / fc / b11426496d29e21c49bc9addc55e8cf7baee27
1 Return-Path: <too@guru.guru-group.fi>\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 3FD89431FAF\r
6         for <notmuch@notmuchmail.org>; Thu,  2 Feb 2012 07:17:37 -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\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         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 cbm97wznjCRk for <notmuch@notmuchmail.org>;\r
16         Thu,  2 Feb 2012 07:17:36 -0800 (PST)\r
17 Received: from guru.guru-group.fi (guru-group.fi [87.108.86.66])\r
18         by olra.theworths.org (Postfix) with ESMTP id D7FBF431FAE\r
19         for <notmuch@notmuchmail.org>; Thu,  2 Feb 2012 07:17:35 -0800 (PST)\r
20 Received: by guru.guru-group.fi (Postfix, from userid 501)\r
21         id 3969268055; Thu,  2 Feb 2012 17:17:35 +0200 (EET)\r
22 From: Tomi Ollila <tomi.ollila@iki.fi>\r
23 To: notmuch@notmuchmail.org\r
24 Subject: [PATCH] add support for user-specified files & directories to ignore\r
25 Date: Thu,  2 Feb 2012 17:17:33 +0200\r
26 Message-Id: <20120202-new-ignore-1-git-send-email-too@iki.fi>\r
27 X-Mailer: git-send-email 1.7.6.1\r
28 In-Reply-To: <id:"1315949524-4948-1-git-send-email-tomi.ollila@iki.fi">\r
29 References: <id:"1315949524-4948-1-git-send-email-tomi.ollila@iki.fi">\r
30 Cc: Tomi Ollila <tomi.ollila@iki.fi>\r
31 X-BeenThere: notmuch@notmuchmail.org\r
32 X-Mailman-Version: 2.1.13\r
33 Precedence: list\r
34 List-Id: "Use and development of the notmuch mail system."\r
35         <notmuch.notmuchmail.org>\r
36 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
37         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
38 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
39 List-Post: <mailto:notmuch@notmuchmail.org>\r
40 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
41 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
42         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
43 X-List-Received-Date: Thu, 02 Feb 2012 15:17:37 -0000\r
44 \r
45 A new configuration key 'new.ignore' is used to determine which\r
46 files and directories user wants not to be scanned as new mails.\r
47 \r
48 Mark the corresponding test as no longer broken\r
49 (test from id:"1328105573-4626-1-git-send-email-pieter@praet.org" ).\r
50 \r
51 This work merges my previous attempts and Andreas Amann's work\r
52 in id:"ylp7hi23mw8.fsf@tyndall.ie"\r
53 \r
54 See notes in id:"20120202-new-ignore-1-git-send-email-too@iki.fi"\r
55 ---\r
56 \r
57 Whenever some already existing directory is added to the exclude list\r
58 and the parent directory timestamp has not changed, notmuch new will not\r
59 notice the directory has gone (as it still is there), user needs to 'touch'\r
60 the parent directory before next 'notmuch new' no make notmuch notice.\r
61 \r
62 2012-01-26: could notmuch track mtime of the configuration file and if\r
63 that changes, ignore mail directory timestamps ?\r
64 \r
65 See previous notes in id:"20120131-new-ignore-1-git-send-email-too@iki.fi"\r
66 \r
67  notmuch-client.h |   10 ++++++++++\r
68  notmuch-config.c |   33 +++++++++++++++++++++++++++++++--\r
69  notmuch-new.c    |   45 +++++++++++++++++++++++++++++++++------------\r
70  test/new         |    1 -\r
71  4 files changed, 74 insertions(+), 15 deletions(-)\r
72 \r
73 diff --git a/notmuch-client.h b/notmuch-client.h\r
74 index e0eb594..26153df 100644\r
75 --- a/notmuch-client.h\r
76 +++ b/notmuch-client.h\r
77 @@ -245,11 +245,21 @@ notmuch_config_set_user_other_email (notmuch_config_t *config,\r
78  const char **\r
79  notmuch_config_get_new_tags (notmuch_config_t *config,\r
80                              size_t *length);\r
81 +\r
82  void\r
83  notmuch_config_set_new_tags (notmuch_config_t *config,\r
84                              const char *new_tags[],\r
85                              size_t length);\r
86  \r
87 +const char **\r
88 +notmuch_config_get_new_ignore (notmuch_config_t *config,\r
89 +                              size_t *length);\r
90 +\r
91 +void\r
92 +notmuch_config_set_new_ignore (notmuch_config_t *config,\r
93 +                              const char *new_ignore[],\r
94 +                              size_t length);\r
95 +\r
96  notmuch_bool_t\r
97  notmuch_config_get_maildir_synchronize_flags (notmuch_config_t *config);\r
98  \r
99 diff --git a/notmuch-config.c b/notmuch-config.c\r
100 index a124e34..1f01004 100644\r
101 --- a/notmuch-config.c\r
102 +++ b/notmuch-config.c\r
103 @@ -44,7 +44,10 @@ static const char new_config_comment[] =\r
104      " The following options are supported here:\n"\r
105      "\n"\r
106      "\ttags    A list (separated by ';') of the tags that will be\n"\r
107 -    "\t        added to all messages incorporated by \"notmuch new\".\n";\r
108 +    "\t        added to all messages incorporated by \"notmuch new\".\n"\r
109 +    "\n"\r
110 +    "\tignore  A list (separated by ';') of file and directory names\n"\r
111 +    "\t        that will not be searched for messages by \"notmuch new\".\n";\r
112  \r
113  static const char user_config_comment[] =\r
114      " User configuration\n"\r
115 @@ -105,6 +108,8 @@ struct _notmuch_config {\r
116      size_t user_other_email_length;\r
117      const char **new_tags;\r
118      size_t new_tags_length;\r
119 +    const char **new_ignore;\r
120 +    size_t new_ignore_length;\r
121      notmuch_bool_t maildir_synchronize_flags;\r
122      const char **search_exclude_tags;\r
123      size_t search_exclude_tags_length;\r
124 @@ -264,6 +269,8 @@ notmuch_config_open (void *ctx,\r
125      config->user_other_email_length = 0;\r
126      config->new_tags = NULL;\r
127      config->new_tags_length = 0;\r
128 +    config->new_ignore = NULL;\r
129 +    config->new_ignore_length = 0;\r
130      config->maildir_synchronize_flags = TRUE;\r
131      config->search_exclude_tags = NULL;\r
132      config->search_exclude_tags_length = 0;\r
133 @@ -361,6 +368,10 @@ notmuch_config_open (void *ctx,\r
134         notmuch_config_set_new_tags (config, tags, 2);\r
135      }\r
136  \r
137 +    if (notmuch_config_get_new_ignore (config, &tmp) == NULL) {\r
138 +       notmuch_config_set_new_ignore (config, NULL, 0);\r
139 +    }\r
140 +\r
141      if (notmuch_config_get_search_exclude_tags (config, &tmp) == NULL) {\r
142         if (is_new) {\r
143             const char *tags[] = { "deleted", "spam" };\r
144 @@ -504,7 +515,8 @@ _config_set_list (notmuch_config_t *config,\r
145                   const char *list[],\r
146                   size_t length, const char ***config_var )\r
147  {\r
148 -    g_key_file_set_string_list (config->key_file, group, name, list, length);\r
149 +    g_key_file_set_string_list (config->key_file,\r
150 +                               group, name, list, length);\r
151      talloc_free (*config_var);\r
152      *config_var = NULL;\r
153  }\r
154 @@ -609,6 +621,14 @@ notmuch_config_get_new_tags (notmuch_config_t *config,   size_t *length)\r
155                              &(config->new_tags_length), length);\r
156  }\r
157  \r
158 +const char **\r
159 +notmuch_config_get_new_ignore (notmuch_config_t *config, size_t *length)\r
160 +{\r
161 +    return _config_get_list (config, "new", "ignore",\r
162 +                            &(config->new_ignore),\r
163 +                            &(config->new_ignore_length), length);\r
164 +}\r
165 +\r
166  void\r
167  notmuch_config_set_user_other_email (notmuch_config_t *config,\r
168                                      const char *list[],\r
169 @@ -627,6 +647,15 @@ notmuch_config_set_new_tags (notmuch_config_t *config,\r
170                      &(config->new_tags));\r
171  }\r
172  \r
173 +void\r
174 +notmuch_config_set_new_ignore (notmuch_config_t *config,\r
175 +                              const char *list[],\r
176 +                              size_t length)\r
177 +{\r
178 +    _config_set_list (config, "new", "ignore", list, length,\r
179 +                    &(config->new_ignore));\r
180 +}\r
181 +\r
182  const char **\r
183  notmuch_config_get_search_exclude_tags (notmuch_config_t *config, size_t *length)\r
184  {\r
185 diff --git a/notmuch-new.c b/notmuch-new.c\r
186 index a569a54..f1c271a 100644\r
187 --- a/notmuch-new.c\r
188 +++ b/notmuch-new.c\r
189 @@ -39,6 +39,8 @@ typedef struct {\r
190      int verbose;\r
191      const char **new_tags;\r
192      size_t new_tags_length;\r
193 +    const char **new_ignore;\r
194 +    size_t new_ignore_length;\r
195  \r
196      int total_files;\r
197      int processed_files;\r
198 @@ -181,6 +183,20 @@ _entries_resemble_maildir (struct dirent **entries, int count)\r
199      return 0;\r
200  }\r
201  \r
202 +/* Test if the file/directory is to be ignored. */\r
203 +\r
204 +static notmuch_bool_t\r
205 +_entry_in_ignore_list (const char *entry, add_files_state_t *state)\r
206 +{\r
207 +    size_t i;\r
208 +\r
209 +    for (i = 0; i < state->new_ignore_length; i++)\r
210 +       if (strcmp (entry, state->new_ignore[i]) == 0)\r
211 +           return TRUE;\r
212 +\r
213 +    return FALSE;\r
214 +}\r
215 +\r
216  /* Examine 'path' recursively as follows:\r
217   *\r
218   *   o Ask the filesystem for the mtime of 'path' (fs_mtime)\r
219 @@ -320,15 +336,15 @@ add_files_recursive (notmuch_database_t *notmuch,\r
220         }\r
221  \r
222         /* Ignore special directories to avoid infinite recursion.\r
223 -        * Also ignore the .notmuch directory and any "tmp" directory\r
224 -        * that appears within a maildir.\r
225 +        * Also ignore the .notmuch directory, any "tmp" directory\r
226 +        * that appears within a maildir and files/directories\r
227 +        * the user has configured to be ignored.\r
228          */\r
229 -       /* XXX: Eventually we'll want more sophistication to let the\r
230 -        * user specify files to be ignored. */\r
231         if (strcmp (entry->d_name, ".") == 0 ||\r
232             strcmp (entry->d_name, "..") == 0 ||\r
233             (is_maildir && strcmp (entry->d_name, "tmp") == 0) ||\r
234 -           strcmp (entry->d_name, ".notmuch") ==0)\r
235 +           strcmp (entry->d_name, ".notmuch") == 0 ||\r
236 +           _entry_in_ignore_list (entry->d_name, state))\r
237         {\r
238             continue;\r
239         }\r
240 @@ -369,6 +385,10 @@ add_files_recursive (notmuch_database_t *notmuch,\r
241  \r
242          entry = fs_entries[i];\r
243  \r
244 +       /* Ignore files & directories user has configured to be ignored */\r
245 +       if (_entry_in_ignore_list (entry->d_name, state))\r
246 +           continue;\r
247 +\r
248         /* Check if we've walked past any names in db_files or\r
249          * db_subdirs. If so, these have been deleted. */\r
250         while (notmuch_filenames_valid (db_files) &&\r
251 @@ -648,7 +668,7 @@ add_files (notmuch_database_t *notmuch,\r
252   * initialized to zero by the top-level caller before calling\r
253   * count_files). */\r
254  static void\r
255 -count_files (const char *path, int *count)\r
256 +count_files (const char *path, int *count, add_files_state_t *state)\r
257  {\r
258      struct dirent *entry = NULL;\r
259      char *next;\r
260 @@ -670,13 +690,13 @@ count_files (const char *path, int *count)\r
261          entry = fs_entries[i++];\r
262  \r
263         /* Ignore special directories to avoid infinite recursion.\r
264 -        * Also ignore the .notmuch directory.\r
265 +        * Also ignore the .notmuch directory and files/directories\r
266 +        * the user has configured to be ignored.\r
267          */\r
268 -       /* XXX: Eventually we'll want more sophistication to let the\r
269 -        * user specify files to be ignored. */\r
270         if (strcmp (entry->d_name, ".") == 0 ||\r
271             strcmp (entry->d_name, "..") == 0 ||\r
272 -           strcmp (entry->d_name, ".notmuch") == 0)\r
273 +           strcmp (entry->d_name, ".notmuch") == 0 ||\r
274 +           _entry_in_ignore_list (entry->d_name, state))\r
275         {\r
276             continue;\r
277         }\r
278 @@ -697,7 +717,7 @@ count_files (const char *path, int *count)\r
279                 fflush (stdout);\r
280             }\r
281         } else if (S_ISDIR (st.st_mode)) {\r
282 -           count_files (next, count);\r
283 +           count_files (next, count, state);\r
284         }\r
285  \r
286         free (next);\r
287 @@ -837,6 +857,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
288         return 1;\r
289  \r
290      add_files_state.new_tags = notmuch_config_get_new_tags (config, &add_files_state.new_tags_length);\r
291 +    add_files_state.new_ignore = notmuch_config_get_new_ignore (config, &add_files_state.new_ignore_length);\r
292      add_files_state.synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);\r
293      db_path = notmuch_config_get_database_path (config);\r
294  \r
295 @@ -852,7 +873,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
296         int count;\r
297  \r
298         count = 0;\r
299 -       count_files (db_path, &count);\r
300 +       count_files (db_path, &count, &add_files_state);\r
301         if (interrupted)\r
302             return 1;\r
303  \r
304 diff --git a/test/new b/test/new\r
305 index 740ba05..b616dec 100755\r
306 --- a/test/new\r
307 +++ b/test/new\r
308 @@ -166,7 +166,6 @@ Note: Ignoring non-mail file: ${MAIL_DIR}/ignored_file\r
309  Added 1 new message to the database."\r
310  \r
311  test_begin_subtest "Ignore files and directories specified in new.ignore"\r
312 -test_subtest_known_broken\r
313  generate_message\r
314  notmuch config set new.ignore .git ignored_file .ignored_hidden_file\r
315  mkdir -p "${MAIL_DIR}"/.git && touch "${MAIL_DIR}"/.git/config\r
316 -- \r
317 1.7.8.2\r
318 \r