1 Return-Path: <jani@nikula.org>
\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 6713A431FAF
\r
6 for <notmuch@notmuchmail.org>; Sun, 3 Mar 2013 06:10:16 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5
\r
12 tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 pVAHfcJg8n92 for <notmuch@notmuchmail.org>;
\r
16 Sun, 3 Mar 2013 06:10:16 -0800 (PST)
\r
17 Received: from mail-lb0-f177.google.com (mail-lb0-f177.google.com
\r
18 [209.85.217.177]) (using TLSv1 with cipher RC4-SHA (128/128 bits))
\r
19 (No client certificate requested)
\r
20 by olra.theworths.org (Postfix) with ESMTPS id AC262431FAE
\r
21 for <notmuch@notmuchmail.org>; Sun, 3 Mar 2013 06:10:15 -0800 (PST)
\r
22 Received: by mail-lb0-f177.google.com with SMTP id go11so3260458lbb.22
\r
23 for <notmuch@notmuchmail.org>; Sun, 03 Mar 2013 06:10:14 -0800 (PST)
\r
24 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
\r
25 d=google.com; s=20120113;
\r
26 h=x-received:from:to:cc:subject:date:message-id:x-mailer
\r
27 :x-gm-message-state;
\r
28 bh=e83dNHPXuHgeFbJGPujqQUwwzo20YasCYiCl61dPAF4=;
\r
29 b=gA5eA5FoElm0VkVVGzY/6NUz3zerEotIVC7+WcLg69uYwZEN9hsywNhxzn3fNHGsi9
\r
30 6I7hGiYipiN26ujtSfWXMtRyak68Qx9MOxVyjuFgeQPZz4rI+8gEm896u3CXxb6RmvtJ
\r
31 Ww6jB3+R0La3oxb7tvE2v9NEJd9vhBRPVzM22VUJZgNgtOXMrYeH/XZ6vTezv3zFL6yo
\r
32 yuz/hikLum/0LAtm3KPlmJstXR/OXEVTnk7I6n6OjLx94M+aBGZQ3vD7ufkHoA9nRVxL
\r
33 rh5uq9mRZtB2ydD1Ibsm5H5/KiQaKFFs83mtyChEiItkD1KM+it987imwjxxkg4rW+Do
\r
35 X-Received: by 10.112.100.41 with SMTP id ev9mr3271963lbb.34.1362319813930;
\r
36 Sun, 03 Mar 2013 06:10:13 -0800 (PST)
\r
37 Received: from localhost (dsl-hkibrasgw4-50df51-27.dhcp.inet.fi.
\r
39 by mx.google.com with ESMTPS id e9sm6241164lbz.1.2013.03.03.06.10.11
\r
40 (version=TLSv1.2 cipher=RC4-SHA bits=128/128);
\r
41 Sun, 03 Mar 2013 06:10:12 -0800 (PST)
\r
42 From: Jani Nikula <jani@nikula.org>
\r
43 To: notmuch@notmuchmail.org
\r
44 Subject: [PATCH 1/2] cli: crypto: abstract gpg context creation for clarity
\r
45 Date: Sun, 3 Mar 2013 16:10:10 +0200
\r
47 <a9f12ba474fc51df71e2fd2b7a20a8d101729c6e.1362319765.git.jani@nikula.org>
\r
48 X-Mailer: git-send-email 1.7.10.4
\r
50 ALoCoQlog9iN+lrzE0gYTv3prokS35bH93ta5TdhOLSwRyvj3fd3xI/usvxVXbrkN6TsMUsj9y1/
\r
51 X-BeenThere: notmuch@notmuchmail.org
\r
52 X-Mailman-Version: 2.1.13
\r
54 List-Id: "Use and development of the notmuch mail system."
\r
55 <notmuch.notmuchmail.org>
\r
56 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
57 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
58 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
59 List-Post: <mailto:notmuch@notmuchmail.org>
\r
60 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
61 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
62 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
63 X-List-Received-Date: Sun, 03 Mar 2013 14:10:16 -0000
\r
65 The code filled with #ifdef GMIME_ATLEAST_26 is difficult to
\r
66 read. Abstract gpg context creation into a function, with separate
\r
67 implementations for GMime 2.4 and 2.6, to clarify the code.
\r
69 There should be no functional changes.
\r
71 crypto.c | 60 +++++++++++++++++++++++++++++++++++++++++-------------------
\r
72 1 file changed, 41 insertions(+), 19 deletions(-)
\r
74 diff --git a/crypto.c b/crypto.c
\r
75 index cb361e1..7d1dfe4 100644
\r
80 #include "notmuch-client.h"
\r
82 +#ifdef GMIME_ATLEAST_26
\r
83 +static notmuch_crypto_context_t *
\r
84 +create_gpg_context (void)
\r
86 + notmuch_crypto_context_t *gpgctx;
\r
88 + /* TODO: GMimePasswordRequestFunc */
\r
89 + gpgctx = g_mime_gpg_context_new (NULL, "gpg");
\r
93 + g_mime_gpg_context_set_use_agent ((GMimeGpgContext *) gpgctx, TRUE);
\r
94 + g_mime_gpg_context_set_always_trust ((GMimeGpgContext *) gpgctx, FALSE);
\r
99 +static notmuch_crypto_context_t *
\r
100 +create_gpg_context (void)
\r
102 + GMimeSession *session;
\r
103 + notmuch_crypto_context_t *gpgctx;
\r
105 + session = g_object_new (g_mime_session_get_type (), NULL);
\r
106 + gpgctx = g_mime_gpg_context_new (session, "gpg");
\r
107 + g_object_unref (session);
\r
112 + g_mime_gpg_context_set_always_trust ((GMimeGpgContext *) gpgctx, FALSE);
\r
118 /* for the specified protocol return the context pointer (initializing
\r
120 notmuch_crypto_context_t *
\r
121 @@ -33,28 +69,14 @@ notmuch_crypto_get_context (notmuch_crypto_t *crypto, const char *protocol)
\r
122 * parameter names as defined in this document are
\r
123 * case-insensitive." Thus, we use strcasecmp for the protocol.
\r
125 - if ((strcasecmp (protocol, "application/pgp-signature") == 0)
\r
126 - || (strcasecmp (protocol, "application/pgp-encrypted") == 0)) {
\r
127 - if (!crypto->gpgctx) {
\r
128 -#ifdef GMIME_ATLEAST_26
\r
129 - /* TODO: GMimePasswordRequestFunc */
\r
130 - crypto->gpgctx = g_mime_gpg_context_new (NULL, "gpg");
\r
132 - GMimeSession* session = g_object_new (g_mime_session_get_type(), NULL);
\r
133 - crypto->gpgctx = g_mime_gpg_context_new (session, "gpg");
\r
134 - g_object_unref (session);
\r
136 - if (crypto->gpgctx) {
\r
137 -#ifdef GMIME_ATLEAST_26
\r
138 - g_mime_gpg_context_set_use_agent ((GMimeGpgContext*) crypto->gpgctx, TRUE);
\r
140 - g_mime_gpg_context_set_always_trust ((GMimeGpgContext*) crypto->gpgctx, FALSE);
\r
142 + if (strcasecmp (protocol, "application/pgp-signature") == 0 ||
\r
143 + strcasecmp (protocol, "application/pgp-encrypted") == 0) {
\r
144 + if (! crypto->gpgctx) {
\r
145 + crypto->gpgctx = create_gpg_context ();
\r
146 + if (! crypto->gpgctx)
\r
147 fprintf (stderr, "Failed to construct gpg context.\n");
\r
150 cryptoctx = crypto->gpgctx;
\r
153 fprintf (stderr, "Unknown or unsupported cryptographic protocol.\n");
\r