Re: [PATCH] add has: query prefix to search for specific properties
[notmuch-archives.git] / 9f / 0a133dafe1db69e050b778113eb5b92816d547
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
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 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
18         [131.215.239.19])\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
46 Precedence: list\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
57 \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
63 ---\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
69 \r
70 diff --git a/mime-node.c b/mime-node.c\r
71 index 73e28c5..857c84c 100644\r
72 --- a/mime-node.c\r
73 +++ b/mime-node.c\r
74 @@ -150,6 +150,7 @@ _mime_node_create (mime_node_t *parent, GMimeObject *part)\r
75  {\r
76      mime_node_t *node = talloc_zero (parent, mime_node_t);\r
77      GError *err = NULL;\r
78 +    GMimeCryptoContext *cryptoctx = NULL;\r
79  \r
80      /* Set basic node properties */\r
81      node->part = part;\r
82 @@ -182,8 +183,15 @@ _mime_node_create (mime_node_t *parent, GMimeObject *part)\r
83         return NULL;\r
84      }\r
85  \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
91 +    }\r
92 +\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
105  #else\r
106             node->decrypted_child = g_mime_multipart_encrypted_decrypt\r
107 -               (encrypteddata, node->ctx->crypto->gpgctx, &err);\r
108 +               (encrypteddata, cryptoctx, &err);\r
109  #endif\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
114             }\r
115         }\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
122         } else {\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
128  \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
147 - * decrypted.\r
148 + * decrypted.  If crypto->gpgctx is NULL, it will be lazily\r
149 + * initialized.\r
150   *\r
151   * Return value:\r
152   *\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
158      else\r
159         reply_format_func = notmuch_reply_format_default;\r
160  \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
165 -#else\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
168 -#endif\r
169 -       if (params.crypto.gpgctx) {\r
170 -           g_mime_gpg_context_set_always_trust ((GMimeGpgContext*) params.crypto.gpgctx, FALSE);\r
171 -       } else {\r
172 -           params.crypto.decrypt = FALSE;\r
173 -           fprintf (stderr, "Failed to construct gpg context.\n");\r
174 -       }\r
175 -#ifndef GMIME_ATLEAST_26\r
176 -       g_object_unref (session);\r
177 -#endif\r
178 -    }\r
179 -\r
180      config = notmuch_config_open (ctx, NULL, NULL);\r
181      if (config == NULL)\r
182         return 1;\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
188         break;\r
189      }\r
190  \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
195 -#else\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
198 -#endif\r
199 -       if (params.crypto.gpgctx) {\r
200 -           g_mime_gpg_context_set_always_trust ((GMimeGpgContext*) params.crypto.gpgctx, FALSE);\r
201 -       } else {\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
208 -       }\r
209 -#ifndef GMIME_ATLEAST_26\r
210 -       g_object_unref (session);\r
211 -#endif\r
212 -    }\r
213 -\r
214      config = notmuch_config_open (ctx, NULL, NULL);\r
215      if (config == NULL)\r
216         return 1;\r
217 -- \r
218 1.7.10\r
219 \r