Re: [PATCH] test: test folder renames
[notmuch-archives.git] / c2 / d2ff6e36190f8793f7a242e3a1c0df3a3cdba6
1 Return-Path: <jrollins@finestructure.net>\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 A9A6E431FB6\r
6         for <notmuch@notmuchmail.org>; Fri, 18 May 2012 10:32:49 -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: -2.3\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_MED=-2.3] 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 UWcHN8OU-AA8 for <notmuch@notmuchmail.org>;\r
16         Fri, 18 May 2012 10:32:46 -0700 (PDT)\r
17 Received: from outgoing-mail.its.caltech.edu (outgoing-mail.its.caltech.edu\r
18         [131.215.239.19])\r
19         by olra.theworths.org (Postfix) with ESMTP id 8CE69431FBC\r
20         for <notmuch@notmuchmail.org>; Fri, 18 May 2012 10:32:46 -0700 (PDT)\r
21 Received: from fire-doxen.imss.caltech.edu (localhost [127.0.0.1])\r
22         by fire-doxen-postvirus (Postfix) with ESMTP id 4B17A328091\r
23         for <notmuch@notmuchmail.org>; Fri, 18 May 2012 10:32:44 -0700 (PDT)\r
24 X-Spam-Scanned: at Caltech-IMSS on fire-doxen by amavisd-new\r
25 Received: from finestructure.net (cpe-98-14-81-93.nyc.res.rr.com\r
26  [98.14.81.93]) (Authenticated sender: jrollins)        by fire-doxen-submit\r
27  (Postfix) with ESMTP id D21FC328076    for <notmuch@notmuchmail.org>; Fri, 18\r
28  May 2012 10:32:41 -0700 (PDT)\r
29 Received: by finestructure.net (Postfix, from userid 1000)\r
30         id 407992F4; Fri, 18 May 2012 10:32:40 -0700 (PDT)\r
31 From: Jameson Graef Rollins <jrollins@finestructure.net>\r
32 To: Notmuch Mail <notmuch@notmuchmail.org>\r
33 Subject: [PATCH v2 1/5] cli: new crypto structure to store crypto contexts and\r
34         parameters\r
35 Date: Fri, 18 May 2012 10:32:33 -0700\r
36 Message-Id: <1337362357-31281-2-git-send-email-jrollins@finestructure.net>\r
37 X-Mailer: git-send-email 1.7.10\r
38 In-Reply-To: <1337362357-31281-1-git-send-email-jrollins@finestructure.net>\r
39 References: <1337362357-31281-1-git-send-email-jrollins@finestructure.net>\r
40 X-BeenThere: notmuch@notmuchmail.org\r
41 X-Mailman-Version: 2.1.13\r
42 Precedence: list\r
43 List-Id: "Use and development of the notmuch mail system."\r
44         <notmuch.notmuchmail.org>\r
45 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
46         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
47 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
48 List-Post: <mailto:notmuch@notmuchmail.org>\r
49 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
50 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
51         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
52 X-List-Received-Date: Fri, 18 May 2012 17:32:50 -0000\r
53 \r
54 The main point here is to keep track of the crypto stuff together in\r
55 one place.  In notmuch-show the crypto struct is a sub structure of\r
56 the parameters struct.  In notmuch-reply, which had been using a\r
57 notmuch_show_params_t to store the crypto parameters, we can now just\r
58 use the general crypto struct.\r
59 \r
60 I slip in a name change of the crypto context itself to better reflect\r
61 what the context is specifically for: it's actually a GPG context,\r
62 which is a sub type of Crypto context.  There are other types of\r
63 Crypto contexts (Pkcs7 in particular) so we want to be clear.\r
64 \r
65 The following patches will use this to simplify some function\r
66 interfaces.\r
67 ---\r
68  notmuch-client.h |   16 ++++++++++------\r
69  notmuch-reply.c  |   36 +++++++++++++++++++-----------------\r
70  notmuch-show.c   |   30 ++++++++++++++++++------------\r
71  3 files changed, 47 insertions(+), 35 deletions(-)\r
72 \r
73 diff --git a/notmuch-client.h b/notmuch-client.h\r
74 index 19b7f01..2ad24cf 100644\r
75 --- a/notmuch-client.h\r
76 +++ b/notmuch-client.h\r
77 @@ -74,17 +74,21 @@ typedef struct notmuch_show_format {\r
78      const char *message_set_end;\r
79  } notmuch_show_format_t;\r
80  \r
81 +typedef struct notmuch_crypto {\r
82 +#ifdef GMIME_ATLEAST_26\r
83 +    GMimeCryptoContext* gpgctx;\r
84 +#else\r
85 +    GMimeCipherContext* gpgctx;\r
86 +#endif\r
87 +    notmuch_bool_t decrypt;\r
88 +} notmuch_crypto_t;\r
89 +\r
90  typedef struct notmuch_show_params {\r
91      notmuch_bool_t entire_thread;\r
92      notmuch_bool_t omit_excluded;\r
93      notmuch_bool_t raw;\r
94      int part;\r
95 -#ifdef GMIME_ATLEAST_26\r
96 -    GMimeCryptoContext* cryptoctx;\r
97 -#else\r
98 -    GMimeCipherContext* cryptoctx;\r
99 -#endif\r
100 -    notmuch_bool_t decrypt;\r
101 +    notmuch_crypto_t crypto;\r
102  } notmuch_show_params_t;\r
103  \r
104  /* There's no point in continuing when we've detected that we've done\r
105 diff --git a/notmuch-reply.c b/notmuch-reply.c\r
106 index 7184a5d..8d608e1 100644\r
107 --- a/notmuch-reply.c\r
108 +++ b/notmuch-reply.c\r
109 @@ -515,7 +515,7 @@ static int\r
110  notmuch_reply_format_default(void *ctx,\r
111                              notmuch_config_t *config,\r
112                              notmuch_query_t *query,\r
113 -                            notmuch_show_params_t *params,\r
114 +                            notmuch_crypto_t *crypto,\r
115                              notmuch_bool_t reply_all)\r
116  {\r
117      GMimeMessage *reply;\r
118 @@ -544,7 +544,7 @@ notmuch_reply_format_default(void *ctx,\r
119         g_object_unref (G_OBJECT (reply));\r
120         reply = NULL;\r
121  \r
122 -       if (mime_node_open (ctx, message, params->cryptoctx, params->decrypt,\r
123 +       if (mime_node_open (ctx, message, crypto->gpgctx, crypto->decrypt,\r
124                             &root) == NOTMUCH_STATUS_SUCCESS) {\r
125             format_part_reply (root);\r
126             talloc_free (root);\r
127 @@ -559,7 +559,7 @@ static int\r
128  notmuch_reply_format_json(void *ctx,\r
129                           notmuch_config_t *config,\r
130                           notmuch_query_t *query,\r
131 -                         notmuch_show_params_t *params,\r
132 +                         notmuch_crypto_t *crypto,\r
133                           notmuch_bool_t reply_all)\r
134  {\r
135      GMimeMessage *reply;\r
136 @@ -574,7 +574,7 @@ notmuch_reply_format_json(void *ctx,\r
137  \r
138      messages = notmuch_query_search_messages (query);\r
139      message = notmuch_messages_get (messages);\r
140 -    if (mime_node_open (ctx, message, params->cryptoctx, params->decrypt,\r
141 +    if (mime_node_open (ctx, message, crypto->gpgctx, crypto->decrypt,\r
142                         &node) != NOTMUCH_STATUS_SUCCESS)\r
143         return 1;\r
144  \r
145 @@ -605,7 +605,7 @@ static int\r
146  notmuch_reply_format_headers_only(void *ctx,\r
147                                   notmuch_config_t *config,\r
148                                   notmuch_query_t *query,\r
149 -                                 unused (notmuch_show_params_t *params),\r
150 +                                 unused (notmuch_crypto_t *crypto),\r
151                                   notmuch_bool_t reply_all)\r
152  {\r
153      GMimeMessage *reply;\r
154 @@ -674,8 +674,10 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
155      notmuch_query_t *query;\r
156      char *query_string;\r
157      int opt_index, ret = 0;\r
158 -    int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query, notmuch_show_params_t *params, notmuch_bool_t reply_all);\r
159 -    notmuch_show_params_t params = { .part = -1 };\r
160 +    int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query, notmuch_crypto_t *crypto, notmuch_bool_t reply_all);\r
161 +    notmuch_crypto_t crypto = {\r
162 +       .decrypt = FALSE\r
163 +    };\r
164      int format = FORMAT_DEFAULT;\r
165      int reply_all = TRUE;\r
166  \r
167 @@ -689,7 +691,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
168           (notmuch_keyword_t []){ { "all", TRUE },\r
169                                   { "sender", FALSE },\r
170                                   { 0, 0 } } },\r
171 -       { NOTMUCH_OPT_BOOLEAN, &params.decrypt, "decrypt", 'd', 0 },\r
172 +       { NOTMUCH_OPT_BOOLEAN, &crypto.decrypt, "decrypt", 'd', 0 },\r
173         { 0, 0, 0, 0, 0 }\r
174      };\r
175  \r
176 @@ -706,18 +708,18 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
177      else\r
178         reply_format_func = notmuch_reply_format_default;\r
179  \r
180 -    if (params.decrypt) {\r
181 +    if (crypto.decrypt) {\r
182  #ifdef GMIME_ATLEAST_26\r
183         /* TODO: GMimePasswordRequestFunc */\r
184 -       params.cryptoctx = g_mime_gpg_context_new (NULL, "gpg");\r
185 +       crypto.gpgctx = g_mime_gpg_context_new (NULL, "gpg");\r
186  #else\r
187         GMimeSession* session = g_object_new (g_mime_session_get_type(), NULL);\r
188 -       params.cryptoctx = g_mime_gpg_context_new (session, "gpg");\r
189 +       crypto.gpgctx = g_mime_gpg_context_new (session, "gpg");\r
190  #endif\r
191 -       if (params.cryptoctx) {\r
192 -           g_mime_gpg_context_set_always_trust ((GMimeGpgContext*) params.cryptoctx, FALSE);\r
193 +       if (crypto.gpgctx) {\r
194 +           g_mime_gpg_context_set_always_trust ((GMimeGpgContext*) crypto.gpgctx, FALSE);\r
195         } else {\r
196 -           params.decrypt = FALSE;\r
197 +           crypto.decrypt = FALSE;\r
198             fprintf (stderr, "Failed to construct gpg context.\n");\r
199         }\r
200  #ifndef GMIME_ATLEAST_26\r
201 @@ -750,14 +752,14 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
202         return 1;\r
203      }\r
204  \r
205 -    if (reply_format_func (ctx, config, query, &params, reply_all) != 0)\r
206 +    if (reply_format_func (ctx, config, query, &crypto, reply_all) != 0)\r
207         return 1;\r
208  \r
209      notmuch_query_destroy (query);\r
210      notmuch_database_destroy (notmuch);\r
211  \r
212 -    if (params.cryptoctx)\r
213 -       g_object_unref(params.cryptoctx);\r
214 +    if (crypto.gpgctx)\r
215 +       g_object_unref(crypto.gpgctx);\r
216  \r
217      return ret;\r
218  }\r
219 diff --git a/notmuch-show.c b/notmuch-show.c\r
220 index 95427d4..7779c3e 100644\r
221 --- a/notmuch-show.c\r
222 +++ b/notmuch-show.c\r
223 @@ -810,8 +810,8 @@ show_message (void *ctx,\r
224      mime_node_t *root, *part;\r
225      notmuch_status_t status;\r
226  \r
227 -    status = mime_node_open (local, message, params->cryptoctx,\r
228 -                            params->decrypt, &root);\r
229 +    status = mime_node_open (local, message, params->crypto.gpgctx,\r
230 +                            params->crypto.decrypt, &root);\r
231      if (status)\r
232         goto DONE;\r
233      part = mime_node_seek_dfs (root, (params->part < 0 ? 0 : params->part));\r
234 @@ -984,7 +984,13 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
235      char *query_string;\r
236      int opt_index, ret;\r
237      const notmuch_show_format_t *format = &format_text;\r
238 -    notmuch_show_params_t params = { .part = -1, .omit_excluded = TRUE };\r
239 +    notmuch_show_params_t params = {\r
240 +       .part = -1,\r
241 +       .omit_excluded = TRUE,\r
242 +       .crypto = {\r
243 +           .decrypt = FALSE\r
244 +       }\r
245 +    };\r
246      int format_sel = NOTMUCH_FORMAT_NOT_SPECIFIED;\r
247      notmuch_bool_t verify = FALSE;\r
248      int exclude = EXCLUDE_TRUE;\r
249 @@ -1002,7 +1008,7 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
250                                    { 0, 0 } } },\r
251         { NOTMUCH_OPT_INT, &params.part, "part", 'p', 0 },\r
252         { NOTMUCH_OPT_BOOLEAN, &params.entire_thread, "entire-thread", 't', 0 },\r
253 -       { NOTMUCH_OPT_BOOLEAN, &params.decrypt, "decrypt", 'd', 0 },\r
254 +       { NOTMUCH_OPT_BOOLEAN, &params.crypto.decrypt, "decrypt", 'd', 0 },\r
255         { NOTMUCH_OPT_BOOLEAN, &verify, "verify", 'v', 0 },\r
256         { 0, 0, 0, 0, 0 }\r
257      };\r
258 @@ -1047,18 +1053,18 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
259         break;\r
260      }\r
261  \r
262 -    if (params.decrypt || verify) {\r
263 +    if (params.crypto.decrypt || verify) {\r
264  #ifdef GMIME_ATLEAST_26\r
265         /* TODO: GMimePasswordRequestFunc */\r
266 -       params.cryptoctx = g_mime_gpg_context_new (NULL, "gpg");\r
267 +       params.crypto.gpgctx = g_mime_gpg_context_new (NULL, "gpg");\r
268  #else\r
269         GMimeSession* session = g_object_new (g_mime_session_get_type(), NULL);\r
270 -       params.cryptoctx = g_mime_gpg_context_new (session, "gpg");\r
271 +       params.crypto.gpgctx = g_mime_gpg_context_new (session, "gpg");\r
272  #endif\r
273 -       if (params.cryptoctx) {\r
274 -           g_mime_gpg_context_set_always_trust ((GMimeGpgContext*) params.cryptoctx, FALSE);\r
275 +       if (params.crypto.gpgctx) {\r
276 +           g_mime_gpg_context_set_always_trust ((GMimeGpgContext*) params.crypto.gpgctx, FALSE);\r
277         } else {\r
278 -           params.decrypt = FALSE;\r
279 +           params.crypto.decrypt = FALSE;\r
280             fprintf (stderr, "Failed to construct gpg context.\n");\r
281         }\r
282  #ifndef GMIME_ATLEAST_26\r
283 @@ -1118,8 +1124,8 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
284      notmuch_query_destroy (query);\r
285      notmuch_database_destroy (notmuch);\r
286  \r
287 -    if (params.cryptoctx)\r
288 -       g_object_unref(params.cryptoctx);\r
289 +    if (params.crypto.gpgctx)\r
290 +       g_object_unref(params.crypto.gpgctx);\r
291  \r
292      return ret;\r
293  }\r
294 -- \r
295 1.7.10\r
296 \r