[PATCH 1/3] crypto: refactor context creation to facilitate further work
authorJani Nikula <jani@nikula.org>
Sun, 18 Jan 2015 10:45:51 +0000 (12:45 +0200)
committerW. Trevor King <wking@tremily.us>
Sat, 20 Aug 2016 21:47:32 +0000 (14:47 -0700)
73/aaed0b94ab2b1ecbf4811824d0bbf3691e5ba0 [new file with mode: 0644]

diff --git a/73/aaed0b94ab2b1ecbf4811824d0bbf3691e5ba0 b/73/aaed0b94ab2b1ecbf4811824d0bbf3691e5ba0
new file mode 100644 (file)
index 0000000..5cf7bcd
--- /dev/null
@@ -0,0 +1,147 @@
+Return-Path: <jani@nikula.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id A3902431FDD\r
+       for <notmuch@notmuchmail.org>; Sun, 18 Jan 2015 02:45:48 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 1.738\r
+X-Spam-Level: *\r
+X-Spam-Status: No, score=1.738 tagged_above=-999 required=5\r
+       tests=[DNS_FROM_AHBL_RHSBL=2.438, RCVD_IN_DNSWL_LOW=-0.7]\r
+       autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id VVjYkxWf2gXE for <notmuch@notmuchmail.org>;\r
+       Sun, 18 Jan 2015 02:45:45 -0800 (PST)\r
+Received: from mail-wi0-f180.google.com (mail-wi0-f180.google.com\r
+       [209.85.212.180]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id E2A6F431FB6\r
+       for <notmuch@notmuchmail.org>; Sun, 18 Jan 2015 02:45:44 -0800 (PST)\r
+Received: by mail-wi0-f180.google.com with SMTP id bs8so11170668wib.1\r
+       for <notmuch@notmuchmail.org>; Sun, 18 Jan 2015 02:45:43 -0800 (PST)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+       d=1e100.net; s=20130820;\r
+       h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\r
+       :references:in-reply-to:references;\r
+       bh=uBZu6WMShVr+8R9ONNtyHu8Edtyja5mRtLal+cUwoDA=;\r
+       b=i+E3QpXBK1xKvlp2JfDJ/Uyv2vksHOr7hp/7cpfU2SVsNs/qNP3PUiSuM03VNF3dmD\r
+       +8DlsxzYQuocdPC4zaT1bS1gpahcusDnyR/XP7fsoxFLBI/2WerRmE0Ty58PTBlRHLKd\r
+       m5stb1ISE9M+BwDRvkdCT93rPXHNwY0wUol0B/FI7lnz43f4M4bdcDTjremBjJbVK8+c\r
+       Ri0O6l5VTFODYzg1Gg6uJVw1R+EU/+Dh82QAbw7b1zEi/nHp5x4PwxC4kmrv3C7bjFYH\r
+       34GNnVWiOUO04OMRXX+ezHaLvsP0VT8pNNw8MauXqN4QaB0X6hd1KdKddY62LBD2ddY3\r
+       p1ZQ==\r
+X-Gm-Message-State:\r
+ ALoCoQkt1wtb0YEhZ/k7iy6NWzFeHiIxoyxxB6S/cd7YVMLXKSTqJs9hAIs7HOcxAJ0YAYQRGoPj\r
+X-Received: by 10.194.88.131 with SMTP id bg3mr45711384wjb.99.1421577943654;\r
+       Sun, 18 Jan 2015 02:45:43 -0800 (PST)\r
+Received: from localhost (mobile-internet-bcee14-89.dhcp.inet.fi.\r
+       [188.238.20.89]) by mx.google.com with ESMTPSA id\r
+       ww4sm12903629wjc.47.2015.01.18.02.45.42\r
+       (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
+       Sun, 18 Jan 2015 02:45:43 -0800 (PST)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: david@tethera.net,\r
+       notmuch@notmuchmail.org\r
+Subject: [PATCH 1/3] crypto: refactor context creation to facilitate further\r
+       work\r
+Date: Sun, 18 Jan 2015 12:45:51 +0200\r
+Message-Id:\r
+ <760fe8048f9f3a641297a40ed129abc6695b6b94.1421577605.git.jani@nikula.org>\r
+X-Mailer: git-send-email 2.1.4\r
+In-Reply-To: <cover.1421577605.git.jani@nikula.org>\r
+References: <1421568167-18683-3-git-send-email-david@tethera.net>\r
+       <cover.1421577605.git.jani@nikula.org>\r
+In-Reply-To: <cover.1421577605.git.jani@nikula.org>\r
+References: <cover.1421577605.git.jani@nikula.org>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sun, 18 Jan 2015 10:45:48 -0000\r
+\r
+---\r
+ crypto.c | 27 +++++++++++++++++----------\r
+ 1 file changed, 17 insertions(+), 10 deletions(-)\r
+\r
+diff --git a/crypto.c b/crypto.c\r
+index 6f4a6db9d0f1..7cd7b69d1221 100644\r
+--- a/crypto.c\r
++++ b/crypto.c\r
+@@ -24,14 +24,20 @@\r
\r
+ /* Create a GPG context (GMime 2.6) */\r
+ static notmuch_crypto_context_t *\r
+-create_gpg_context (void)\r
++create_gpg_context (notmuch_crypto_t *crypto)\r
+ {\r
+     notmuch_crypto_context_t *gpgctx;\r
\r
++    if (crypto->gpgctx)\r
++      return crypto->gpgctx;\r
++\r
+     /* TODO: GMimePasswordRequestFunc */\r
+     gpgctx = g_mime_gpg_context_new (NULL, "gpg");\r
+-    if (! gpgctx)\r
++    if (! gpgctx) {\r
++      fprintf (stderr, "Failed to construct gpg context.\n");\r
+       return NULL;\r
++    }\r
++    crypto->gpgctx = gpgctx;\r
\r
+     g_mime_gpg_context_set_use_agent ((GMimeGpgContext *) gpgctx, TRUE);\r
+     g_mime_gpg_context_set_always_trust ((GMimeGpgContext *) gpgctx, FALSE);\r
+@@ -43,17 +49,23 @@ create_gpg_context (void)\r
\r
+ /* Create a GPG context (GMime 2.4) */\r
+ static notmuch_crypto_context_t *\r
+-create_gpg_context (void)\r
++create_gpg_context (notmuch_crypto_t *crypto)\r
+ {\r
+     GMimeSession *session;\r
+     notmuch_crypto_context_t *gpgctx;\r
\r
++    if (crypto->gpgctx)\r
++      return crypto->gpgctx;\r
++\r
+     session = g_object_new (g_mime_session_get_type (), NULL);\r
+     gpgctx = g_mime_gpg_context_new (session, "gpg");\r
+     g_object_unref (session);\r
\r
+-    if (! gpgctx)\r
++    if (! gpgctx) {\r
++      fprintf (stderr, "Failed to construct gpg context.\n");\r
+       return NULL;\r
++    }\r
++    crypto->gpgctx = gpgctx;\r
\r
+     g_mime_gpg_context_set_always_trust ((GMimeGpgContext *) gpgctx, FALSE);\r
\r
+@@ -82,12 +94,7 @@ notmuch_crypto_get_context (notmuch_crypto_t *crypto, const char *protocol)\r
+      */\r
+     if (strcasecmp (protocol, "application/pgp-signature") == 0 ||\r
+       strcasecmp (protocol, "application/pgp-encrypted") == 0) {\r
+-      if (! crypto->gpgctx) {\r
+-          crypto->gpgctx = create_gpg_context ();\r
+-          if (! crypto->gpgctx)\r
+-              fprintf (stderr, "Failed to construct gpg context.\n");\r
+-      }\r
+-      cryptoctx = crypto->gpgctx;\r
++      cryptoctx = create_gpg_context (crypto);\r
+     } else {\r
+       fprintf (stderr, "Unknown or unsupported cryptographic protocol.\n");\r
+     }\r
+-- \r
+2.1.4\r
+\r