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 B29A9431FD2
\r
6 for <notmuch@notmuchmail.org>; Tue, 22 May 2012 18:43:59 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\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 DL+aKTm-cN4e for <notmuch@notmuchmail.org>;
\r
16 Tue, 22 May 2012 18:43:58 -0700 (PDT)
\r
17 Received: from outgoing-mail.its.caltech.edu (outgoing-mail.its.caltech.edu
\r
19 by olra.theworths.org (Postfix) with ESMTP id C94AD431FB6
\r
20 for <notmuch@notmuchmail.org>; Tue, 22 May 2012 18:43:57 -0700 (PDT)
\r
21 Received: from earth-doxen.imss.caltech.edu (localhost [127.0.0.1])
\r
22 by earth-doxen-postvirus (Postfix) with ESMTP id 806D466E0169
\r
23 for <notmuch@notmuchmail.org>; Tue, 22 May 2012 18:43:57 -0700 (PDT)
\r
24 X-Spam-Scanned: at Caltech-IMSS on earth-doxen by amavisd-new
\r
25 Received: from finestructure.net (gwave-125.ligo.caltech.edu
\r
26 [131.215.114.125]) (Authenticated sender: jrollins) by earth-doxen-submit
\r
27 (Postfix) with ESMTP id 67D1266E0172 for <notmuch@notmuchmail.org>; Tue, 22
\r
28 May 2012 18:43:55 -0700 (PDT)
\r
29 Received: by finestructure.net (Postfix, from userid 1000)
\r
30 id 41ADF1E7; Tue, 22 May 2012 18:43:54 -0700 (PDT)
\r
31 From: Jameson Graef Rollins <jrollins@finestructure.net>
\r
32 To: Notmuch Mail <notmuch@notmuchmail.org>
\r
33 Subject: [PATCH v3 6/6] cli: use new notmuch_crypto_get_context in mime-node.c
\r
34 Date: Tue, 22 May 2012 18:43:50 -0700
\r
35 Message-Id: <1337737430-21160-7-git-send-email-jrollins@finestructure.net>
\r
36 X-Mailer: git-send-email 1.7.10
\r
37 In-Reply-To: <1337737430-21160-6-git-send-email-jrollins@finestructure.net>
\r
38 References: <1337737430-21160-1-git-send-email-jrollins@finestructure.net>
\r
39 <1337737430-21160-2-git-send-email-jrollins@finestructure.net>
\r
40 <1337737430-21160-3-git-send-email-jrollins@finestructure.net>
\r
41 <1337737430-21160-4-git-send-email-jrollins@finestructure.net>
\r
42 <1337737430-21160-5-git-send-email-jrollins@finestructure.net>
\r
43 <1337737430-21160-6-git-send-email-jrollins@finestructure.net>
\r
44 X-BeenThere: notmuch@notmuchmail.org
\r
45 X-Mailman-Version: 2.1.13
\r
47 List-Id: "Use and development of the notmuch mail system."
\r
48 <notmuch.notmuchmail.org>
\r
49 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
50 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
51 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
52 List-Post: <mailto:notmuch@notmuchmail.org>
\r
53 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
54 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
55 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
56 X-List-Received-Date: Wed, 23 May 2012 01:44:00 -0000
\r
58 This has the affect of lazily creating the crypto contexts only when
\r
59 needed. This removes code duplication from notmuch-show and
\r
60 notmuch-reply, and should speed up these functions considerably if the
\r
61 crypto flags are provided but the messages don't have any
\r
62 cryptographic parts.
\r
64 mime-node.c | 20 ++++++++++++++------
\r
65 notmuch-client.h | 3 ++-
\r
66 notmuch-reply.c | 19 -------------------
\r
67 notmuch-show.c | 23 -----------------------
\r
68 4 files changed, 16 insertions(+), 49 deletions(-)
\r
70 diff --git a/mime-node.c b/mime-node.c
\r
71 index 73e28c5..857c84c 100644
\r
74 @@ -150,6 +150,7 @@ _mime_node_create (mime_node_t *parent, GMimeObject *part)
\r
76 mime_node_t *node = talloc_zero (parent, mime_node_t);
\r
78 + GMimeCryptoContext *cryptoctx = NULL;
\r
80 /* Set basic node properties */
\r
82 @@ -182,8 +183,15 @@ _mime_node_create (mime_node_t *parent, GMimeObject *part)
\r
86 + if ((GMIME_IS_MULTIPART_ENCRYPTED (part) && node->ctx->crypto->decrypt)
\r
87 + || (GMIME_IS_MULTIPART_SIGNED (part) && node->ctx->crypto->verify)) {
\r
88 + GMimeContentType *content_type = g_mime_object_get_content_type (part);
\r
89 + const char *protocol = g_mime_content_type_get_parameter (content_type, "protocol");
\r
90 + cryptoctx = notmuch_crypto_get_context (node->ctx->crypto, protocol);
\r
93 /* Handle PGP/MIME parts */
\r
94 - if (GMIME_IS_MULTIPART_ENCRYPTED (part) && node->ctx->crypto->decrypt) {
\r
95 + if (GMIME_IS_MULTIPART_ENCRYPTED (part) && node->ctx->crypto->decrypt && cryptoctx) {
\r
96 if (node->nchildren != 2) {
\r
97 /* this violates RFC 3156 section 4, so we won't bother with it. */
\r
98 fprintf (stderr, "Error: %d part(s) for a multipart/encrypted "
\r
99 @@ -196,10 +204,10 @@ _mime_node_create (mime_node_t *parent, GMimeObject *part)
\r
100 #ifdef GMIME_ATLEAST_26
\r
101 GMimeDecryptResult *decrypt_result = NULL;
\r
102 node->decrypted_child = g_mime_multipart_encrypted_decrypt
\r
103 - (encrypteddata, node->ctx->crypto->gpgctx, &decrypt_result, &err);
\r
104 + (encrypteddata, cryptoctx, &decrypt_result, &err);
\r
106 node->decrypted_child = g_mime_multipart_encrypted_decrypt
\r
107 - (encrypteddata, node->ctx->crypto->gpgctx, &err);
\r
108 + (encrypteddata, cryptoctx, &err);
\r
110 if (node->decrypted_child) {
\r
111 node->decrypt_success = node->verify_attempted = TRUE;
\r
112 @@ -217,7 +225,7 @@ _mime_node_create (mime_node_t *parent, GMimeObject *part)
\r
113 (err ? err->message : "no error explanation given"));
\r
116 - } else if (GMIME_IS_MULTIPART_SIGNED (part) && node->ctx->crypto->verify) {
\r
117 + } else if (GMIME_IS_MULTIPART_SIGNED (part) && node->ctx->crypto->verify && cryptoctx) {
\r
118 if (node->nchildren != 2) {
\r
119 /* this violates RFC 3156 section 5, so we won't bother with it. */
\r
120 fprintf (stderr, "Error: %d part(s) for a multipart/signed message "
\r
121 @@ -226,7 +234,7 @@ _mime_node_create (mime_node_t *parent, GMimeObject *part)
\r
123 #ifdef GMIME_ATLEAST_26
\r
124 node->sig_list = g_mime_multipart_signed_verify
\r
125 - (GMIME_MULTIPART_SIGNED (part), node->ctx->crypto->gpgctx, &err);
\r
126 + (GMIME_MULTIPART_SIGNED (part), cryptoctx, &err);
\r
127 node->verify_attempted = TRUE;
\r
129 if (!node->sig_list)
\r
130 @@ -242,7 +250,7 @@ _mime_node_create (mime_node_t *parent, GMimeObject *part)
\r
131 * In GMime 2.6, they're both non-const, so we'll be able
\r
132 * to clean up this asymmetry. */
\r
133 GMimeSignatureValidity *sig_validity = g_mime_multipart_signed_verify
\r
134 - (GMIME_MULTIPART_SIGNED (part), node->ctx->crypto->gpgctx, &err);
\r
135 + (GMIME_MULTIPART_SIGNED (part), cryptoctx, &err);
\r
136 node->verify_attempted = TRUE;
\r
137 node->sig_validity = sig_validity;
\r
138 if (sig_validity) {
\r
139 diff --git a/notmuch-client.h b/notmuch-client.h
\r
140 index db1c347..2434c4c 100644
\r
141 --- a/notmuch-client.h
\r
142 +++ b/notmuch-client.h
\r
143 @@ -354,7 +354,8 @@ struct mime_node {
\r
144 /* Construct a new MIME node pointing to the root message part of
\r
145 * message. If crypto->verify is true, signed child parts will be
\r
146 * verified. If crypto->decrypt is true, encrypted child parts will be
\r
148 + * decrypted. If crypto->gpgctx is NULL, it will be lazily
\r
153 diff --git a/notmuch-reply.c b/notmuch-reply.c
\r
154 index e4f293f..aecd173 100644
\r
155 --- a/notmuch-reply.c
\r
156 +++ b/notmuch-reply.c
\r
157 @@ -710,25 +710,6 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
\r
159 reply_format_func = notmuch_reply_format_default;
\r
161 - if (params.crypto.decrypt) {
\r
162 -#ifdef GMIME_ATLEAST_26
\r
163 - /* TODO: GMimePasswordRequestFunc */
\r
164 - params.crypto.gpgctx = g_mime_gpg_context_new (NULL, "gpg");
\r
166 - GMimeSession* session = g_object_new (g_mime_session_get_type(), NULL);
\r
167 - params.crypto.gpgctx = g_mime_gpg_context_new (session, "gpg");
\r
169 - if (params.crypto.gpgctx) {
\r
170 - g_mime_gpg_context_set_always_trust ((GMimeGpgContext*) params.crypto.gpgctx, FALSE);
\r
172 - params.crypto.decrypt = FALSE;
\r
173 - fprintf (stderr, "Failed to construct gpg context.\n");
\r
175 -#ifndef GMIME_ATLEAST_26
\r
176 - g_object_unref (session);
\r
180 config = notmuch_config_open (ctx, NULL, NULL);
\r
181 if (config == NULL)
\r
183 diff --git a/notmuch-show.c b/notmuch-show.c
\r
184 index 3c06792..8247f1d 100644
\r
185 --- a/notmuch-show.c
\r
186 +++ b/notmuch-show.c
\r
187 @@ -1056,29 +1056,6 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
\r
191 - if (params.crypto.decrypt || params.crypto.verify) {
\r
192 -#ifdef GMIME_ATLEAST_26
\r
193 - /* TODO: GMimePasswordRequestFunc */
\r
194 - params.crypto.gpgctx = g_mime_gpg_context_new (NULL, "gpg");
\r
196 - GMimeSession* session = g_object_new (g_mime_session_get_type(), NULL);
\r
197 - params.crypto.gpgctx = g_mime_gpg_context_new (session, "gpg");
\r
199 - if (params.crypto.gpgctx) {
\r
200 - g_mime_gpg_context_set_always_trust ((GMimeGpgContext*) params.crypto.gpgctx, FALSE);
\r
202 - /* If we fail to create the gpgctx set the verify and
\r
203 - * decrypt flags to FALSE so we don't try to do any
\r
204 - * further verification or decryption */
\r
205 - params.crypto.verify = FALSE;
\r
206 - params.crypto.decrypt = FALSE;
\r
207 - fprintf (stderr, "Failed to construct gpg context.\n");
\r
209 -#ifndef GMIME_ATLEAST_26
\r
210 - g_object_unref (session);
\r
214 config = notmuch_config_open (ctx, NULL, NULL);
\r
215 if (config == NULL)
\r