--- /dev/null
+Return-Path: <bremner@tesseract.cs.unb.ca>\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 83E2A431FD9\r
+ for <notmuch@notmuchmail.org>; Sun, 18 Jan 2015 00:03:19 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 2.438\r
+X-Spam-Level: **\r
+X-Spam-Status: No, score=2.438 tagged_above=-999 required=5\r
+ tests=[DNS_FROM_AHBL_RHSBL=2.438] 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 NQEfnsku6wXc for <notmuch@notmuchmail.org>;\r
+ Sun, 18 Jan 2015 00:03:18 -0800 (PST)\r
+Received: from yantan.tethera.net (yantan.tethera.net [199.188.72.155])\r
+ (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 0C9FA431FDF\r
+ for <notmuch@notmuchmail.org>; Sun, 18 Jan 2015 00:03:12 -0800 (PST)\r
+Received: from remotemail by yantan.tethera.net with local (Exim 4.80)\r
+ (envelope-from <bremner@tesseract.cs.unb.ca>)\r
+ id 1YCkp7-0004qT-A5; Sun, 18 Jan 2015 04:03:05 -0400\r
+Received: (nullmailer pid 18923 invoked by uid 1000); Sun, 18 Jan 2015\r
+ 08:02:54 -0000\r
+From: David Bremner <david@tethera.net>\r
+To: notmuch@notmuchmail.org\r
+Subject: [Patch v4 2/5] cli: S/MIME verification/decryption support\r
+Date: Sun, 18 Jan 2015 09:02:44 +0100\r
+Message-Id: <1421568167-18683-3-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 2.1.4\r
+In-Reply-To: <1421568167-18683-1-git-send-email-david@tethera.net>\r
+References: <1421568167-18683-1-git-send-email-david@tethera.net>\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 08:03:19 -0000\r
+\r
+From: Jameson Graef Rollins <jrollins@finestructure.net>\r
+\r
+The notmuch-show flags --decrypt and --verify will now also process\r
+S/MIME multiparts if encountered. Requires gmime-2.6 and gpgsm.\r
+---\r
+ crypto.c | 20 ++++++++++++++++++++\r
+ notmuch-client.h | 5 +++--\r
+ 2 files changed, 23 insertions(+), 2 deletions(-)\r
+\r
+diff --git a/crypto.c b/crypto.c\r
+index 6f4a6db..d66aa66 100644\r
+--- a/crypto.c\r
++++ b/crypto.c\r
+@@ -88,6 +88,21 @@ notmuch_crypto_get_context (notmuch_crypto_t *crypto, const char *protocol)\r
+ fprintf (stderr, "Failed to construct gpg context.\n");\r
+ }\r
+ cryptoctx = crypto->gpgctx;\r
++#ifdef GMIME_ATLEAST_26\r
++ } else if ((strcasecmp (protocol, "application/pkcs7-signature") == 0)\r
++ || (strcasecmp (protocol, "application/x-pkcs7-signature") == 0)\r
++ || (strcasecmp (protocol, "application/pkcs7-encrypted") == 0)) {\r
++ if (! crypto->pkcs7ctx) {\r
++ /* TODO: GMimePasswordRequestFunc */\r
++ crypto->pkcs7ctx = g_mime_pkcs7_context_new (NULL);\r
++ if (crypto->pkcs7ctx) {\r
++ g_mime_pkcs7_context_set_always_trust ((GMimePkcs7Context*) crypto->pkcs7ctx, FALSE);\r
++ } else {\r
++ fprintf (stderr, "Failed to construct pkcs7 context.\n");\r
++ }\r
++ }\r
++ cryptoctx = crypto->pkcs7ctx;\r
++#endif\r
+ } else {\r
+ fprintf (stderr, "Unknown or unsupported cryptographic protocol.\n");\r
+ }\r
+@@ -103,5 +118,10 @@ notmuch_crypto_cleanup (notmuch_crypto_t *crypto)\r
+ crypto->gpgctx = NULL;\r
+ }\r
+ \r
++ if (crypto->pkcs7ctx) {\r
++ g_object_unref (crypto->pkcs7ctx);\r
++ crypto->pkcs7ctx = NULL;\r
++ }\r
++\r
+ return 0;\r
+ }\r
+diff --git a/notmuch-client.h b/notmuch-client.h\r
+index 5e0d475..986f6cd 100644\r
+--- a/notmuch-client.h\r
++++ b/notmuch-client.h\r
+@@ -78,6 +78,7 @@ typedef struct notmuch_show_format {\r
+ \r
+ typedef struct notmuch_crypto {\r
+ notmuch_crypto_context_t* gpgctx;\r
++ notmuch_crypto_context_t* pkcs7ctx;\r
+ notmuch_bool_t verify;\r
+ notmuch_bool_t decrypt;\r
+ } notmuch_crypto_t;\r
+@@ -414,8 +415,8 @@ struct mime_node {\r
+ /* Construct a new MIME node pointing to the root message part of\r
+ * message. If crypto->verify is true, signed child parts will be\r
+ * verified. If crypto->decrypt is true, encrypted child parts will be\r
+- * decrypted. If crypto->gpgctx is NULL, it will be lazily\r
+- * initialized.\r
++ * decrypted. If the crypto contexts (crypto->gpgctx or\r
++ * crypto->pkcs7) are NULL, they will be lazily initialized.\r
+ *\r
+ * Return value:\r
+ *\r
+-- \r
+2.1.4\r
+\r