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 50D31431FBD
\r
6 for <notmuch@notmuchmail.org>; Wed, 23 May 2012 15:40:55 -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 T+k5HAexTW9k for <notmuch@notmuchmail.org>;
\r
16 Wed, 23 May 2012 15:40:53 -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 7E3A6431FC3
\r
20 for <notmuch@notmuchmail.org>; Wed, 23 May 2012 15:40:50 -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 9E6B6328081
\r
23 for <notmuch@notmuchmail.org>; Wed, 23 May 2012 15:40:49 -0700 (PDT)
\r
24 X-Spam-Scanned: at Caltech-IMSS on fire-doxen by amavisd-new
\r
25 Received: from finestructure.net (unknown [137.151.175.56])
\r
26 (Authenticated sender: jrollins)
\r
27 by fire-doxen-submit (Postfix) with ESMTP id 8644432807B
\r
28 for <notmuch@notmuchmail.org>; Wed, 23 May 2012 15:40:47 -0700 (PDT)
\r
29 Received: by finestructure.net (Postfix, from userid 1000)
\r
30 id 0D1691F4; Wed, 23 May 2012 15:40:46 -0700 (PDT)
\r
31 From: Jameson Graef Rollins <jrollins@finestructure.net>
\r
32 To: Notmuch Mail <notmuch@notmuchmail.org>
\r
33 Subject: [PATCH v4 7/7] cli: use new notmuch_crypto_get_context in mime-node.c
\r
34 Date: Wed, 23 May 2012 15:40:43 -0700
\r
35 Message-Id: <1337812843-14986-8-git-send-email-jrollins@finestructure.net>
\r
36 X-Mailer: git-send-email 1.7.10
\r
37 In-Reply-To: <1337812843-14986-7-git-send-email-jrollins@finestructure.net>
\r
38 References: <1337812843-14986-1-git-send-email-jrollins@finestructure.net>
\r
39 <1337812843-14986-2-git-send-email-jrollins@finestructure.net>
\r
40 <1337812843-14986-3-git-send-email-jrollins@finestructure.net>
\r
41 <1337812843-14986-4-git-send-email-jrollins@finestructure.net>
\r
42 <1337812843-14986-5-git-send-email-jrollins@finestructure.net>
\r
43 <1337812843-14986-6-git-send-email-jrollins@finestructure.net>
\r
44 <1337812843-14986-7-git-send-email-jrollins@finestructure.net>
\r
45 X-BeenThere: notmuch@notmuchmail.org
\r
46 X-Mailman-Version: 2.1.13
\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: Wed, 23 May 2012 22:40:55 -0000
\r
59 This has the affect of lazily creating the crypto contexts only when
\r
60 needed. This removes code duplication from notmuch-show and
\r
61 notmuch-reply, and should speed up these functions considerably if the
\r
62 crypto flags are provided but the messages don't have any
\r
63 cryptographic parts.
\r
65 mime-node.c | 20 ++++++++++++++------
\r
66 notmuch-client.h | 3 ++-
\r
67 notmuch-reply.c | 19 -------------------
\r
68 notmuch-show.c | 23 -----------------------
\r
69 4 files changed, 16 insertions(+), 49 deletions(-)
\r
71 diff --git a/mime-node.c b/mime-node.c
\r
72 index 73e28c5..857c84c 100644
\r
75 @@ -150,6 +150,7 @@ _mime_node_create (mime_node_t *parent, GMimeObject *part)
\r
77 mime_node_t *node = talloc_zero (parent, mime_node_t);
\r
79 + GMimeCryptoContext *cryptoctx = NULL;
\r
81 /* Set basic node properties */
\r
83 @@ -182,8 +183,15 @@ _mime_node_create (mime_node_t *parent, GMimeObject *part)
\r
87 + if ((GMIME_IS_MULTIPART_ENCRYPTED (part) && node->ctx->crypto->decrypt)
\r
88 + || (GMIME_IS_MULTIPART_SIGNED (part) && node->ctx->crypto->verify)) {
\r
89 + GMimeContentType *content_type = g_mime_object_get_content_type (part);
\r
90 + const char *protocol = g_mime_content_type_get_parameter (content_type, "protocol");
\r
91 + cryptoctx = notmuch_crypto_get_context (node->ctx->crypto, protocol);
\r
94 /* Handle PGP/MIME parts */
\r
95 - if (GMIME_IS_MULTIPART_ENCRYPTED (part) && node->ctx->crypto->decrypt) {
\r
96 + if (GMIME_IS_MULTIPART_ENCRYPTED (part) && node->ctx->crypto->decrypt && cryptoctx) {
\r
97 if (node->nchildren != 2) {
\r
98 /* this violates RFC 3156 section 4, so we won't bother with it. */
\r
99 fprintf (stderr, "Error: %d part(s) for a multipart/encrypted "
\r
100 @@ -196,10 +204,10 @@ _mime_node_create (mime_node_t *parent, GMimeObject *part)
\r
101 #ifdef GMIME_ATLEAST_26
\r
102 GMimeDecryptResult *decrypt_result = NULL;
\r
103 node->decrypted_child = g_mime_multipart_encrypted_decrypt
\r
104 - (encrypteddata, node->ctx->crypto->gpgctx, &decrypt_result, &err);
\r
105 + (encrypteddata, cryptoctx, &decrypt_result, &err);
\r
107 node->decrypted_child = g_mime_multipart_encrypted_decrypt
\r
108 - (encrypteddata, node->ctx->crypto->gpgctx, &err);
\r
109 + (encrypteddata, cryptoctx, &err);
\r
111 if (node->decrypted_child) {
\r
112 node->decrypt_success = node->verify_attempted = TRUE;
\r
113 @@ -217,7 +225,7 @@ _mime_node_create (mime_node_t *parent, GMimeObject *part)
\r
114 (err ? err->message : "no error explanation given"));
\r
117 - } else if (GMIME_IS_MULTIPART_SIGNED (part) && node->ctx->crypto->verify) {
\r
118 + } else if (GMIME_IS_MULTIPART_SIGNED (part) && node->ctx->crypto->verify && cryptoctx) {
\r
119 if (node->nchildren != 2) {
\r
120 /* this violates RFC 3156 section 5, so we won't bother with it. */
\r
121 fprintf (stderr, "Error: %d part(s) for a multipart/signed message "
\r
122 @@ -226,7 +234,7 @@ _mime_node_create (mime_node_t *parent, GMimeObject *part)
\r
124 #ifdef GMIME_ATLEAST_26
\r
125 node->sig_list = g_mime_multipart_signed_verify
\r
126 - (GMIME_MULTIPART_SIGNED (part), node->ctx->crypto->gpgctx, &err);
\r
127 + (GMIME_MULTIPART_SIGNED (part), cryptoctx, &err);
\r
128 node->verify_attempted = TRUE;
\r
130 if (!node->sig_list)
\r
131 @@ -242,7 +250,7 @@ _mime_node_create (mime_node_t *parent, GMimeObject *part)
\r
132 * In GMime 2.6, they're both non-const, so we'll be able
\r
133 * to clean up this asymmetry. */
\r
134 GMimeSignatureValidity *sig_validity = g_mime_multipart_signed_verify
\r
135 - (GMIME_MULTIPART_SIGNED (part), node->ctx->crypto->gpgctx, &err);
\r
136 + (GMIME_MULTIPART_SIGNED (part), cryptoctx, &err);
\r
137 node->verify_attempted = TRUE;
\r
138 node->sig_validity = sig_validity;
\r
139 if (sig_validity) {
\r
140 diff --git a/notmuch-client.h b/notmuch-client.h
\r
141 index c501186..243b49c 100644
\r
142 --- a/notmuch-client.h
\r
143 +++ b/notmuch-client.h
\r
144 @@ -352,7 +352,8 @@ struct mime_node {
\r
145 /* Construct a new MIME node pointing to the root message part of
\r
146 * message. If crypto->verify is true, signed child parts will be
\r
147 * verified. If crypto->decrypt is true, encrypted child parts will be
\r
149 + * decrypted. If crypto->gpgctx is NULL, it will be lazily
\r
154 diff --git a/notmuch-reply.c b/notmuch-reply.c
\r
155 index e4f293f..aecd173 100644
\r
156 --- a/notmuch-reply.c
\r
157 +++ b/notmuch-reply.c
\r
158 @@ -710,25 +710,6 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
\r
160 reply_format_func = notmuch_reply_format_default;
\r
162 - if (params.crypto.decrypt) {
\r
163 -#ifdef GMIME_ATLEAST_26
\r
164 - /* TODO: GMimePasswordRequestFunc */
\r
165 - params.crypto.gpgctx = g_mime_gpg_context_new (NULL, "gpg");
\r
167 - GMimeSession* session = g_object_new (g_mime_session_get_type(), NULL);
\r
168 - params.crypto.gpgctx = g_mime_gpg_context_new (session, "gpg");
\r
170 - if (params.crypto.gpgctx) {
\r
171 - g_mime_gpg_context_set_always_trust ((GMimeGpgContext*) params.crypto.gpgctx, FALSE);
\r
173 - params.crypto.decrypt = FALSE;
\r
174 - fprintf (stderr, "Failed to construct gpg context.\n");
\r
176 -#ifndef GMIME_ATLEAST_26
\r
177 - g_object_unref (session);
\r
181 config = notmuch_config_open (ctx, NULL, NULL);
\r
182 if (config == NULL)
\r
184 diff --git a/notmuch-show.c b/notmuch-show.c
\r
185 index 3c06792..8247f1d 100644
\r
186 --- a/notmuch-show.c
\r
187 +++ b/notmuch-show.c
\r
188 @@ -1056,29 +1056,6 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
\r
192 - if (params.crypto.decrypt || params.crypto.verify) {
\r
193 -#ifdef GMIME_ATLEAST_26
\r
194 - /* TODO: GMimePasswordRequestFunc */
\r
195 - params.crypto.gpgctx = g_mime_gpg_context_new (NULL, "gpg");
\r
197 - GMimeSession* session = g_object_new (g_mime_session_get_type(), NULL);
\r
198 - params.crypto.gpgctx = g_mime_gpg_context_new (session, "gpg");
\r
200 - if (params.crypto.gpgctx) {
\r
201 - g_mime_gpg_context_set_always_trust ((GMimeGpgContext*) params.crypto.gpgctx, FALSE);
\r
203 - /* If we fail to create the gpgctx set the verify and
\r
204 - * decrypt flags to FALSE so we don't try to do any
\r
205 - * further verification or decryption */
\r
206 - params.crypto.verify = FALSE;
\r
207 - params.crypto.decrypt = FALSE;
\r
208 - fprintf (stderr, "Failed to construct gpg context.\n");
\r
210 -#ifndef GMIME_ATLEAST_26
\r
211 - g_object_unref (session);
\r
215 config = notmuch_config_open (ctx, NULL, NULL);
\r
216 if (config == NULL)
\r