Re: [PATCH 9/9] add has: query prefix to search for specific properties
[notmuch-archives.git] / d3 / 4ca7033f729b1dee659e790f4f5ac1b032af5b
1 Return-Path: <eg@gaute.vetsj.com>\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 06615431FBC\r
6         for <notmuch@notmuchmail.org>; Sun,  6 Apr 2014 09:12:55 -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: -0.7\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 Z1fBRpAvTIbu for <notmuch@notmuchmail.org>;\r
16         Sun,  6 Apr 2014 09:12:47 -0700 (PDT)\r
17 Received: from mail-we0-f171.google.com (mail-we0-f171.google.com\r
18         [74.125.82.171]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id D7A18431FB6\r
21         for <notmuch@notmuchmail.org>; Sun,  6 Apr 2014 09:12:46 -0700 (PDT)\r
22 Received: by mail-we0-f171.google.com with SMTP id t61so5674112wes.16\r
23         for <notmuch@notmuchmail.org>; Sun, 06 Apr 2014 09:12:44 -0700 (PDT)\r
24 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
25         d=1e100.net; s=20130820;\r
26         h=x-gm-message-state:from:to:cc:subject:date:message-id;\r
27         bh=xnlWSPwhR6JuK24gvecKiujzIIJJTGKqVWuvlipNrTs=;\r
28         b=BWCRKj7zlVxRuZv24KkyFYKLFkkzLlynPhJ4E1TCn5+xGP1+gbk4tHo1f7khGbDTe2\r
29         sG82IYt1bQYf1ILgSLSRWaLEdf1X54bo2rjs+xC1LvbmlWyqbi0K6gDoPiwrXCm6O+eK\r
30         CgjOxEWuabBoOpCpCTZeTA05MafQ1zaOhZP6SgBbK2lzWtXxwOT20pwdnAnDt5cCywn5\r
31         7M2fWeAvBLgPsVAirSEwy7NSIat1fALWq4lpiEoUESXcWo+YOjxLeYRBGxQbNKzx0dLP\r
32         5kWqLUR66ZfCp9n2kee6r7c/I+27i+U8bVP1412tyVESBVwMaQZaZUuszi2Ifuo1BhZH\r
33         vJ1g==\r
34 X-Gm-Message-State:\r
35  ALoCoQk8QRRKz3SqUix/D50k1MZQ2lnvwQckV84OmQy2mmklENBMzDJrB8kUSOTrAx2KK2gtPD3T\r
36 X-Received: by 10.194.48.80 with SMTP id j16mr36104947wjn.44.1396800764024;\r
37         Sun, 06 Apr 2014 09:12:44 -0700 (PDT)\r
38 Received: from localhost ([188.113.84.221])\r
39         by mx.google.com with ESMTPSA id n41sm35458956eeg.4.2014.04.06.09.12.42\r
40         for <multiple recipients>\r
41         (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
42         Sun, 06 Apr 2014 09:12:43 -0700 (PDT)\r
43 From: Gaute Hope <eg@gaute.vetsj.com>\r
44 To: notmuch@notmuchmail.org\r
45 Subject: [PATCH] Add configurable changed tag to messages that have been\r
46         changed on disk\r
47 Date: Sun,  6 Apr 2014 18:11:23 +0200\r
48 Message-Id: <1396800683-9164-1-git-send-email-eg@gaute.vetsj.com>\r
49 X-Mailer: git-send-email 1.9.1\r
50 X-BeenThere: notmuch@notmuchmail.org\r
51 X-Mailman-Version: 2.1.13\r
52 Precedence: list\r
53 List-Id: "Use and development of the notmuch mail system."\r
54         <notmuch.notmuchmail.org>\r
55 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
56         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
57 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
58 List-Post: <mailto:notmuch@notmuchmail.org>\r
59 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
60 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
61         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
62 X-List-Received-Date: Sun, 06 Apr 2014 16:12:55 -0000\r
63 \r
64 When one of the source files for a message is changed on disk, renamed,\r
65 deleted or a new source file is added. A configurable changed tag is\r
66 is added. The tag can be configured under the option 'changed_tags' in\r
67 the [new] section, the default is none. Tests have been updated to\r
68 accept the new config option.\r
69 \r
70 notmuch-setup now asks for a changed tag after the new tags question.\r
71 \r
72 This could be useful for for example 'afew' to detect remote changes in\r
73 IMAP folders and update the FolderNameFilter to also add tags or remove\r
74 tags when a _existing_ message has been added to or removed from a\r
75 maildir.\r
76 ---\r
77  notmuch-client.h    |  8 ++++++++\r
78  notmuch-config.c    | 42 ++++++++++++++++++++++++++++++++++++++----\r
79  notmuch-new.c       | 34 +++++++++++++++++++++++++++++-----\r
80  notmuch-setup.c     | 17 +++++++++++++++++\r
81  test/T030-config.sh |  1 +\r
82  test/T040-setup.sh  |  2 ++\r
83  6 files changed, 95 insertions(+), 9 deletions(-)\r
84 \r
85 diff --git a/notmuch-client.h b/notmuch-client.h\r
86 index d110648..8b60645 100644\r
87 --- a/notmuch-client.h\r
88 +++ b/notmuch-client.h\r
89 @@ -314,6 +314,14 @@ notmuch_config_set_new_ignore (notmuch_config_t *config,\r
90                                const char *new_ignore[],\r
91                                size_t length);\r
92  \r
93 +const char **\r
94 +notmuch_config_get_changed_tags (notmuch_config_t *config,\r
95 +                            size_t *length);\r
96 +void\r
97 +notmuch_config_set_changed_tags (notmuch_config_t *config,\r
98 +                            const char *changed_tags[],\r
99 +                            size_t length);\r
100 +\r
101  notmuch_bool_t\r
102  notmuch_config_get_maildir_synchronize_flags (notmuch_config_t *config);\r
103  \r
104 diff --git a/notmuch-config.c b/notmuch-config.c\r
105 index 8d28653..5ea0635 100644\r
106 --- a/notmuch-config.c\r
107 +++ b/notmuch-config.c\r
108 @@ -51,7 +51,11 @@ static const char new_config_comment[] =\r
109      "\n"\r
110      "\t        NOTE: *Every* file/directory that goes by one of those\n"\r
111      "\t        names will be ignored, independent of its depth/location\n"\r
112 -    "\t        in the mail store.\n";\r
113 +    "\t        in the mail store.\n"\r
114 +    "\n"\r
115 +    "\tchanged_tags A list (separated by ';') of tags that will be\n"\r
116 +    "\t added to messages where a one or more of its source files have\n"\r
117 +    "\t have been changed (added, renamed or deleted).\n";\r
118  \r
119  static const char user_config_comment[] =\r
120      " User configuration\n"\r
121 @@ -111,10 +115,15 @@ struct _notmuch_config {\r
122      char *user_primary_email;\r
123      const char **user_other_email;\r
124      size_t user_other_email_length;\r
125 +\r
126      const char **new_tags;\r
127      size_t new_tags_length;\r
128      const char **new_ignore;\r
129      size_t new_ignore_length;\r
130 +\r
131 +    const char **changed_tags;\r
132 +    size_t changed_tags_length;\r
133 +\r
134      notmuch_bool_t maildir_synchronize_flags;\r
135      const char **search_exclude_tags;\r
136      size_t search_exclude_tags_length;\r
137 @@ -249,7 +258,7 @@ notmuch_config_open (void *ctx,\r
138         fprintf (stderr, "Out of memory.\n");\r
139         return NULL;\r
140      }\r
141 -    \r
142 +\r
143      talloc_set_destructor (config, notmuch_config_destructor);\r
144  \r
145      if (filename) {\r
146 @@ -273,6 +282,8 @@ notmuch_config_open (void *ctx,\r
147      config->new_tags_length = 0;\r
148      config->new_ignore = NULL;\r
149      config->new_ignore_length = 0;\r
150 +    config->changed_tags = NULL;\r
151 +    config->changed_tags_length = 0;\r
152      config->maildir_synchronize_flags = TRUE;\r
153      config->search_exclude_tags = NULL;\r
154      config->search_exclude_tags_length = 0;\r
155 @@ -373,6 +384,10 @@ notmuch_config_open (void *ctx,\r
156         notmuch_config_set_new_ignore (config, NULL, 0);\r
157      }\r
158  \r
159 +    if (notmuch_config_get_changed_tags (config, &tmp) == NULL) {\r
160 +      notmuch_config_set_changed_tags (config, NULL, 0);\r
161 +    }\r
162 +\r
163      if (notmuch_config_get_search_exclude_tags (config, &tmp) == NULL) {\r
164         if (config->is_new) {\r
165             const char *tags[] = { "deleted", "spam" };\r
166 @@ -422,7 +437,7 @@ notmuch_config_open (void *ctx,\r
167  }\r
168  \r
169  /* Close the given notmuch_config_t object, freeing all resources.\r
170 - * \r
171 + *\r
172   * Note: Any changes made to the configuration are *not* saved by this\r
173   * function. To save changes, call notmuch_config_save before\r
174   * notmuch_config_close.\r
175 @@ -631,6 +646,14 @@ notmuch_config_get_new_ignore (notmuch_config_t *config, size_t *length)\r
176                              &(config->new_ignore_length), length);\r
177  }\r
178  \r
179 +const char **\r
180 +notmuch_config_get_changed_tags (notmuch_config_t *config,   size_t *length)\r
181 +{\r
182 +    return _config_get_list (config, "new", "changed_tags",\r
183 +                            &(config->changed_tags),\r
184 +                            &(config->changed_tags_length), length);\r
185 +}\r
186 +\r
187  void\r
188  notmuch_config_set_user_other_email (notmuch_config_t *config,\r
189                                      const char *list[],\r
190 @@ -658,6 +681,15 @@ notmuch_config_set_new_ignore (notmuch_config_t *config,\r
191                      &(config->new_ignore));\r
192  }\r
193  \r
194 +void\r
195 +notmuch_config_set_changed_tags (notmuch_config_t *config,\r
196 +                                    const char *list[],\r
197 +                                    size_t length)\r
198 +{\r
199 +    _config_set_list (config, "new", "changed_tags", list, length,\r
200 +                    &(config->changed_tags));\r
201 +}\r
202 +\r
203  const char **\r
204  notmuch_config_get_search_exclude_tags (notmuch_config_t *config, size_t *length)\r
205  {\r
206 @@ -714,17 +746,19 @@ notmuch_config_command_get (notmuch_config_t *config, char *item)\r
207      } else if (strcmp(item, "user.other_email") == 0) {\r
208         const char **other_email;\r
209         size_t i, length;\r
210 -       \r
211 +\r
212         other_email = notmuch_config_get_user_other_email (config, &length);\r
213         for (i = 0; i < length; i++)\r
214             printf ("%s\n", other_email[i]);\r
215      } else if (strcmp(item, "new.tags") == 0) {\r
216 +\r
217         const char **tags;\r
218         size_t i, length;\r
219  \r
220         tags = notmuch_config_get_new_tags (config, &length);\r
221         for (i = 0; i < length; i++)\r
222             printf ("%s\n", tags[i]);\r
223 +\r
224      } else {\r
225         char **value;\r
226         size_t i, length;\r
227 diff --git a/notmuch-new.c b/notmuch-new.c\r
228 index 82acf69..db52961 100644\r
229 --- a/notmuch-new.c\r
230 +++ b/notmuch-new.c\r
231 @@ -50,6 +50,9 @@ typedef struct {\r
232      const char **new_ignore;\r
233      size_t new_ignore_length;\r
234  \r
235 +    const char **changed_tags;\r
236 +    size_t changed_tags_length;\r
237 +\r
238      int total_files;\r
239      int processed_files;\r
240      int added_messages, removed_messages, renamed_messages;\r
241 @@ -274,8 +277,12 @@ add_file (notmuch_database_t *notmuch, const char *filename,\r
242         break;\r
243      /* Non-fatal issues (go on to next file). */\r
244      case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:\r
245 +       notmuch_message_freeze (message);\r
246 +       for (tag = state->changed_tags; *tag != NULL; tag++)\r
247 +           notmuch_message_add_tag (message, *tag);\r
248         if (state->synchronize_flags)\r
249             notmuch_message_maildir_flags_to_tags (message);\r
250 +       notmuch_message_thaw (message);\r
251         break;\r
252      case NOTMUCH_STATUS_FILE_NOT_EMAIL:\r
253         fprintf (stderr, "Note: Ignoring non-mail file: %s\n", filename);\r
254 @@ -809,13 +816,25 @@ remove_filename (notmuch_database_t *notmuch,\r
255  \r
256      status = notmuch_database_remove_message (notmuch, path);\r
257      if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID) {\r
258 -       add_files_state->renamed_messages++;\r
259 -       if (add_files_state->synchronize_flags == TRUE)\r
260 -           notmuch_message_maildir_flags_to_tags (message);\r
261 -       status = NOTMUCH_STATUS_SUCCESS;\r
262 +\r
263 +    add_files_state->renamed_messages++;\r
264 +\r
265 +    /* add changed tags */\r
266 +    const char **tag;\r
267 +    for (tag = add_files_state->changed_tags; *tag != NULL; tag++)\r
268 +        notmuch_message_add_tag (message, *tag);\r
269 +\r
270 +    if (add_files_state->synchronize_flags == TRUE)\r
271 +        notmuch_message_maildir_flags_to_tags (message);\r
272 +\r
273 +    status = NOTMUCH_STATUS_SUCCESS;\r
274 +\r
275      } else if (status == NOTMUCH_STATUS_SUCCESS) {\r
276 -       add_files_state->removed_messages++;\r
277 +\r
278 +      add_files_state->removed_messages++;\r
279 +\r
280      }\r
281 +\r
282      notmuch_message_destroy (message);\r
283  \r
284    DONE:\r
285 @@ -946,8 +965,13 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])\r
286      else if (verbose)\r
287         add_files_state.verbosity = VERBOSITY_VERBOSE;\r
288  \r
289 +    /* tags for added files */\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 +\r
293 +    /* tags for changed files */\r
294 +    add_files_state.changed_tags = notmuch_config_get_changed_tags (config, &add_files_state.changed_tags_length);\r
295 +\r
296      add_files_state.synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);\r
297      db_path = notmuch_config_get_database_path (config);\r
298  \r
299 diff --git a/notmuch-setup.c b/notmuch-setup.c\r
300 index 36a6171..cf99ee0 100644\r
301 --- a/notmuch-setup.c\r
302 +++ b/notmuch-setup.c\r
303 @@ -131,6 +131,8 @@ notmuch_setup_command (notmuch_config_t *config,\r
304      unsigned int i;\r
305      const char **new_tags;\r
306      size_t new_tags_len;\r
307 +    const char **changed_tags;\r
308 +    size_t changed_tags_len;\r
309      const char **search_exclude_tags;\r
310      size_t search_exclude_tags_len;\r
311  \r
312 @@ -206,6 +208,21 @@ notmuch_setup_command (notmuch_config_t *config,\r
313         g_ptr_array_free (tags, TRUE);\r
314      }\r
315  \r
316 +    changed_tags = notmuch_config_get_changed_tags (config, &changed_tags_len);\r
317 +\r
318 +    printf ("Tags to apply to all changed messages (separated by spaces) [");\r
319 +    print_tag_list (changed_tags, changed_tags_len);\r
320 +    prompt ("]: ");\r
321 +\r
322 +    if (strlen (response)) {\r
323 +       GPtrArray *tags = parse_tag_list (config, response);\r
324 +\r
325 +       notmuch_config_set_changed_tags (config, (const char **) tags->pdata,\r
326 +                                    tags->len);\r
327 +\r
328 +       g_ptr_array_free (tags, TRUE);\r
329 +    }\r
330 +\r
331  \r
332      search_exclude_tags = notmuch_config_get_search_exclude_tags (config, &search_exclude_tags_len);\r
333  \r
334 diff --git a/test/T030-config.sh b/test/T030-config.sh\r
335 index ca4cf33..d1e095b 100755\r
336 --- a/test/T030-config.sh\r
337 +++ b/test/T030-config.sh\r
338 @@ -52,6 +52,7 @@ user.primary_email=test_suite@notmuchmail.org\r
339  user.other_email=test_suite_other@notmuchmail.org;test_suite@otherdomain.org\r
340  new.tags=unread;inbox;\r
341  new.ignore=\r
342 +new.changed_tags=\r
343  search.exclude_tags=\r
344  maildir.synchronize_flags=true\r
345  foo.string=this is another string value\r
346 diff --git a/test/T040-setup.sh b/test/T040-setup.sh\r
347 index 124ef1c..7e37ea1 100755\r
348 --- a/test/T040-setup.sh\r
349 +++ b/test/T040-setup.sh\r
350 @@ -11,6 +11,7 @@ another.suite@example.com\r
351  \r
352  /path/to/maildir\r
353  foo bar\r
354 +chaz\r
355  baz\r
356  EOF\r
357  output=$(notmuch --config=new-notmuch-config config list)\r
358 @@ -21,6 +22,7 @@ user.primary_email=test.suite@example.com\r
359  user.other_email=another.suite@example.com;\r
360  new.tags=foo;bar;\r
361  new.ignore=\r
362 +new.changed_tags=chaz;\r
363  search.exclude_tags=baz;\r
364  maildir.synchronize_flags=true"\r
365  \r
366 -- \r
367 1.9.1\r
368 \r