Re: [feature request] emacs: use `notmuch insert` for FCC
[notmuch-archives.git] / 80 / bb01790d8a5fcc59ddf6476a4cc4e831e32486
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 4677D431FBC\r
6         for <notmuch@notmuchmail.org>; Fri, 18 May 2012 10:32:52 -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 crdDL4yPwtqo for <notmuch@notmuchmail.org>;\r
16         Fri, 18 May 2012 10:32:50 -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 BAB54431FC2\r
20         for <notmuch@notmuchmail.org>; Fri, 18 May 2012 10:32:46 -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 7194F66E00A3\r
23         for <notmuch@notmuchmail.org>; Fri, 18 May 2012 10:32:46 -0700 (PDT)\r
24 X-Spam-Scanned: at Caltech-IMSS on earth-doxen by amavisd-new\r
25 Received: from finestructure.net (cpe-98-14-81-93.nyc.res.rr.com\r
26  [98.14.81.93]) (Authenticated sender: jrollins)        by earth-doxen-submit\r
27  (Postfix) with ESMTP id 4571D66E01B3   for <notmuch@notmuchmail.org>; Fri, 18\r
28  May 2012 10:32:44 -0700 (PDT)\r
29 Received: by finestructure.net (Postfix, from userid 1000)\r
30         id 4BBE3628; Fri, 18 May 2012 10:32:40 -0700 (PDT)\r
31 From: Jameson Graef Rollins <jrollins@finestructure.net>\r
32 To: Notmuch Mail <notmuch@notmuchmail.org>\r
33 Subject: [PATCH v2 5/5] cli: lazily create the crypto gpg context only when\r
34         needed\r
35 Date: Fri, 18 May 2012 10:32:37 -0700\r
36 Message-Id: <1337362357-31281-6-git-send-email-jrollins@finestructure.net>\r
37 X-Mailer: git-send-email 1.7.10\r
38 In-Reply-To: <1337362357-31281-5-git-send-email-jrollins@finestructure.net>\r
39 References: <1337362357-31281-1-git-send-email-jrollins@finestructure.net>\r
40         <1337362357-31281-2-git-send-email-jrollins@finestructure.net>\r
41         <1337362357-31281-3-git-send-email-jrollins@finestructure.net>\r
42         <1337362357-31281-4-git-send-email-jrollins@finestructure.net>\r
43         <1337362357-31281-5-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: Fri, 18 May 2012 17:32:52 -0000\r
57 \r
58 Move the creation of the crypto ctx into mime-node.c and create it\r
59 only when 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      |   25 +++++++++++++++++++++++++\r
65  notmuch-client.h |    3 ++-\r
66  notmuch-reply.c  |   19 -------------------\r
67  notmuch-show.c   |   23 -----------------------\r
68  4 files changed, 27 insertions(+), 43 deletions(-)\r
69 \r
70 diff --git a/mime-node.c b/mime-node.c\r
71 index 3adbe5a..592e0b6 100644\r
72 --- a/mime-node.c\r
73 +++ b/mime-node.c\r
74 @@ -182,6 +182,31 @@ _mime_node_create (mime_node_t *parent, GMimeObject *part)\r
75         return NULL;\r
76      }\r
77  \r
78 +    /* Lazily create the gpgctx if it's needed and hasn't been initialized yet */\r
79 +    if ((GMIME_IS_MULTIPART_ENCRYPTED (part) || GMIME_IS_MULTIPART_SIGNED (part))\r
80 +       && (node->ctx->crypto->verify || node->ctx->crypto->decrypt)) {\r
81 +       if (!node->ctx->crypto->gpgctx) {\r
82 +#ifdef GMIME_ATLEAST_26\r
83 +           /* TODO: GMimePasswordRequestFunc */\r
84 +           node->ctx->crypto->gpgctx = g_mime_gpg_context_new (NULL, "gpg");\r
85 +#else\r
86 +           GMimeSession* session = g_object_new (g_mime_session_get_type(), NULL);\r
87 +           node->ctx->crypto->gpgctx = g_mime_gpg_context_new (session, "gpg");\r
88 +           g_object_unref (session);\r
89 +#endif\r
90 +           if (node->ctx->crypto->gpgctx) {\r
91 +               g_mime_gpg_context_set_always_trust ((GMimeGpgContext*) node->ctx->crypto->gpgctx, FALSE);\r
92 +           } else {\r
93 +               /* If we fail to create the gpgctx set the verify and\r
94 +                * decrypt flags to FALSE so we don't try to do any\r
95 +                * further verification or decryption */\r
96 +               node->ctx->crypto->verify = FALSE;\r
97 +               node->ctx->crypto->decrypt = FALSE;\r
98 +               fprintf (stderr, "Failed to construct gpg context.\n");\r
99 +           }\r
100 +       }\r
101 +    }\r
102 +\r
103      /* Handle PGP/MIME parts */\r
104      if (GMIME_IS_MULTIPART_ENCRYPTED (part) && node->ctx->crypto->decrypt) {\r
105         if (node->nchildren != 2) {\r
106 diff --git a/notmuch-client.h b/notmuch-client.h\r
107 index c671c13..c79eaa9 100644\r
108 --- a/notmuch-client.h\r
109 +++ b/notmuch-client.h\r
110 @@ -348,7 +348,8 @@ struct mime_node {\r
111  /* Construct a new MIME node pointing to the root message part of\r
112   * message. If crypto->verify is true, signed child parts will be\r
113   * verified. If crypto->decrypt is true, encrypted child parts will be\r
114 - * decrypted.\r
115 + * decrypted.  The GPG context crypto->gpgctx does not need to be\r
116 + * pre-initialized as it will be initialized lazily as needed.\r
117   *\r
118   * Return value:\r
119   *\r
120 diff --git a/notmuch-reply.c b/notmuch-reply.c\r
121 index 345be76..1a61aa7 100644\r
122 --- a/notmuch-reply.c\r
123 +++ b/notmuch-reply.c\r
124 @@ -707,25 +707,6 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
125      else\r
126         reply_format_func = notmuch_reply_format_default;\r
127  \r
128 -    if (crypto.decrypt) {\r
129 -#ifdef GMIME_ATLEAST_26\r
130 -       /* TODO: GMimePasswordRequestFunc */\r
131 -       crypto.gpgctx = g_mime_gpg_context_new (NULL, "gpg");\r
132 -#else\r
133 -       GMimeSession* session = g_object_new (g_mime_session_get_type(), NULL);\r
134 -       crypto.gpgctx = g_mime_gpg_context_new (session, "gpg");\r
135 -#endif\r
136 -       if (crypto.gpgctx) {\r
137 -           g_mime_gpg_context_set_always_trust ((GMimeGpgContext*) crypto.gpgctx, FALSE);\r
138 -       } else {\r
139 -           crypto.decrypt = FALSE;\r
140 -           fprintf (stderr, "Failed to construct gpg context.\n");\r
141 -       }\r
142 -#ifndef GMIME_ATLEAST_26\r
143 -       g_object_unref (session);\r
144 -#endif\r
145 -    }\r
146 -\r
147      config = notmuch_config_open (ctx, NULL, NULL);\r
148      if (config == NULL)\r
149         return 1;\r
150 diff --git a/notmuch-show.c b/notmuch-show.c\r
151 index f4ee038..5f785d0 100644\r
152 --- a/notmuch-show.c\r
153 +++ b/notmuch-show.c\r
154 @@ -1056,29 +1056,6 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
155         break;\r
156      }\r
157  \r
158 -    if (params.crypto.decrypt || params.crypto.verify) {\r
159 -#ifdef GMIME_ATLEAST_26\r
160 -       /* TODO: GMimePasswordRequestFunc */\r
161 -       params.crypto.gpgctx = g_mime_gpg_context_new (NULL, "gpg");\r
162 -#else\r
163 -       GMimeSession* session = g_object_new (g_mime_session_get_type(), NULL);\r
164 -       params.crypto.gpgctx = g_mime_gpg_context_new (session, "gpg");\r
165 -#endif\r
166 -       if (params.crypto.gpgctx) {\r
167 -           g_mime_gpg_context_set_always_trust ((GMimeGpgContext*) params.crypto.gpgctx, FALSE);\r
168 -       } else {\r
169 -           /* If we fail to create the gpgctx set the verify and\r
170 -            * decrypt flags to FALSE so we don't try to do any\r
171 -            * further verification or decryption */\r
172 -           params.crypto.verify = FALSE;\r
173 -           params.crypto.decrypt = FALSE;\r
174 -           fprintf (stderr, "Failed to construct gpg context.\n");\r
175 -       }\r
176 -#ifndef GMIME_ATLEAST_26\r
177 -       g_object_unref (session);\r
178 -#endif\r
179 -    }\r
180 -\r
181      config = notmuch_config_open (ctx, NULL, NULL);\r
182      if (config == NULL)\r
183         return 1;\r
184 -- \r
185 1.7.10\r
186 \r