Re: notmuch-mutt: Use of uninitialized value.
[notmuch-archives.git] / b2 / 3850093b3bc90bc3f1ec58693c444b8be8916a
1 Return-Path: <jani@nikula.org>\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 8CD3C4077A1\r
6         for <notmuch@notmuchmail.org>; Fri,  6 Jan 2012 14:45:36 -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.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 F9XiM+zLXWeJ for <notmuch@notmuchmail.org>;\r
16         Fri,  6 Jan 2012 14:45:35 -0800 (PST)\r
17 Received: from mail-ee0-f53.google.com (mail-ee0-f53.google.com\r
18  [74.125.83.53])        (using TLSv1 with cipher RC4-SHA (128/128 bits))        (No client\r
19  certificate requested) by olra.theworths.org (Postfix) with ESMTPS id\r
20  3FA5B4077BE    for <notmuch@notmuchmail.org>; Fri,  6 Jan 2012 14:45:35 -0800\r
21  (PST)\r
22 Received: by eekd41 with SMTP id d41so1649522eek.26\r
23         for <notmuch@notmuchmail.org>; Fri, 06 Jan 2012 14:45:34 -0800 (PST)\r
24 Received: by 10.14.48.9 with SMTP id u9mr3036145eeb.37.1325889933950;\r
25         Fri, 06 Jan 2012 14:45:33 -0800 (PST)\r
26 Received: from localhost (dsl-hkibrasgw4-fe5cdc00-23.dhcp.inet.fi.\r
27         [80.220.92.23])\r
28         by mx.google.com with ESMTPS id t1sm253676256eeb.3.2012.01.06.14.45.31\r
29         (version=SSLv3 cipher=OTHER); Fri, 06 Jan 2012 14:45:32 -0800 (PST)\r
30 From: Jani Nikula <jani@nikula.org>\r
31 To: Antoine =?utf-8?Q?Beaupr=C3=A9?= <anarcat@koumbit.org>,\r
32         notmuch@notmuchmail.org\r
33 Subject: Re: [PATCH 2/2] lib: add 'safe' setting for flags\r
34 In-Reply-To: <1310874973-28437-2-git-send-email-anarcat@koumbit.org>\r
35 References: <1310874973-28437-1-git-send-email-anarcat@koumbit.org>\r
36         <1310874973-28437-2-git-send-email-anarcat@koumbit.org>\r
37 User-Agent: Notmuch/0.10.2+182~g93862a2 (http://notmuchmail.org) Emacs/23.3.1\r
38         (i686-pc-linux-gnu)\r
39 Date: Sat, 07 Jan 2012 00:45:30 +0200\r
40 Message-ID: <871urc8n79.fsf@nikula.org>\r
41 MIME-Version: 1.0\r
42 Content-Type: text/plain; charset=utf-8\r
43 Content-Transfer-Encoding: quoted-printable\r
44 Cc: Antoine =?utf-8?Q?Beaupr=C3=A9?= <anarcat@koumbit.org>\r
45 X-BeenThere: notmuch@notmuchmail.org\r
46 X-Mailman-Version: 2.1.13\r
47 Precedence: list\r
48 List-Id: "Use and development of the notmuch mail system."\r
49         <notmuch.notmuchmail.org>\r
50 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
51         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
52 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
53 List-Post: <mailto:notmuch@notmuchmail.org>\r
54 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
55 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
56         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
57 X-List-Received-Date: Fri, 06 Jan 2012 22:45:36 -0000\r
58 \r
59 On Sat, 16 Jul 2011 23:56:13 -0400, Antoine Beaupr=C3=A9 <anarcat@koumbit.o=\r
60 rg> wrote:\r
61 > the 'safe' setting needs to be 'true' for flags to be manipulated by\r
62 > notmuch new/tag/restore.\r
63 >=20\r
64 > for now, only the (T)rash tag is configurable and set to false (by\r
65 > default) but this could be extended to allow the user to configure which\r
66 > flags are allowed to be synchronized.\r
67 >=20\r
68 > the reason why only T is configurable is because (a) it's the the only\r
69 > one that is actually dangerous and (b) I couldn't figure out how to\r
70 > properly configure multiple settings like this.\r
71 > ---\r
72 >  lib/message.cc    |   40 +++++++++++++++++++++++++---------------\r
73 >  lib/notmuch.h     |   20 ++++++++++++++++----\r
74 >  notmuch-new.c     |    1 +\r
75 >  notmuch-restore.c |    1 +\r
76 >  notmuch-tag.c     |    1 +\r
77 >  5 files changed, 44 insertions(+), 19 deletions(-)\r
78 >=20\r
79 > diff --git a/lib/message.cc b/lib/message.cc\r
80 > index f633887..f812648 100644\r
81 > --- a/lib/message.cc\r
82 > +++ b/lib/message.cc\r
83 > @@ -50,16 +50,17 @@ struct maildir_flag_tag {\r
84 >      char flag;\r
85 >      const char *tag;\r
86 >      bool inverse;\r
87 > +    bool safe;\r
88 >  };\r
89 >=20=20\r
90 >  /* ASCII ordered table of Maildir flags and associated tags */\r
91 >  static struct maildir_flag_tag flag2tag[] =3D {\r
92 > -    { 'D', "draft",   false},\r
93 > -    { 'F', "flagged", false},\r
94 > -    { 'P', "passed",  false},\r
95 > -    { 'R', "replied", false},\r
96 > -    { 'S', "unread",  true },\r
97 > -    { 'T', "deleted", false},\r
98 > +    { 'D', "draft",   false, true},\r
99 > +    { 'F', "flagged", false, true},\r
100 > +    { 'P', "passed",  false, true},\r
101 > +    { 'R', "replied", false, true},\r
102 > +    { 'S', "unread",  true , true},\r
103 > +    { 'T', "deleted", false, false},\r
104 >  };\r
105 >=20=20\r
106 >  /* We end up having to call the destructor explicitly because we had\r
107 > @@ -994,7 +995,6 @@ notmuch_message_maildir_flags_to_tags (notmuch_messag=\r
108 e_t *message)\r
109 >      char *combined_flags =3D talloc_strdup (message, "");\r
110 >      unsigned i;\r
111 >      int seen_maildir_info =3D 0;\r
112 > -    notmuch_bool_t reckless_trash;\r
113 >=20=20\r
114 >      for (filenames =3D notmuch_message_get_filenames (message);\r
115 >        notmuch_filenames_valid (filenames);\r
116 > @@ -1022,15 +1022,8 @@ notmuch_message_maildir_flags_to_tags (notmuch_mes=\r
117 sage_t *message)\r
118 >      if (status)\r
119 >       return status;\r
120 >=20=20\r
121 > -    // TODO: this should probably be moved up in the stack to avoid\r
122 > -    // opening the config file on every message (!)\r
123 > -    config =3D notmuch_config_open (ctx, NULL, NULL);\r
124 > -    if (config =3D=3D NULL)\r
125 > -     return 1;\r
126 > -    reckless_trash =3D notmuch_config_get_maildir_reckless_trash (config=\r
127 );\r
128 > -\r
129 \r
130 Antoine -\r
131 \r
132 You do *not* send a patch 1/2 that adds features and then 2/2 that takes\r
133 them away. I feel like I totally wasted my time reviewing the first.\r
134 \r
135 \r
136 Jani.\r
137 \r
138 \r
139 \r
140 >      for (i =3D 0; i < ARRAY_SIZE(flag2tag); i++) {\r
141 > -     if (flag2tag[i].flag =3D=3D 'T' && !reckless_trash) {\r
142 > +     if (!flag2tag[i].safe) {\r
143 >           continue;\r
144 >       }\r
145 >       if ((strchr (combined_flags, flag2tag[i].flag) !=3D NULL)\r
146 > @@ -1119,6 +1112,9 @@ _get_maildir_flag_actions (notmuch_message_t *messa=\r
147 ge,\r
148 >       tag =3D notmuch_tags_get (tags);\r
149 >=20=20\r
150 >       for (i =3D 0; i < ARRAY_SIZE (flag2tag); i++) {\r
151 > +         if (!flag2tag[i].safe) {\r
152 > +             continue;\r
153 > +         }\r
154 >           if (strcmp (tag, flag2tag[i].tag) =3D=3D 0) {\r
155 >               if (flag2tag[i].inverse)\r
156 >                   to_clear =3D talloc_asprintf_append (to_clear,\r
157 > @@ -1134,6 +1130,9 @@ _get_maildir_flag_actions (notmuch_message_t *messa=\r
158 ge,\r
159 >=20=20\r
160 >      /* Then, find the flags for all tags not present. */\r
161 >      for (i =3D 0; i < ARRAY_SIZE (flag2tag); i++) {\r
162 > +     if (!flag2tag[i].safe) {\r
163 > +         continue;\r
164 > +     }\r
165 >       if (flag2tag[i].inverse) {\r
166 >           if (strchr (to_clear, flag2tag[i].flag) =3D=3D NULL)\r
167 >               to_set =3D talloc_asprintf_append (to_set, "%c", flag2tag[i].flag);\r
168 > @@ -1256,6 +1255,17 @@ _new_maildir_filename (void *ctx,\r
169 >      return filename_new;\r
170 >  }\r
171 >=20=20\r
172 > +void\r
173 > +notmuch_message_set_flag_safety (char flag, notmuch_bool_t safe)\r
174 > +{\r
175 > +    unsigned i;\r
176 > +    for (i =3D 0; i < ARRAY_SIZE (flag2tag); i++) {\r
177 > +        if (flag2tag[i].flag =3D=3D flag) {\r
178 > +            flag2tag[i].safe =3D safe;\r
179 > +        }\r
180 > +    }\r
181 > +}\r
182 > +\r
183 >  notmuch_status_t\r
184 >  notmuch_message_tags_to_maildir_flags (notmuch_message_t *message)\r
185 >  {\r
186 > diff --git a/lib/notmuch.h b/lib/notmuch.h\r
187 > index f0c1b67..475e75a 100644\r
188 > --- a/lib/notmuch.h\r
189 > +++ b/lib/notmuch.h\r
190 > @@ -922,8 +922,7 @@ notmuch_message_remove_all_tags (notmuch_message_t *m=\r
191 essage);\r
192 >   *   'P'     Adds the "passed" tag to the message\r
193 >   *   'R'     Adds the "replied" tag to the message\r
194 >   *   'S'     Removes the "unread" tag from the message\r
195 > - *   'T'     Adds the "deleted" tag to the message and\r
196 > - *           state->reckless_trash is TRUE.\r
197 > + *   'T'     Adds the "deleted" tag to the message\r
198 >   *\r
199 >   * For each flag that is not present, the opposite action (add/remove)\r
200 >   * is performed for the corresponding tags.\r
201 > @@ -941,6 +940,9 @@ notmuch_message_remove_all_tags (notmuch_message_t *m=\r
202 essage);\r
203 >   * notmuch_database_add_message. See also\r
204 >   * notmuch_message_tags_to_maildir_flags for synchronizing tag changes\r
205 >   * back to maildir flags.\r
206 > + *\r
207 > + * Actions are performed only if the tag is marked as "safe" in the\r
208 > + * configuration (only used by maildir_reckless_trash for now).\r
209 >   */\r
210 >  notmuch_status_t\r
211 >  notmuch_message_maildir_flags_to_tags (notmuch_message_t *message);\r
212 > @@ -964,8 +966,7 @@ notmuch_message_maildir_flags_to_tags (notmuch_messag=\r
213 e_t *message);\r
214 >   *   'P' iff the message has the "passed" tag\r
215 >   *   'R' iff the message has the "replied" tag\r
216 >   *   'S' iff the message does not have the "unread" tag\r
217 > - *   'T' iff the message has the "trashed" tag and\r
218 > - *   state->reckless_trash is TRUE.\r
219 > + *   'T' iff the message has the "trashed" tag\r
220 >   *\r
221 >   * Any existing flags unmentioned in the list above will be preserved\r
222 >   * in the renaming.\r
223 > @@ -979,10 +980,21 @@ notmuch_message_maildir_flags_to_tags (notmuch_mess=\r
224 age_t *message);\r
225 >   * notmuch_message_remove_tag, or notmuch_message_freeze/\r
226 >   * notmuch_message_thaw). See also notmuch_message_maildir_flags_to_tags\r
227 >   * for synchronizing maildir flag changes back to tags.\r
228 > + *\r
229 > + * Actions are performed only if the tag is marked as "safe" in the\r
230 > + * configuration (only used by maildir_reckless_trash for now).\r
231 >   */\r
232 >  notmuch_status_t\r
233 >  notmuch_message_tags_to_maildir_flags (notmuch_message_t *message);\r
234 >=20=20\r
235 > +/* Set the 'safe' setting on the given flag\r
236 > + *\r
237 > + * The flag is the one-character IMAP flag, for example for Trashed\r
238 > + * messages, it's the char 'T'.\r
239 > + */\r
240 > +void\r
241 > +notmuch_message_set_flag_safety(char flag, notmuch_bool_t safe);\r
242 > +\r
243 >  /* Freeze the current state of 'message' within the database.\r
244 >   *\r
245 >   * This means that changes to the message state, (via\r
246 > diff --git a/notmuch-new.c b/notmuch-new.c\r
247 > index 7d17793..1502a70 100644\r
248 > --- a/notmuch-new.c\r
249 > +++ b/notmuch-new.c\r
250 > @@ -801,6 +801,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[=\r
251 ])\r
252 >=20=20\r
253 >      add_files_state.new_tags =3D notmuch_config_get_new_tags (config, &a=\r
254 dd_files_state.new_tags_length);\r
255 >      add_files_state.synchronize_flags =3D notmuch_config_get_maildir_syn=\r
256 chronize_flags (config);\r
257 > +    notmuch_message_set_flag_safety('T', notmuch_config_get_maildir_reck=\r
258 less_trash (config));\r
259 >      add_files_state.message_ids_to_sync =3D _filename_list_create (ctx);\r
260 >      db_path =3D notmuch_config_get_database_path (config);\r
261 >=20=20\r
262 > diff --git a/notmuch-restore.c b/notmuch-restore.c\r
263 > index f095f64..1f3622e 100644\r
264 > --- a/notmuch-restore.c\r
265 > +++ b/notmuch-restore.c\r
266 > @@ -43,6 +43,7 @@ notmuch_restore_command (unused (void *ctx), int argc, =\r
267 char *argv[])\r
268 >       return 1;\r
269 >=20=20\r
270 >      synchronize_flags =3D notmuch_config_get_maildir_synchronize_flags (=\r
271 config);\r
272 > +    notmuch_message_set_flag_safety('T', notmuch_config_get_maildir_reck=\r
273 less_trash (config));\r
274 >=20=20\r
275 >      if (argc) {\r
276 >       input =3D fopen (argv[0], "r");\r
277 > diff --git a/notmuch-tag.c b/notmuch-tag.c\r
278 > index 6204ae3..e2f7cb8 100644\r
279 > --- a/notmuch-tag.c\r
280 > +++ b/notmuch-tag.c\r
281 > @@ -101,6 +101,7 @@ notmuch_tag_command (void *ctx, unused (int argc), un=\r
282 used (char *argv[]))\r
283 >       return 1;\r
284 >=20=20\r
285 >      synchronize_flags =3D notmuch_config_get_maildir_synchronize_flags (=\r
286 config);\r
287 > +    notmuch_message_set_flag_safety('T', notmuch_config_get_maildir_reck=\r
288 less_trash (config));\r
289 >=20=20\r
290 >      query =3D notmuch_query_create (notmuch, query_string);\r
291 >      if (query =3D=3D NULL) {\r
292 > --=20\r
293 > 1.7.2.5\r
294 >=20\r
295 > _______________________________________________\r
296 > notmuch mailing list\r
297 > notmuch@notmuchmail.org\r
298 > http://notmuchmail.org/mailman/listinfo/notmuch\r