Re: [PATCH 3/5] nmbug-status: Add an nmbug-status(5) man page
[notmuch-archives.git] / 70 / f2d199474b4e46bbdce1d262759c9be3e52e13
1 Return-Path: <anarcat@angela.anarcat.ath.cx>\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 82CD2429E2A\r
6         for <notmuch@notmuchmail.org>; Sat, 16 Jul 2011 20:56:27 -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\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 3tMfZ-CsfKnU for <notmuch@notmuchmail.org>;\r
16         Sat, 16 Jul 2011 20:56:26 -0700 (PDT)\r
17 Received: from bureau.koumbit.net (homere.koumbit.net [209.44.112.81])\r
18         (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id 60CC9431FB6\r
21         for <notmuch@notmuchmail.org>; Sat, 16 Jul 2011 20:56:26 -0700 (PDT)\r
22 Received: from localhost (H144.C72.B0.tor.eicat.ca [72.0.72.144])\r
23         (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))\r
24         (No client certificate requested)\r
25         by bureau.koumbit.net (Postfix) with ESMTPSA id 6614CE80EF7;\r
26         Sat, 16 Jul 2011 23:56:25 -0400 (EDT)\r
27 Received: by localhost (Postfix, from userid 1000)\r
28         id AC3F36305; Sat, 16 Jul 2011 23:56:27 -0400 (EDT)\r
29 From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= <anarcat@koumbit.org>\r
30 To: notmuch@notmuchmail.org\r
31 Subject: [PATCH 2/2] lib: add 'safe' setting for flags\r
32 Date: Sat, 16 Jul 2011 23:56:13 -0400\r
33 Message-Id: <1310874973-28437-2-git-send-email-anarcat@koumbit.org>\r
34 X-Mailer: git-send-email 1.7.2.5\r
35 In-Reply-To: <1310874973-28437-1-git-send-email-anarcat@koumbit.org>\r
36 References: <1310874973-28437-1-git-send-email-anarcat@koumbit.org>\r
37 Cc: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= <anarcat@koumbit.org>\r
38 X-BeenThere: notmuch@notmuchmail.org\r
39 X-Mailman-Version: 2.1.13\r
40 Precedence: list\r
41 List-Id: "Use and development of the notmuch mail system."\r
42         <notmuch.notmuchmail.org>\r
43 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
44         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
45 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
46 List-Post: <mailto:notmuch@notmuchmail.org>\r
47 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
48 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
49         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
50 X-List-Received-Date: Sun, 17 Jul 2011 03:56:28 -0000\r
51 \r
52 the 'safe' setting needs to be 'true' for flags to be manipulated by\r
53 notmuch new/tag/restore.\r
54 \r
55 for now, only the (T)rash tag is configurable and set to false (by\r
56 default) but this could be extended to allow the user to configure which\r
57 flags are allowed to be synchronized.\r
58 \r
59 the reason why only T is configurable is because (a) it's the the only\r
60 one that is actually dangerous and (b) I couldn't figure out how to\r
61 properly configure multiple settings like this.\r
62 ---\r
63  lib/message.cc    |   40 +++++++++++++++++++++++++---------------\r
64  lib/notmuch.h     |   20 ++++++++++++++++----\r
65  notmuch-new.c     |    1 +\r
66  notmuch-restore.c |    1 +\r
67  notmuch-tag.c     |    1 +\r
68  5 files changed, 44 insertions(+), 19 deletions(-)\r
69 \r
70 diff --git a/lib/message.cc b/lib/message.cc\r
71 index f633887..f812648 100644\r
72 --- a/lib/message.cc\r
73 +++ b/lib/message.cc\r
74 @@ -50,16 +50,17 @@ struct maildir_flag_tag {\r
75      char flag;\r
76      const char *tag;\r
77      bool inverse;\r
78 +    bool safe;\r
79  };\r
80  \r
81  /* ASCII ordered table of Maildir flags and associated tags */\r
82  static struct maildir_flag_tag flag2tag[] = {\r
83 -    { 'D', "draft",   false},\r
84 -    { 'F', "flagged", false},\r
85 -    { 'P', "passed",  false},\r
86 -    { 'R', "replied", false},\r
87 -    { 'S', "unread",  true },\r
88 -    { 'T', "deleted", false},\r
89 +    { 'D', "draft",   false, true},\r
90 +    { 'F', "flagged", false, true},\r
91 +    { 'P', "passed",  false, true},\r
92 +    { 'R', "replied", false, true},\r
93 +    { 'S', "unread",  true , true},\r
94 +    { 'T', "deleted", false, false},\r
95  };\r
96  \r
97  /* We end up having to call the destructor explicitly because we had\r
98 @@ -994,7 +995,6 @@ notmuch_message_maildir_flags_to_tags (notmuch_message_t *message)\r
99      char *combined_flags = talloc_strdup (message, "");\r
100      unsigned i;\r
101      int seen_maildir_info = 0;\r
102 -    notmuch_bool_t reckless_trash;\r
103  \r
104      for (filenames = notmuch_message_get_filenames (message);\r
105          notmuch_filenames_valid (filenames);\r
106 @@ -1022,15 +1022,8 @@ notmuch_message_maildir_flags_to_tags (notmuch_message_t *message)\r
107      if (status)\r
108         return status;\r
109  \r
110 -    // TODO: this should probably be moved up in the stack to avoid\r
111 -    // opening the config file on every message (!)\r
112 -    config = notmuch_config_open (ctx, NULL, NULL);\r
113 -    if (config == NULL)\r
114 -       return 1;\r
115 -    reckless_trash = notmuch_config_get_maildir_reckless_trash (config);\r
116 -\r
117      for (i = 0; i < ARRAY_SIZE(flag2tag); i++) {\r
118 -       if (flag2tag[i].flag == 'T' && !reckless_trash) {\r
119 +       if (!flag2tag[i].safe) {\r
120             continue;\r
121         }\r
122         if ((strchr (combined_flags, flag2tag[i].flag) != NULL)\r
123 @@ -1119,6 +1112,9 @@ _get_maildir_flag_actions (notmuch_message_t *message,\r
124         tag = notmuch_tags_get (tags);\r
125  \r
126         for (i = 0; i < ARRAY_SIZE (flag2tag); i++) {\r
127 +           if (!flag2tag[i].safe) {\r
128 +               continue;\r
129 +           }\r
130             if (strcmp (tag, flag2tag[i].tag) == 0) {\r
131                 if (flag2tag[i].inverse)\r
132                     to_clear = talloc_asprintf_append (to_clear,\r
133 @@ -1134,6 +1130,9 @@ _get_maildir_flag_actions (notmuch_message_t *message,\r
134  \r
135      /* Then, find the flags for all tags not present. */\r
136      for (i = 0; i < ARRAY_SIZE (flag2tag); i++) {\r
137 +       if (!flag2tag[i].safe) {\r
138 +           continue;\r
139 +       }\r
140         if (flag2tag[i].inverse) {\r
141             if (strchr (to_clear, flag2tag[i].flag) == NULL)\r
142                 to_set = talloc_asprintf_append (to_set, "%c", flag2tag[i].flag);\r
143 @@ -1256,6 +1255,17 @@ _new_maildir_filename (void *ctx,\r
144      return filename_new;\r
145  }\r
146  \r
147 +void\r
148 +notmuch_message_set_flag_safety (char flag, notmuch_bool_t safe)\r
149 +{\r
150 +    unsigned i;\r
151 +    for (i = 0; i < ARRAY_SIZE (flag2tag); i++) {\r
152 +        if (flag2tag[i].flag == flag) {\r
153 +            flag2tag[i].safe = safe;\r
154 +        }\r
155 +    }\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 diff --git a/lib/notmuch.h b/lib/notmuch.h\r
162 index f0c1b67..475e75a 100644\r
163 --- a/lib/notmuch.h\r
164 +++ b/lib/notmuch.h\r
165 @@ -922,8 +922,7 @@ notmuch_message_remove_all_tags (notmuch_message_t *message);\r
166   *     'P'     Adds the "passed" tag to the message\r
167   *     'R'     Adds the "replied" tag to the message\r
168   *     'S'     Removes the "unread" tag from the message\r
169 - *     'T'     Adds the "deleted" tag to the message and\r
170 - *             state->reckless_trash is TRUE.\r
171 + *     'T'     Adds the "deleted" tag to the message\r
172   *\r
173   * For each flag that is not present, the opposite action (add/remove)\r
174   * is performed for the corresponding tags.\r
175 @@ -941,6 +940,9 @@ notmuch_message_remove_all_tags (notmuch_message_t *message);\r
176   * notmuch_database_add_message. See also\r
177   * notmuch_message_tags_to_maildir_flags for synchronizing tag changes\r
178   * back to maildir flags.\r
179 + *\r
180 + * Actions are performed only if the tag is marked as "safe" in the\r
181 + * configuration (only used by maildir_reckless_trash for now).\r
182   */\r
183  notmuch_status_t\r
184  notmuch_message_maildir_flags_to_tags (notmuch_message_t *message);\r
185 @@ -964,8 +966,7 @@ notmuch_message_maildir_flags_to_tags (notmuch_message_t *message);\r
186   *   'P' iff the message has the "passed" tag\r
187   *   'R' iff the message has the "replied" tag\r
188   *   'S' iff the message does not have the "unread" tag\r
189 - *   'T' iff the message has the "trashed" tag and\r
190 - *   state->reckless_trash is TRUE.\r
191 + *   'T' iff the message has the "trashed" tag\r
192   *\r
193   * Any existing flags unmentioned in the list above will be preserved\r
194   * in the renaming.\r
195 @@ -979,10 +980,21 @@ notmuch_message_maildir_flags_to_tags (notmuch_message_t *message);\r
196   * notmuch_message_remove_tag, or notmuch_message_freeze/\r
197   * notmuch_message_thaw). See also notmuch_message_maildir_flags_to_tags\r
198   * for synchronizing maildir flag changes back to tags.\r
199 + *\r
200 + * Actions are performed only if the tag is marked as "safe" in the\r
201 + * configuration (only used by maildir_reckless_trash for now).\r
202   */\r
203  notmuch_status_t\r
204  notmuch_message_tags_to_maildir_flags (notmuch_message_t *message);\r
205  \r
206 +/* Set the 'safe' setting on the given flag\r
207 + *\r
208 + * The flag is the one-character IMAP flag, for example for Trashed\r
209 + * messages, it's the char 'T'.\r
210 + */\r
211 +void\r
212 +notmuch_message_set_flag_safety(char flag, notmuch_bool_t safe);\r
213 +\r
214  /* Freeze the current state of 'message' within the database.\r
215   *\r
216   * This means that changes to the message state, (via\r
217 diff --git a/notmuch-new.c b/notmuch-new.c\r
218 index 7d17793..1502a70 100644\r
219 --- a/notmuch-new.c\r
220 +++ b/notmuch-new.c\r
221 @@ -801,6 +801,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
222  \r
223      add_files_state.new_tags = notmuch_config_get_new_tags (config, &add_files_state.new_tags_length);\r
224      add_files_state.synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);\r
225 +    notmuch_message_set_flag_safety('T', notmuch_config_get_maildir_reckless_trash (config));\r
226      add_files_state.message_ids_to_sync = _filename_list_create (ctx);\r
227      db_path = notmuch_config_get_database_path (config);\r
228  \r
229 diff --git a/notmuch-restore.c b/notmuch-restore.c\r
230 index f095f64..1f3622e 100644\r
231 --- a/notmuch-restore.c\r
232 +++ b/notmuch-restore.c\r
233 @@ -43,6 +43,7 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])\r
234         return 1;\r
235  \r
236      synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);\r
237 +    notmuch_message_set_flag_safety('T', notmuch_config_get_maildir_reckless_trash (config));\r
238  \r
239      if (argc) {\r
240         input = fopen (argv[0], "r");\r
241 diff --git a/notmuch-tag.c b/notmuch-tag.c\r
242 index 6204ae3..e2f7cb8 100644\r
243 --- a/notmuch-tag.c\r
244 +++ b/notmuch-tag.c\r
245 @@ -101,6 +101,7 @@ notmuch_tag_command (void *ctx, unused (int argc), unused (char *argv[]))\r
246         return 1;\r
247  \r
248      synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);\r
249 +    notmuch_message_set_flag_safety('T', notmuch_config_get_maildir_reckless_trash (config));\r
250  \r
251      query = notmuch_query_create (notmuch, query_string);\r
252      if (query == NULL) {\r
253 -- \r
254 1.7.2.5\r
255 \r