Re: Error with contrib/notmuch-pick
[notmuch-archives.git] / 9b / e8a1510ae3a33e0a2d062f58dd9402ab084219
1 Return-Path: <lrilling@gmail.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 1C224431FD0\r
6         for <notmuch@notmuchmail.org>; Thu, 23 Jun 2011 08:37:25 -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.699\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.699 tagged_above=-999 required=5\r
12         tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FREEMAIL_FROM=0.001,\r
13         RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
14 Received: from olra.theworths.org ([127.0.0.1])\r
15         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
16         with ESMTP id 78MAjsbCvvoy for <notmuch@notmuchmail.org>;\r
17         Thu, 23 Jun 2011 08:37:23 -0700 (PDT)\r
18 Received: from mail-fx0-f53.google.com (mail-fx0-f53.google.com\r
19         [209.85.161.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id 4B0B5431FB6\r
22         for <notmuch@notmuchmail.org>; Thu, 23 Jun 2011 08:37:23 -0700 (PDT)\r
23 Received: by fxm8 with SMTP id 8so1484027fxm.26\r
24         for <notmuch@notmuchmail.org>; Thu, 23 Jun 2011 08:37:22 -0700 (PDT)\r
25 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;\r
26         h=domainkey-signature:sender:from:to:cc:subject:date:message-id\r
27         :x-mailer; bh=eMh2YnbNM6yeFEniYwoEgO4LejWIO+5cpUDBvFh4BO4=;\r
28         b=HejZiBach1msEKYeuv2yGYej4EAJKIadVNPMy29zuXejrIgL+zjf2n34Xb3ngVymhk\r
29         IeUXdP9Qp2pV8Pf1v8sF8bpy5346BUsgRpRbyrZV59az6wtouedTArqqJBJQiMzalCI3\r
30         14AR0S6zL0UxX2R35Fg+Spw1yn3/eI1ktFERQ=\r
31 DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma;\r
32         h=sender:from:to:cc:subject:date:message-id:x-mailer;\r
33         b=tT1Jhi1aFknLiU8JuYIBQzHEssBEXuLjTJ4oaI1jBGY0vrVB528tWHYkx3RJ+t3yc3\r
34         kmT7PeCyhNak9snToPqNy0m8fsZxGzeCjHMTHBcjSHp+AjSnbycwzolYe3Ug50+Wrwgf\r
35         SYOYdyaOZ1oX8T6SO7x4xbDmlRCBNs0M5WyFQ=\r
36 Received: by 10.223.60.7 with SMTP id n7mr2890621fah.51.1308843441873;\r
37         Thu, 23 Jun 2011 08:37:21 -0700 (PDT)\r
38 Received: from osdor.le-roi-du-couscous.fr ([78.222.14.116])\r
39         by mx.google.com with ESMTPS id w15sm1058499faj.47.2011.06.23.08.37.21\r
40         (version=SSLv3 cipher=OTHER); Thu, 23 Jun 2011 08:37:21 -0700 (PDT)\r
41 Sender: Louis Rilling <lrilling@gmail.com>\r
42 From: Louis Rilling <l.rilling@av7.net>\r
43 To: notmuch@notmuchmail.org\r
44 Subject: [RFC][PATCH] tags_to_maildir_flags: Add option to not move messages\r
45         from "new/" to "cur/"\r
46 Date: Thu, 23 Jun 2011 17:36:06 +0200\r
47 Message-Id: <1308843366-6159-1-git-send-email-l.rilling@av7.net>\r
48 X-Mailer: git-send-email 1.7.2.5\r
49 X-BeenThere: notmuch@notmuchmail.org\r
50 X-Mailman-Version: 2.1.13\r
51 Precedence: list\r
52 List-Id: "Use and development of the notmuch mail system."\r
53         <notmuch.notmuchmail.org>\r
54 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
55         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
56 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
57 List-Post: <mailto:notmuch@notmuchmail.org>\r
58 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
59 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
60         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
61 X-List-Received-Date: Thu, 23 Jun 2011 15:37:25 -0000\r
62 \r
63 notmuch_message_tags_to_maildir_flags() moves messages from maildir directory\r
64 "new/" to maildir directory "cur/", which makes messages lose their "new" status\r
65 in the MUA. However some users want to keep this "new" status after, for\r
66 instance, an auto-tagging of new messages.\r
67 \r
68 This patch introduces notmuch_message_tags_to_maildir_flags_preserve(), which\r
69 does the same job as notmuch_message_tags_to_maildir_flags() except moving\r
70 from "maildir "new/" to maildir "cur/". A new option "preserve_new" is\r
71 introduced in "[maildir]" section of .notmuch-config, so that users can\r
72 configure whether commands "notmuch tag" and "notmuch restore" preserve the\r
73 "new" status or not.\r
74 \r
75 Signed-off-by: Louis Rilling <l.rilling@av7.net>\r
76 ---\r
77 Hi,\r
78 \r
79 I'm in the process of using notmuch, but the issue "addressed" by this patch\r
80 would make me change my habits a bit too fast. I use the "new" status for\r
81 quickly checking (often without reading) which emails I just received,\r
82 implementing some kind of context/mood/daytime-dependent quick filtering. I'd\r
83 also like to run a pre-tagging script automatically when synchronizing\r
84 periodically (and automatically too) my mailboxes. But the current behavior of\r
85 "notmuch tag" makes me lose my quick filtering ability.\r
86 \r
87 This patch is mostly written for discussion. It is certainly not polished (API,\r
88 ABI, bindings) and not tested at all. In particular, I know that there are some\r
89 plans to customize flags synchronization, but I don't know how the library API\r
90 could/should be impacted.\r
91 \r
92 Thanks for your comments!\r
93 \r
94 Louis\r
95 \r
96 \r
97  lib/message.cc    |   33 +++++++++++++++++++++++++--------\r
98  lib/notmuch.h     |    7 +++++++\r
99  notmuch-client.h  |    7 +++++++\r
100  notmuch-config.c  |   35 ++++++++++++++++++++++++++++++++++-\r
101  notmuch-restore.c |   10 ++++++++--\r
102  notmuch-tag.c     |   10 ++++++++--\r
103  6 files changed, 89 insertions(+), 13 deletions(-)\r
104 \r
105 diff --git a/lib/message.cc b/lib/message.cc\r
106 index 4b59fa9..c6c4160 100644\r
107 --- a/lib/message.cc\r
108 +++ b/lib/message.cc\r
109 @@ -1130,7 +1130,8 @@ static char*\r
110  _new_maildir_filename (void *ctx,\r
111                        const char *filename,\r
112                        const char *flags_to_set,\r
113 -                      const char *flags_to_clear)\r
114 +                      const char *flags_to_clear,\r
115 +                      bool preserve_new)\r
116  {\r
117      const char *info, *flags;\r
118      unsigned int flag, last_flag;\r
119 @@ -1211,16 +1212,19 @@ _new_maildir_filename (void *ctx,\r
120      }\r
121      *s = '\0';\r
122  \r
123 -    /* If message is in new/ move it under cur/. */\r
124 -    dir = (char *) _filename_is_in_maildir (filename_new);\r
125 -    if (dir && STRNCMP_LITERAL (dir, "new/") == 0)\r
126 -       memcpy (dir, "cur/", 4);\r
127 +    if (!preserve_new) {\r
128 +       /* If message is in new/ move it under cur/. */\r
129 +       dir = (char *) _filename_is_in_maildir (filename_new);\r
130 +       if (dir && STRNCMP_LITERAL (dir, "new/") == 0)\r
131 +           memcpy (dir, "cur/", 4);\r
132 +    }\r
133  \r
134      return filename_new;\r
135  }\r
136  \r
137 -notmuch_status_t\r
138 -notmuch_message_tags_to_maildir_flags (notmuch_message_t *message)\r
139 +static notmuch_status_t\r
140 +_notmuch_message_tags_to_maildir_flags (notmuch_message_t *message,\r
141 +                                       bool preserve_new)\r
142  {\r
143      notmuch_filenames_t *filenames;\r
144      const char *filename;\r
145 @@ -1240,7 +1244,8 @@ notmuch_message_tags_to_maildir_flags (notmuch_message_t *message)\r
146             continue;\r
147  \r
148         filename_new = _new_maildir_filename (message, filename,\r
149 -                                             to_set, to_clear);\r
150 +                                             to_set, to_clear,\r
151 +                                             preserve_new);\r
152         if (filename_new == NULL)\r
153             continue;\r
154  \r
155 @@ -1281,6 +1286,18 @@ notmuch_message_tags_to_maildir_flags (notmuch_message_t *message)\r
156  }\r
157  \r
158  notmuch_status_t\r
159 +notmuch_message_tags_to_maildir_flags (notmuch_message_t *message)\r
160 +{\r
161 +    _notmuch_message_tags_to_maildir_flags(message, false);\r
162 +}\r
163 +\r
164 +notmuch_status_t\r
165 +notmuch_message_tags_to_maildir_flags_preserve (notmuch_message_t *message)\r
166 +{\r
167 +    _notmuch_message_tags_to_maildir_flags(message, true);\r
168 +}\r
169 +\r
170 +notmuch_status_t\r
171  notmuch_message_remove_all_tags (notmuch_message_t *message)\r
172  {\r
173      notmuch_private_status_t private_status;\r
174 diff --git a/lib/notmuch.h b/lib/notmuch.h\r
175 index e508309..eeddc17 100644\r
176 --- a/lib/notmuch.h\r
177 +++ b/lib/notmuch.h\r
178 @@ -978,6 +978,13 @@ notmuch_message_maildir_flags_to_tags (notmuch_message_t *message);\r
179   */\r
180  notmuch_status_t\r
181  notmuch_message_tags_to_maildir_flags (notmuch_message_t *message);\r
182 +/* Rename message filename(s) to encode tags as maildir flags, without moving from new/ to cur/\r
183 + *\r
184 + * Same as notmuch_message_tags_to_maildir_flags, but messages living in\r
185 + * directory "new" are not moved to neighboring directory "cur".\r
186 + */\r
187 +notmuch_status_t\r
188 +notmuch_message_tags_to_maildir_flags_preserve (notmuch_message_t *message);\r
189  \r
190  /* Freeze the current state of 'message' within the database.\r
191   *\r
192 diff --git a/notmuch-client.h b/notmuch-client.h\r
193 index 63be337..2372fe6 100644\r
194 --- a/notmuch-client.h\r
195 +++ b/notmuch-client.h\r
196 @@ -235,6 +235,13 @@ notmuch_config_set_maildir_synchronize_flags (notmuch_config_t *config,\r
197                                               notmuch_bool_t synchronize_flags);\r
198  \r
199  notmuch_bool_t\r
200 +notmuch_config_get_maildir_preserve_new (notmuch_config_t *config);\r
201 +\r
202 +void\r
203 +notmuch_config_set_maildir_preserve_new (notmuch_config_t *config,\r
204 +                                        notmuch_bool_t preserve_new);\r
205 +\r
206 +notmuch_bool_t\r
207  debugger_is_active (void);\r
208  \r
209  #endif\r
210 diff --git a/notmuch-config.c b/notmuch-config.c\r
211 index 6e4c5c4..5ef5f44 100644\r
212 --- a/notmuch-config.c\r
213 +++ b/notmuch-config.c\r
214 @@ -81,7 +81,14 @@ static const char maildir_config_comment[] =\r
215      "\n"\r
216      "\tThe \"notmuch new\" command will notice flag changes in filenames\n"\r
217      "\tand update tags, while the \"notmuch tag\" and \"notmuch restore\"\n"\r
218 -    "\tcommands will notice tag changes and update flags in filenames\n";\r
219 +    "\tcommands will notice tag changes and update flags in filenames\n"\r
220 +    "\n"\r
221 +    "\tpreserve_new           Valid values are true and false.\n"\r
222 +    "\n"\r
223 +    "\tThis setting has only effects if synchronize_flags is set to true.\n"\r
224 +    "\tIf true, the \"notmuch tag\" and \"notmuch restore\" commands will\n"\r
225 +    "\tpreserve the maildir \"new\" status of messages. If false, all updated\n"\r
226 +    "\tmessages lose their \"new\" status.\n";\r
227  \r
228  struct _notmuch_config {\r
229      char *filename;\r
230 @@ -95,6 +102,7 @@ struct _notmuch_config {\r
231      const char **new_tags;\r
232      size_t new_tags_length;\r
233      notmuch_bool_t maildir_synchronize_flags;\r
234 +    notmuch_bool_t maildir_preserve_new;\r
235  };\r
236  \r
237  static int\r
238 @@ -251,6 +259,7 @@ notmuch_config_open (void *ctx,\r
239      config->new_tags = NULL;\r
240      config->new_tags_length = 0;\r
241      config->maildir_synchronize_flags = TRUE;\r
242 +    config->maildir_preserve_new = FALSE;\r
243  \r
244      if (! g_key_file_load_from_file (config->key_file,\r
245                                      config->filename,\r
246 @@ -353,6 +362,15 @@ notmuch_config_open (void *ctx,\r
247         g_error_free (error);\r
248      }\r
249  \r
250 +    error = NULL;\r
251 +    config->maildir_preserve_new =\r
252 +       g_key_file_get_boolean (config->key_file,\r
253 +                               "maildir", "preserve_new", &error);\r
254 +    if (error) {\r
255 +       notmuch_config_set_maildir_preserve_new (config, FALSE);\r
256 +       g_error_free (error);\r
257 +    }\r
258 +\r
259      /* Whenever we know of configuration sections that don't appear in\r
260       * the configuration file, we add some comments to help the user\r
261       * understand what can be done. */\r
262 @@ -764,3 +782,18 @@ notmuch_config_set_maildir_synchronize_flags (notmuch_config_t *config,\r
263                             "maildir", "synchronize_flags", synchronize_flags);\r
264      config->maildir_synchronize_flags = synchronize_flags;\r
265  }\r
266 +\r
267 +notmuch_bool_t\r
268 +notmuch_config_get_maildir_preserve_new (notmuch_config_t *config)\r
269 +{\r
270 +    return config->maildir_preserve_new;\r
271 +}\r
272 +\r
273 +void\r
274 +notmuch_config_set_maildir_preserve_new (notmuch_config_t *config,\r
275 +                                        notmuch_bool_t preserve_new)\r
276 +{\r
277 +    g_key_file_set_boolean (config->key_file,\r
278 +                           "maildir", "preserve_new", preserve_new);\r
279 +    config->maildir_preserve_new = preserve_new;\r
280 +}\r
281 diff --git a/notmuch-restore.c b/notmuch-restore.c\r
282 index f095f64..620a1f2 100644\r
283 --- a/notmuch-restore.c\r
284 +++ b/notmuch-restore.c\r
285 @@ -26,6 +26,7 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])\r
286      notmuch_config_t *config;\r
287      notmuch_database_t *notmuch;\r
288      notmuch_bool_t synchronize_flags;\r
289 +    notmuch_bool_t preserve_new;\r
290      FILE *input;\r
291      char *line = NULL;\r
292      size_t line_size;\r
293 @@ -43,6 +44,7 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])\r
294         return 1;\r
295  \r
296      synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);\r
297 +    preserve_new = notmuch_config_get_maildir_preserve_new (config);\r
298  \r
299      if (argc) {\r
300         input = fopen (argv[0], "r");\r
301 @@ -134,8 +136,12 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])\r
302  \r
303         notmuch_message_thaw (message);\r
304  \r
305 -       if (synchronize_flags)\r
306 -           notmuch_message_tags_to_maildir_flags (message);\r
307 +       if (synchronize_flags) {\r
308 +           if (preserve_new)\r
309 +               notmuch_message_tags_to_maildir_flags_preserve (message);\r
310 +           else\r
311 +               notmuch_message_tags_to_maildir_flags (message);\r
312 +       }\r
313  \r
314        NEXT_LINE:\r
315         if (message)\r
316 diff --git a/notmuch-tag.c b/notmuch-tag.c\r
317 index 6204ae3..c36c3c9 100644\r
318 --- a/notmuch-tag.c\r
319 +++ b/notmuch-tag.c\r
320 @@ -44,6 +44,7 @@ notmuch_tag_command (void *ctx, unused (int argc), unused (char *argv[]))\r
321      notmuch_message_t *message;\r
322      struct sigaction action;\r
323      notmuch_bool_t synchronize_flags;\r
324 +    notmuch_bool_t preserve_new;\r
325      int i;\r
326  \r
327      /* Setup our handler for SIGINT */\r
328 @@ -101,6 +102,7 @@ notmuch_tag_command (void *ctx, unused (int argc), unused (char *argv[]))\r
329         return 1;\r
330  \r
331      synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);\r
332 +    preserve_new = notmuch_config_get_maildir_preserve_new (config);\r
333  \r
334      query = notmuch_query_create (notmuch, query_string);\r
335      if (query == NULL) {\r
336 @@ -128,8 +130,12 @@ notmuch_tag_command (void *ctx, unused (int argc), unused (char *argv[]))\r
337  \r
338         notmuch_message_thaw (message);\r
339  \r
340 -       if (synchronize_flags)\r
341 -           notmuch_message_tags_to_maildir_flags (message);\r
342 +       if (synchronize_flags) {\r
343 +           if (preserve_new)\r
344 +               notmuch_message_tags_to_maildir_flags_preserve (message);\r
345 +           else\r
346 +               notmuch_message_tags_to_maildir_flags (message);\r
347 +       }\r
348  \r
349         notmuch_message_destroy (message);\r
350      }\r
351 -- \r
352 1.7.2.5\r
353 \r