[PATCH 6/9] CLI: refactor dumping of tags.
[notmuch-archives.git] / b5 / b1fb49c274272426bf8adbc8e135d0f66e9f88
1 Return-Path: <bremner@tesseract.cs.unb.ca>\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 83E2A431FD9\r
6         for <notmuch@notmuchmail.org>; Sun, 18 Jan 2015 00:03:19 -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: 2.438\r
10 X-Spam-Level: **\r
11 X-Spam-Status: No, score=2.438 tagged_above=-999 required=5\r
12         tests=[DNS_FROM_AHBL_RHSBL=2.438] 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 NQEfnsku6wXc for <notmuch@notmuchmail.org>;\r
16         Sun, 18 Jan 2015 00:03:18 -0800 (PST)\r
17 Received: from yantan.tethera.net (yantan.tethera.net [199.188.72.155])\r
18         (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id 0C9FA431FDF\r
21         for <notmuch@notmuchmail.org>; Sun, 18 Jan 2015 00:03:12 -0800 (PST)\r
22 Received: from remotemail by yantan.tethera.net with local (Exim 4.80)\r
23         (envelope-from <bremner@tesseract.cs.unb.ca>)\r
24         id 1YCkp7-0004qT-A5; Sun, 18 Jan 2015 04:03:05 -0400\r
25 Received: (nullmailer pid 18923 invoked by uid 1000); Sun, 18 Jan 2015\r
26         08:02:54 -0000\r
27 From: David Bremner <david@tethera.net>\r
28 To: notmuch@notmuchmail.org\r
29 Subject: [Patch v4 2/5] cli: S/MIME verification/decryption support\r
30 Date: Sun, 18 Jan 2015 09:02:44 +0100\r
31 Message-Id: <1421568167-18683-3-git-send-email-david@tethera.net>\r
32 X-Mailer: git-send-email 2.1.4\r
33 In-Reply-To: <1421568167-18683-1-git-send-email-david@tethera.net>\r
34 References: <1421568167-18683-1-git-send-email-david@tethera.net>\r
35 X-BeenThere: notmuch@notmuchmail.org\r
36 X-Mailman-Version: 2.1.13\r
37 Precedence: list\r
38 List-Id: "Use and development of the notmuch mail system."\r
39         <notmuch.notmuchmail.org>\r
40 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
41         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
42 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
43 List-Post: <mailto:notmuch@notmuchmail.org>\r
44 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
45 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
46         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
47 X-List-Received-Date: Sun, 18 Jan 2015 08:03:19 -0000\r
48 \r
49 From: Jameson Graef Rollins <jrollins@finestructure.net>\r
50 \r
51 The notmuch-show flags --decrypt and --verify will now also process\r
52 S/MIME multiparts if encountered.  Requires gmime-2.6 and gpgsm.\r
53 ---\r
54  crypto.c         | 20 ++++++++++++++++++++\r
55  notmuch-client.h |  5 +++--\r
56  2 files changed, 23 insertions(+), 2 deletions(-)\r
57 \r
58 diff --git a/crypto.c b/crypto.c\r
59 index 6f4a6db..d66aa66 100644\r
60 --- a/crypto.c\r
61 +++ b/crypto.c\r
62 @@ -88,6 +88,21 @@ notmuch_crypto_get_context (notmuch_crypto_t *crypto, const char *protocol)\r
63                 fprintf (stderr, "Failed to construct gpg context.\n");\r
64         }\r
65         cryptoctx = crypto->gpgctx;\r
66 +#ifdef GMIME_ATLEAST_26\r
67 +    } else if ((strcasecmp (protocol, "application/pkcs7-signature") == 0)\r
68 +              || (strcasecmp (protocol, "application/x-pkcs7-signature") == 0)\r
69 +              || (strcasecmp (protocol, "application/pkcs7-encrypted") == 0)) {\r
70 +       if (! crypto->pkcs7ctx) {\r
71 +           /* TODO: GMimePasswordRequestFunc */\r
72 +           crypto->pkcs7ctx = g_mime_pkcs7_context_new (NULL);\r
73 +           if (crypto->pkcs7ctx) {\r
74 +               g_mime_pkcs7_context_set_always_trust ((GMimePkcs7Context*) crypto->pkcs7ctx, FALSE);\r
75 +           } else {\r
76 +               fprintf (stderr, "Failed to construct pkcs7 context.\n");\r
77 +           }\r
78 +       }\r
79 +       cryptoctx = crypto->pkcs7ctx;\r
80 +#endif\r
81      } else {\r
82         fprintf (stderr, "Unknown or unsupported cryptographic protocol.\n");\r
83      }\r
84 @@ -103,5 +118,10 @@ notmuch_crypto_cleanup (notmuch_crypto_t *crypto)\r
85         crypto->gpgctx = NULL;\r
86      }\r
87  \r
88 +    if (crypto->pkcs7ctx) {\r
89 +       g_object_unref (crypto->pkcs7ctx);\r
90 +       crypto->pkcs7ctx = NULL;\r
91 +    }\r
92 +\r
93      return 0;\r
94  }\r
95 diff --git a/notmuch-client.h b/notmuch-client.h\r
96 index 5e0d475..986f6cd 100644\r
97 --- a/notmuch-client.h\r
98 +++ b/notmuch-client.h\r
99 @@ -78,6 +78,7 @@ typedef struct notmuch_show_format {\r
100  \r
101  typedef struct notmuch_crypto {\r
102      notmuch_crypto_context_t* gpgctx;\r
103 +    notmuch_crypto_context_t* pkcs7ctx;\r
104      notmuch_bool_t verify;\r
105      notmuch_bool_t decrypt;\r
106  } notmuch_crypto_t;\r
107 @@ -414,8 +415,8 @@ struct mime_node {\r
108  /* Construct a new MIME node pointing to the root message part of\r
109   * message. If crypto->verify is true, signed child parts will be\r
110   * verified. If crypto->decrypt is true, encrypted child parts will be\r
111 - * decrypted.  If crypto->gpgctx is NULL, it will be lazily\r
112 - * initialized.\r
113 + * decrypted.  If the crypto contexts (crypto->gpgctx or\r
114 + * crypto->pkcs7) are NULL, they will be lazily initialized.\r
115   *\r
116   * Return value:\r
117   *\r
118 -- \r
119 2.1.4\r
120 \r