[PATCH 4/4] Update NEWS for user.other_name
[notmuch-archives.git] / a8 / 9a129a709051faa8c944c811b5884764408675
1 Return-Path: <dkg@fifthhorseman.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 arlo.cworth.org (Postfix) with ESMTP id 1A7966DE1B1C\r
6  for <notmuch@notmuchmail.org>; Sun, 31 Jan 2016 12:40:15 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.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 arlo.cworth.org ([127.0.0.1])\r
14  by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
15  with ESMTP id vkPz5K4UqHMl for <notmuch@notmuchmail.org>;\r
16  Sun, 31 Jan 2016 12:40:12 -0800 (PST)\r
17 Received: from che.mayfirst.org (che.mayfirst.org [209.234.253.108])\r
18  by arlo.cworth.org (Postfix) with ESMTP id E51046DE0C5F\r
19  for <notmuch@notmuchmail.org>; Sun, 31 Jan 2016 12:40:08 -0800 (PST)\r
20 Received: from fifthhorseman.net (ip-64-134-185-108.public.wayport.net\r
21  [64.134.185.108])\r
22  by che.mayfirst.org (Postfix) with ESMTPSA id 8B562F993\r
23  for <notmuch@notmuchmail.org>; Sun, 31 Jan 2016 15:40:05 -0500 (EST)\r
24 Received: by fifthhorseman.net (Postfix, from userid 1000)\r
25  id 30F5920388; Sun, 31 Jan 2016 15:40:06 -0500 (EST)\r
26 From: Daniel Kahn Gillmor <dkg@fifthhorseman.net>\r
27 To: Notmuch Mail <notmuch@notmuchmail.org>\r
28 Subject: [PATCH v3 02/16] Move crypto.c into libutil\r
29 Date: Sun, 31 Jan 2016 15:39:47 -0500\r
30 Message-Id: <1454272801-23623-3-git-send-email-dkg@fifthhorseman.net>\r
31 X-Mailer: git-send-email 2.7.0.rc3\r
32 In-Reply-To: <1454272801-23623-1-git-send-email-dkg@fifthhorseman.net>\r
33 References: <1454272801-23623-1-git-send-email-dkg@fifthhorseman.net>\r
34 MIME-Version: 1.0\r
35 Content-Type: text/plain; charset=UTF-8\r
36 Content-Transfer-Encoding: 8bit\r
37 X-BeenThere: notmuch@notmuchmail.org\r
38 X-Mailman-Version: 2.1.20\r
39 Precedence: list\r
40 List-Id: "Use and development of the notmuch mail system."\r
41  <notmuch.notmuchmail.org>\r
42 List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,\r
43  <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
44 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
45 List-Post: <mailto:notmuch@notmuchmail.org>\r
46 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
47 List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
48  <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
49 X-List-Received-Date: Sun, 31 Jan 2016 20:40:15 -0000\r
50 \r
51 This prepares us for using the crypto object in both the library and\r
52 the client.\r
53 \r
54 i've prefixed notmuch_crypto with _ to indicate that while this can be\r
55 built into the library when needed, it's not something to be exported\r
56 or used externally.\r
57 ---\r
58  Makefile.local      |   1 -\r
59  crypto.c            | 134 --------------------------------------------------\r
60  mime-node.c         |  12 ++---\r
61  notmuch-client.h    |  23 ++-------\r
62  notmuch-reply.c     |   2 +-\r
63  notmuch-show.c      |   2 +-\r
64  util/Makefile.local |   2 +-\r
65  util/crypto.c       | 138 ++++++++++++++++++++++++++++++++++++++++++++++++++++\r
66  util/crypto.h       |  25 ++++++++++\r
67  9 files changed, 175 insertions(+), 164 deletions(-)\r
68  delete mode 100644 crypto.c\r
69  create mode 100644 util/crypto.c\r
70  create mode 100644 util/crypto.h\r
71 \r
72 diff --git a/Makefile.local b/Makefile.local\r
73 index 066ecf2..6206771 100644\r
74 --- a/Makefile.local\r
75 +++ b/Makefile.local\r
76 @@ -293,7 +293,6 @@ notmuch_client_srcs =               \\r
77         sprinter-text.c         \\r
78         query-string.c          \\r
79         mime-node.c             \\r
80 -       crypto.c                \\r
81         tag-util.c\r
82  \r
83  notmuch_client_modules = $(notmuch_client_srcs:.c=.o)\r
84 diff --git a/crypto.c b/crypto.c\r
85 deleted file mode 100644\r
86 index 3dabc97..0000000\r
87 --- a/crypto.c\r
88 +++ /dev/null\r
89 @@ -1,134 +0,0 @@\r
90 -/* notmuch - Not much of an email program, (just index and search)\r
91 - *\r
92 - * Copyright © 2012 Jameson Rollins\r
93 - *\r
94 - * This program is free software: you can redistribute it and/or modify\r
95 - * it under the terms of the GNU General Public License as published by\r
96 - * the Free Software Foundation, either version 3 of the License, or\r
97 - * (at your option) any later version.\r
98 - *\r
99 - * This program is distributed in the hope that it will be useful,\r
100 - * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
101 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
102 - * GNU General Public License for more details.\r
103 - *\r
104 - * You should have received a copy of the GNU General Public License\r
105 - * along with this program.  If not, see http://www.gnu.org/licenses/ .\r
106 - *\r
107 - * Authors: Jameson Rollins <jrollins@finestructure.net>\r
108 - */\r
109 -\r
110 -#include "notmuch-client.h"\r
111 -\r
112 -/* Create a GPG context (GMime 2.6) */\r
113 -static notmuch_crypto_context_t *\r
114 -create_gpg_context (notmuch_crypto_t *crypto)\r
115 -{\r
116 -    notmuch_crypto_context_t *gpgctx;\r
117 -\r
118 -    if (crypto->gpgctx)\r
119 -       return crypto->gpgctx;\r
120 -\r
121 -    /* TODO: GMimePasswordRequestFunc */\r
122 -    gpgctx = g_mime_gpg_context_new (NULL, crypto->gpgpath ? crypto->gpgpath : "gpg");\r
123 -    if (! gpgctx) {\r
124 -       fprintf (stderr, "Failed to construct gpg context.\n");\r
125 -       return NULL;\r
126 -    }\r
127 -    crypto->gpgctx = gpgctx;\r
128 -\r
129 -    g_mime_gpg_context_set_use_agent ((GMimeGpgContext *) gpgctx, TRUE);\r
130 -    g_mime_gpg_context_set_always_trust ((GMimeGpgContext *) gpgctx, FALSE);\r
131 -\r
132 -    return gpgctx;\r
133 -}\r
134 -\r
135 -/* Create a PKCS7 context (GMime 2.6) */\r
136 -static notmuch_crypto_context_t *\r
137 -create_pkcs7_context (notmuch_crypto_t *crypto)\r
138 -{\r
139 -    notmuch_crypto_context_t *pkcs7ctx;\r
140 -\r
141 -    if (crypto->pkcs7ctx)\r
142 -       return crypto->pkcs7ctx;\r
143 -\r
144 -    /* TODO: GMimePasswordRequestFunc */\r
145 -    pkcs7ctx = g_mime_pkcs7_context_new (NULL);\r
146 -    if (! pkcs7ctx) {\r
147 -       fprintf (stderr, "Failed to construct pkcs7 context.\n");\r
148 -       return NULL;\r
149 -    }\r
150 -    crypto->pkcs7ctx = pkcs7ctx;\r
151 -\r
152 -    g_mime_pkcs7_context_set_always_trust ((GMimePkcs7Context *) pkcs7ctx,\r
153 -                                          FALSE);\r
154 -\r
155 -    return pkcs7ctx;\r
156 -}\r
157 -static const struct {\r
158 -    const char *protocol;\r
159 -    notmuch_crypto_context_t *(*get_context) (notmuch_crypto_t *crypto);\r
160 -} protocols[] = {\r
161 -    {\r
162 -       .protocol = "application/pgp-signature",\r
163 -       .get_context = create_gpg_context,\r
164 -    },\r
165 -    {\r
166 -       .protocol = "application/pgp-encrypted",\r
167 -       .get_context = create_gpg_context,\r
168 -    },\r
169 -    {\r
170 -       .protocol = "application/pkcs7-signature",\r
171 -       .get_context = create_pkcs7_context,\r
172 -    },\r
173 -    {\r
174 -       .protocol = "application/x-pkcs7-signature",\r
175 -       .get_context = create_pkcs7_context,\r
176 -    },\r
177 -};\r
178 -\r
179 -/* for the specified protocol return the context pointer (initializing\r
180 - * if needed) */\r
181 -notmuch_crypto_context_t *\r
182 -notmuch_crypto_get_context (notmuch_crypto_t *crypto, const char *protocol)\r
183 -{\r
184 -    notmuch_crypto_context_t *cryptoctx = NULL;\r
185 -    size_t i;\r
186 -\r
187 -    if (! protocol) {\r
188 -       fprintf (stderr, "Cryptographic protocol is empty.\n");\r
189 -       return cryptoctx;\r
190 -    }\r
191 -\r
192 -    /* As per RFC 1847 section 2.1: "the [protocol] value token is\r
193 -     * comprised of the type and sub-type tokens of the Content-Type".\r
194 -     * As per RFC 1521 section 2: "Content-Type values, subtypes, and\r
195 -     * parameter names as defined in this document are\r
196 -     * case-insensitive."  Thus, we use strcasecmp for the protocol.\r
197 -     */\r
198 -    for (i = 0; i < ARRAY_SIZE (protocols); i++) {\r
199 -       if (strcasecmp (protocol, protocols[i].protocol) == 0)\r
200 -           return protocols[i].get_context (crypto);\r
201 -    }\r
202 -\r
203 -    fprintf (stderr, "Unknown or unsupported cryptographic protocol %s.\n",\r
204 -            protocol);\r
205 -\r
206 -    return NULL;\r
207 -}\r
208 -\r
209 -int\r
210 -notmuch_crypto_cleanup (notmuch_crypto_t *crypto)\r
211 -{\r
212 -    if (crypto->gpgctx) {\r
213 -       g_object_unref (crypto->gpgctx);\r
214 -       crypto->gpgctx = NULL;\r
215 -    }\r
216 -\r
217 -    if (crypto->pkcs7ctx) {\r
218 -       g_object_unref (crypto->pkcs7ctx);\r
219 -       crypto->pkcs7ctx = NULL;\r
220 -    }\r
221 -\r
222 -    return 0;\r
223 -}\r
224 diff --git a/mime-node.c b/mime-node.c\r
225 index e96e663..a8f5670 100644\r
226 --- a/mime-node.c\r
227 +++ b/mime-node.c\r
228 @@ -33,7 +33,7 @@ typedef struct mime_node_context {\r
229      GMimeMessage *mime_message;\r
230  \r
231      /* Context provided by the caller. */\r
232 -    notmuch_crypto_t *crypto;\r
233 +    _notmuch_crypto_t *crypto;\r
234  } mime_node_context_t;\r
235  \r
236  static int\r
237 @@ -56,7 +56,7 @@ _mime_node_context_free (mime_node_context_t *res)\r
238  \r
239  notmuch_status_t\r
240  mime_node_open (const void *ctx, notmuch_message_t *message,\r
241 -               notmuch_crypto_t *crypto, mime_node_t **root_out)\r
242 +               _notmuch_crypto_t *crypto, mime_node_t **root_out)\r
243  {\r
244      const char *filename = notmuch_message_get_filename (message);\r
245      mime_node_context_t *mctx;\r
246 @@ -151,7 +151,7 @@ set_signature_list_destructor (mime_node_t *node)\r
247  /* Verify a signed mime node (GMime 2.6) */\r
248  static void\r
249  node_verify (mime_node_t *node, GMimeObject *part,\r
250 -            notmuch_crypto_context_t *cryptoctx)\r
251 +            GMimeCryptoContext *cryptoctx)\r
252  {\r
253      GError *err = NULL;\r
254  \r
255 @@ -172,7 +172,7 @@ node_verify (mime_node_t *node, GMimeObject *part,\r
256  /* Decrypt and optionally verify an encrypted mime node (GMime 2.6) */\r
257  static void\r
258  node_decrypt_and_verify (mime_node_t *node, GMimeObject *part,\r
259 -                        notmuch_crypto_context_t *cryptoctx)\r
260 +                        GMimeCryptoContext *cryptoctx)\r
261  {\r
262      GError *err = NULL;\r
263      GMimeDecryptResult *decrypt_result = NULL;\r
264 @@ -207,7 +207,7 @@ static mime_node_t *\r
265  _mime_node_create (mime_node_t *parent, GMimeObject *part)\r
266  {\r
267      mime_node_t *node = talloc_zero (parent, mime_node_t);\r
268 -    notmuch_crypto_context_t *cryptoctx = NULL;\r
269 +    GMimeCryptoContext *cryptoctx = NULL;\r
270  \r
271      /* Set basic node properties */\r
272      node->part = part;\r
273 @@ -244,7 +244,7 @@ _mime_node_create (mime_node_t *parent, GMimeObject *part)\r
274         || (GMIME_IS_MULTIPART_SIGNED (part) && node->ctx->crypto->verify)) {\r
275         GMimeContentType *content_type = g_mime_object_get_content_type (part);\r
276         const char *protocol = g_mime_content_type_get_parameter (content_type, "protocol");\r
277 -       cryptoctx = notmuch_crypto_get_context (node->ctx->crypto, protocol);\r
278 +       cryptoctx = _notmuch_crypto_get_gmime_context (node->ctx->crypto, protocol);\r
279      }\r
280  \r
281      /* Handle PGP/MIME parts */\r
282 diff --git a/notmuch-client.h b/notmuch-client.h\r
283 index 18e6c60..a41e90a 100644\r
284 --- a/notmuch-client.h\r
285 +++ b/notmuch-client.h\r
286 @@ -30,10 +30,6 @@\r
287  \r
288  #include <gmime/gmime.h>\r
289  \r
290 -typedef GMimeCryptoContext notmuch_crypto_context_t;\r
291 -/* This is automatically included only since gmime 2.6.10 */\r
292 -#include <gmime/gmime-pkcs7-context.h>\r
293 -\r
294  #include "notmuch.h"\r
295  \r
296  /* This is separate from notmuch-private.h because we're trying to\r
297 @@ -53,6 +49,7 @@ typedef GMimeCryptoContext notmuch_crypto_context_t;\r
298  #include <ctype.h>\r
299  \r
300  #include "talloc-extra.h"\r
301 +#include "crypto.h"\r
302  \r
303  #define unused(x) x __attribute__ ((unused))\r
304  \r
305 @@ -70,21 +67,13 @@ typedef struct notmuch_show_format {\r
306                               const struct notmuch_show_params *params);\r
307  } notmuch_show_format_t;\r
308  \r
309 -typedef struct notmuch_crypto {\r
310 -    notmuch_crypto_context_t* gpgctx;\r
311 -    notmuch_crypto_context_t* pkcs7ctx;\r
312 -    notmuch_bool_t verify;\r
313 -    notmuch_bool_t decrypt;\r
314 -    const char *gpgpath;\r
315 -} notmuch_crypto_t;\r
316 -\r
317  typedef struct notmuch_show_params {\r
318      notmuch_bool_t entire_thread;\r
319      notmuch_bool_t omit_excluded;\r
320      notmuch_bool_t output_body;\r
321      notmuch_bool_t raw;\r
322      int part;\r
323 -    notmuch_crypto_t crypto;\r
324 +    _notmuch_crypto_t crypto;\r
325      notmuch_bool_t include_html;\r
326  } notmuch_show_params_t;\r
327  \r
328 @@ -167,12 +156,6 @@ typedef struct _notmuch_config notmuch_config_t;\r
329  void\r
330  notmuch_exit_if_unsupported_format (void);\r
331  \r
332 -notmuch_crypto_context_t *\r
333 -notmuch_crypto_get_context (notmuch_crypto_t *crypto, const char *protocol);\r
334 -\r
335 -int\r
336 -notmuch_crypto_cleanup (notmuch_crypto_t *crypto);\r
337 -\r
338  int\r
339  notmuch_count_command (notmuch_config_t *config, int argc, char *argv[]);\r
340  \r
341 @@ -423,7 +406,7 @@ struct mime_node {\r
342   */\r
343  notmuch_status_t\r
344  mime_node_open (const void *ctx, notmuch_message_t *message,\r
345 -               notmuch_crypto_t *crypto, mime_node_t **node_out);\r
346 +               _notmuch_crypto_t *crypto, mime_node_t **node_out);\r
347  \r
348  /* Return a new MIME node for the requested child part of parent.\r
349   * parent will be used as the talloc context for the returned child\r
350 diff --git a/notmuch-reply.c b/notmuch-reply.c\r
351 index 6df54fc..eccfb32 100644\r
352 --- a/notmuch-reply.c\r
353 +++ b/notmuch-reply.c\r
354 @@ -862,7 +862,7 @@ notmuch_reply_command (notmuch_config_t *config, int argc, char *argv[])\r
355      if (reply_format_func (config, config, query, &params, reply_all, sp) != 0)\r
356         return EXIT_FAILURE;\r
357  \r
358 -    notmuch_crypto_cleanup (&params.crypto);\r
359 +    _notmuch_crypto_cleanup (&params.crypto);\r
360      notmuch_query_destroy (query);\r
361      notmuch_database_destroy (notmuch);\r
362  \r
363 diff --git a/notmuch-show.c b/notmuch-show.c\r
364 index 87e52bb..3c91ece 100644\r
365 --- a/notmuch-show.c\r
366 +++ b/notmuch-show.c\r
367 @@ -1171,7 +1171,7 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])\r
368         ret = do_show (config, query, format, sprinter, &params);\r
369      }\r
370  \r
371 -    notmuch_crypto_cleanup (&params.crypto);\r
372 +    _notmuch_crypto_cleanup (&params.crypto);\r
373      notmuch_query_destroy (query);\r
374      notmuch_database_destroy (notmuch);\r
375  \r
376 diff --git a/util/Makefile.local b/util/Makefile.local\r
377 index 8b2b91b..7590618 100644\r
378 --- a/util/Makefile.local\r
379 +++ b/util/Makefile.local\r
380 @@ -5,7 +5,7 @@ extra_cflags += -I$(srcdir)/$(dir)\r
381  \r
382  libutil_c_srcs := $(dir)/xutil.c $(dir)/error_util.c $(dir)/hex-escape.c \\r
383                   $(dir)/string-util.c $(dir)/talloc-extra.c $(dir)/zlib-extra.c \\r
384 -               $(dir)/util.c $(dir)/search-path.c\r
385 +               $(dir)/util.c $(dir)/search-path.c $(dir)/crypto.c\r
386  \r
387  libutil_modules := $(libutil_c_srcs:.c=.o)\r
388  \r
389 diff --git a/util/crypto.c b/util/crypto.c\r
390 new file mode 100644\r
391 index 0000000..eab12a3\r
392 --- /dev/null\r
393 +++ b/util/crypto.c\r
394 @@ -0,0 +1,138 @@\r
395 +/* notmuch - Not much of an email program, (just index and search)\r
396 + *\r
397 + * Copyright © 2012 Jameson Rollins\r
398 + *\r
399 + * This program is free software: you can redistribute it and/or modify\r
400 + * it under the terms of the GNU General Public License as published by\r
401 + * the Free Software Foundation, either version 3 of the License, or\r
402 + * (at your option) any later version.\r
403 + *\r
404 + * This program is distributed in the hope that it will be useful,\r
405 + * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
406 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
407 + * GNU General Public License for more details.\r
408 + *\r
409 + * You should have received a copy of the GNU General Public License\r
410 + * along with this program.  If not, see http://www.gnu.org/licenses/ .\r
411 + *\r
412 + * Authors: Jameson Rollins <jrollins@finestructure.net>\r
413 + *          Daniel Kahn Gillmor <dkg@fifthhorseman.net>\r
414 + */\r
415 +\r
416 +#include "notmuch.h"\r
417 +#include "crypto.h"\r
418 +#include <string.h>\r
419 +\r
420 +#define ARRAY_SIZE(arr) (sizeof (arr) / sizeof (arr[0]))\r
421 +\r
422 +/* Create a GPG context (GMime 2.6) */\r
423 +static GMimeCryptoContext*\r
424 +create_gpg_context (_notmuch_crypto_t *crypto)\r
425 +{\r
426 +    GMimeCryptoContext *gpgctx;\r
427 +\r
428 +    if (crypto->gpgctx) {\r
429 +       return crypto->gpgctx;\r
430 +    }\r
431 +\r
432 +    /* TODO: GMimePasswordRequestFunc */\r
433 +    gpgctx = g_mime_gpg_context_new (NULL, crypto->gpgpath ? crypto->gpgpath : "gpg");\r
434 +    if (! gpgctx) {\r
435 +       fprintf (stderr, "Failed to construct gpg context.\n");\r
436 +       return NULL;\r
437 +    }\r
438 +    crypto->gpgctx = gpgctx;\r
439 +\r
440 +    g_mime_gpg_context_set_use_agent ((GMimeGpgContext *) gpgctx, TRUE);\r
441 +    g_mime_gpg_context_set_always_trust ((GMimeGpgContext *) gpgctx, FALSE);\r
442 +\r
443 +    return crypto->gpgctx;\r
444 +}\r
445 +\r
446 +/* Create a PKCS7 context (GMime 2.6) */\r
447 +static notmuch_crypto_context_t *\r
448 +create_pkcs7_context (notmuch_crypto_t *crypto)\r
449 +{\r
450 +    notmuch_crypto_context_t *pkcs7ctx;\r
451 +\r
452 +    if (crypto->pkcs7ctx)\r
453 +       return crypto->pkcs7ctx;\r
454 +\r
455 +    /* TODO: GMimePasswordRequestFunc */\r
456 +    pkcs7ctx = g_mime_pkcs7_context_new (NULL);\r
457 +    if (! pkcs7ctx) {\r
458 +       fprintf (stderr, "Failed to construct pkcs7 context.\n");\r
459 +       return NULL;\r
460 +    }\r
461 +    crypto->pkcs7ctx = pkcs7ctx;\r
462 +\r
463 +    g_mime_pkcs7_context_set_always_trust ((GMimePkcs7Context *) pkcs7ctx,\r
464 +                                          FALSE);\r
465 +\r
466 +    return crypto->pkcs7ctx;\r
467 +}\r
468 +static const struct {\r
469 +    const char *protocol;\r
470 +    GMimeCryptoContext *(*get_context) (_notmuch_crypto_t *crypto);\r
471 +} protocols[] = {\r
472 +    {\r
473 +       .protocol = "application/pgp-signature",\r
474 +       .get_context = create_gpg_context,\r
475 +    },\r
476 +    {\r
477 +       .protocol = "application/pgp-encrypted",\r
478 +       .get_context = create_gpg_context,\r
479 +    },\r
480 +    {\r
481 +       .protocol = "application/pkcs7-signature",\r
482 +       .get_context = create_pkcs7_context,\r
483 +    },\r
484 +    {\r
485 +       .protocol = "application/x-pkcs7-signature",\r
486 +       .get_context = create_pkcs7_context,\r
487 +    },\r
488 +};\r
489 +\r
490 +/* for the specified protocol return the context pointer (initializing\r
491 + * if needed) */\r
492 +GMimeCryptoContext *\r
493 +_notmuch_crypto_get_gmime_context (_notmuch_crypto_t *crypto, const char *protocol)\r
494 +{\r
495 +    GMimeCryptoContext *cryptoctx = NULL;\r
496 +    size_t i;\r
497 +\r
498 +    if (! protocol) {\r
499 +       fprintf (stderr, "Cryptographic protocol is empty.\n");\r
500 +       return cryptoctx;\r
501 +    }\r
502 +\r
503 +    /* As per RFC 1847 section 2.1: "the [protocol] value token is\r
504 +     * comprised of the type and sub-type tokens of the Content-Type".\r
505 +     * As per RFC 1521 section 2: "Content-Type values, subtypes, and\r
506 +     * parameter names as defined in this document are\r
507 +     * case-insensitive."  Thus, we use strcasecmp for the protocol.\r
508 +     */\r
509 +    for (i = 0; i < ARRAY_SIZE (protocols); i++) {\r
510 +       if (strcasecmp (protocol, protocols[i].protocol) == 0)\r
511 +           return protocols[i].get_context (crypto);\r
512 +    }\r
513 +\r
514 +    fprintf (stderr, "Unknown or unsupported cryptographic protocol %s.\n",\r
515 +            protocol);\r
516 +\r
517 +    return NULL;\r
518 +}\r
519 +\r
520 +void\r
521 +_notmuch_crypto_cleanup (_notmuch_crypto_t *crypto)\r
522 +{\r
523 +    if (crypto->gpgctx) {\r
524 +       g_object_unref (crypto->gpgctx);\r
525 +       crypto->gpgctx = NULL;\r
526 +    }\r
527 +\r
528 +    if (crypto->pkcs7ctx) {\r
529 +       g_object_unref (crypto->pkcs7ctx);\r
530 +       crypto->pkcs7ctx = NULL;\r
531 +    }\r
532 +}\r
533 diff --git a/util/crypto.h b/util/crypto.h\r
534 new file mode 100644\r
535 index 0000000..d4a51e8\r
536 --- /dev/null\r
537 +++ b/util/crypto.h\r
538 @@ -0,0 +1,25 @@\r
539 +#ifndef _CRYPTO_H\r
540 +#define _CRYPTO_H\r
541 +\r
542 +#include "notmuch.h"\r
543 +#include <gmime/gmime.h>\r
544 +/* This is automatically included only since gmime 2.6.10 */\r
545 +#include <gmime/gmime-pkcs7-context.h>\r
546 +\r
547 +typedef struct _notmuch_crypto {\r
548 +    GMimeCryptoContext* gpgctx;\r
549 +    GMimeCryptoContext* pkcs7ctx;\r
550 +    notmuch_bool_t verify;\r
551 +    notmuch_bool_t decrypt;\r
552 +    const char *gpgpath;\r
553 +} _notmuch_crypto_t;\r
554 +\r
555 +\r
556 +GMimeCryptoContext *\r
557 +_notmuch_crypto_get_gmime_context (_notmuch_crypto_t *crypto, const char *protocol);\r
558 +\r
559 +void\r
560 +_notmuch_crypto_cleanup (_notmuch_crypto_t *crypto);\r
561 +\r
562 +\r
563 +#endif\r
564 -- \r
565 2.7.0.rc3\r
566 \r