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