--- /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 arlo.cworth.org (Postfix) with ESMTP id 7FCD16DE18FE\r
+ for <notmuch@notmuchmail.org>; Sun, 16 Aug 2015 10:43:24 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.126\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.126 tagged_above=-999 required=5 tests=[AWL=0.116, \r
+ T_HEADER_FROM_DIFFERENT_DOMAINS=0.01] autolearn=disabled\r
+Received: from arlo.cworth.org ([127.0.0.1])\r
+ by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id aDsRWghoG00M for <notmuch@notmuchmail.org>;\r
+ Sun, 16 Aug 2015 10:43:22 -0700 (PDT)\r
+Received: from gitolite.debian.net (gitolite.debian.net [87.98.215.224])\r
+ by arlo.cworth.org (Postfix) with ESMTPS id 5DEC06DE17FE\r
+ for <notmuch@notmuchmail.org>; Sun, 16 Aug 2015 10:43:20 -0700 (PDT)\r
+Received: from remotemail by gitolite.debian.net with local (Exim 4.80)\r
+ (envelope-from <bremner@tesseract.cs.unb.ca>)\r
+ id 1ZR1wK-0003by-IW; Sun, 16 Aug 2015 17:41:48 +0000\r
+Received: (nullmailer pid 26317 invoked by uid 1000); Sun, 16 Aug 2015\r
+ 17:41:28 -0000\r
+From: David Bremner <david@tethera.net>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 6/8] cli: crypto: S/MIME verification support\r
+Date: Sun, 16 Aug 2015 19:41:14 +0200\r
+Message-Id: <1439746876-23654-7-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 2.5.0\r
+In-Reply-To: <1439746876-23654-1-git-send-email-david@tethera.net>\r
+References: <54CA467B.30408@gnome.org>\r
+ <1439746876-23654-1-git-send-email-david@tethera.net>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.18\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, 16 Aug 2015 17:43:24 -0000\r
+\r
+From: Jani Nikula <jani@nikula.org>\r
+\r
+notmuch-show --verify will now also process S/MIME multiparts if\r
+encountered. Requires gmime-2.6 and gpgsm.\r
+\r
+Based on work by Jameson Graef Rollins <jrollins@finestructure.net>.\r
+---\r
+ crypto.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++\r
+ notmuch-client.h | 7 +++++--\r
+ test/T355-smime.sh | 1 -\r
+ 3 files changed, 55 insertions(+), 3 deletions(-)\r
+\r
+diff --git a/crypto.c b/crypto.c\r
+index 11c167e..ce683d2 100644\r
+--- a/crypto.c\r
++++ b/crypto.c\r
+@@ -43,6 +43,51 @@ create_gpg_context (notmuch_crypto_t *crypto)\r
+ return gpgctx;\r
+ }\r
+ \r
++/* Create a PKCS7 context (GMime 2.6) */\r
++static notmuch_crypto_context_t *\r
++create_pkcs7_context (notmuch_crypto_t *crypto)\r
++{\r
++ notmuch_crypto_context_t *pkcs7ctx;\r
++\r
++ if (crypto->pkcs7ctx)\r
++ return crypto->pkcs7ctx;\r
++\r
++ /* TODO: GMimePasswordRequestFunc */\r
++ pkcs7ctx = g_mime_pkcs7_context_new (NULL);\r
++ if (! pkcs7ctx) {\r
++ fprintf (stderr, "Failed to construct pkcs7 context.\n");\r
++ return NULL;\r
++ }\r
++ crypto->pkcs7ctx = pkcs7ctx;\r
++\r
++ g_mime_pkcs7_context_set_always_trust ((GMimePkcs7Context *) pkcs7ctx,\r
++ FALSE);\r
++\r
++ return pkcs7ctx;\r
++}\r
++\r
++static const struct {\r
++ const char *protocol;\r
++ notmuch_crypto_context_t *(*get_context) (notmuch_crypto_t *crypto);\r
++} protocols[] = {\r
++ {\r
++ .protocol = "application/pgp-signature",\r
++ .get_context = create_gpg_context,\r
++ },\r
++ {\r
++ .protocol = "application/pgp-encrypted",\r
++ .get_context = create_gpg_context,\r
++ },\r
++ {\r
++ .protocol = "application/pkcs7-signature",\r
++ .get_context = create_pkcs7_context,\r
++ },\r
++ {\r
++ .protocol = "application/x-pkcs7-signature",\r
++ .get_context = create_pkcs7_context,\r
++ },\r
++};\r
++\r
+ /* for the specified protocol return the context pointer (initializing\r
+ * if needed) */\r
+ notmuch_crypto_context_t *\r
+@@ -81,5 +126,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 1f82656..774b620 100644\r
+--- a/notmuch-client.h\r
++++ b/notmuch-client.h\r
+@@ -31,6 +31,8 @@\r
+ #include <gmime/gmime.h>\r
+ \r
+ typedef GMimeCryptoContext notmuch_crypto_context_t;\r
++/* This is automatically included only since gmime 2.6.10 */\r
++#include <gmime/gmime-pkcs7-context.h>\r
+ \r
+ #include "notmuch.h"\r
+ \r
+@@ -69,6 +71,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
+ const char *gpgpath;\r
+@@ -406,8 +409,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
+diff --git a/test/T355-smime.sh b/test/T355-smime.sh\r
+index b3cc76e..caedf5e 100755\r
+--- a/test/T355-smime.sh\r
++++ b/test/T355-smime.sh\r
+@@ -56,7 +56,6 @@ EOF\r
+ test_expect_equal_file OUTPUT EXPECTED\r
+ \r
+ test_begin_subtest "signature verification (notmuch CLI)"\r
+-test_subtest_known_broken\r
+ output=$(notmuch show --format=json --verify subject:"test signed message 001" \\r
+ | notmuch_json_show_sanitize \\r
+ | sed -e 's|"created": [1234567890]*|"created": 946728000|' \\r
+-- \r
+2.5.0\r
+\r