--- /dev/null
+Return-Path: <dkg@fifthhorseman.net>\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 438816DE1B8B\r
+ for <notmuch@notmuchmail.org>; Sun, 31 Jan 2016 12:40:21 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+ 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 ua34pvW6G1oy for <notmuch@notmuchmail.org>;\r
+ Sun, 31 Jan 2016 12:40:19 -0800 (PST)\r
+Received: from che.mayfirst.org (che.mayfirst.org [209.234.253.108])\r
+ by arlo.cworth.org (Postfix) with ESMTP id 9A62B6DE1ACD\r
+ for <notmuch@notmuchmail.org>; Sun, 31 Jan 2016 12:40:09 -0800 (PST)\r
+Received: from fifthhorseman.net (ip-64-134-185-108.public.wayport.net\r
+ [64.134.185.108])\r
+ by che.mayfirst.org (Postfix) with ESMTPSA id E9615F9A4\r
+ for <notmuch@notmuchmail.org>; Sun, 31 Jan 2016 15:40:06 -0500 (EST)\r
+Received: by fifthhorseman.net (Postfix, from userid 1000)\r
+ id 6198E211A2; Sun, 31 Jan 2016 15:40:06 -0500 (EST)\r
+From: Daniel Kahn Gillmor <dkg@fifthhorseman.net>\r
+To: Notmuch Mail <notmuch@notmuchmail.org>\r
+Subject: [PATCH v3 14/16] test indexing cleartext version of delivered\r
+ messages.\r
+Date: Sun, 31 Jan 2016 15:39:59 -0500\r
+Message-Id: <1454272801-23623-15-git-send-email-dkg@fifthhorseman.net>\r
+X-Mailer: git-send-email 2.7.0.rc3\r
+In-Reply-To: <1454272801-23623-1-git-send-email-dkg@fifthhorseman.net>\r
+References: <1454272801-23623-1-git-send-email-dkg@fifthhorseman.net>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.20\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <https://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: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sun, 31 Jan 2016 20:40:21 -0000\r
+\r
+This requires a bit of reorganization:\r
+\r
+ * add_gnupg_home gets moved to test-lib.sh, and\r
+\r
+ * we allow passing --long-arguments to "notmuch new" via\r
+ emacs_fcc_message\r
+---\r
+ test/T350-crypto.sh | 15 ---------------\r
+ test/T357-index-decryption.sh | 42 ++++++++++++++++++++++++++++++++++++++++++\r
+ test/test-lib.sh | 26 +++++++++++++++++++++++++-\r
+ 3 files changed, 67 insertions(+), 16 deletions(-)\r
+ create mode 100755 test/T357-index-decryption.sh\r
+\r
+diff --git a/test/T350-crypto.sh b/test/T350-crypto.sh\r
+index 4bc15bc..50cc526 100755\r
+--- a/test/T350-crypto.sh\r
++++ b/test/T350-crypto.sh\r
+@@ -7,21 +7,6 @@\r
+ test_description='PGP/MIME signature verification and decryption'\r
+ . ./test-lib.sh || exit 1\r
+ \r
+-add_gnupg_home ()\r
+-{\r
+- local output\r
+- [ -d ${GNUPGHOME} ] && return\r
+- mkdir -m 0700 "$GNUPGHOME"\r
+- $GPG --no-tty --import <$TEST_DIRECTORY/gnupg-secret-key.asc >"$GNUPGHOME"/import.log 2>&1\r
+- test_debug "cat $GNUPGHOME/import.log"\r
+- if ($GPG --quick-random --version >/dev/null 2>&1) ; then\r
+- echo quick-random >> "$GNUPGHOME"/gpg.conf\r
+- elif ($GPG --debug-quick-random --version >/dev/null 2>&1) ; then\r
+- echo debug-quick-random >> "$GNUPGHOME"/gpg.conf\r
+- fi\r
+- echo no-emit-version >> "$GNUPGHOME"/gpg.conf\r
+-}\r
+-\r
+ ##################################################\r
+ \r
+ add_gnupg_home\r
+diff --git a/test/T357-index-decryption.sh b/test/T357-index-decryption.sh\r
+new file mode 100755\r
+index 0000000..03e49cc\r
+--- /dev/null\r
++++ b/test/T357-index-decryption.sh\r
+@@ -0,0 +1,42 @@\r
++#!/usr/bin/env bash\r
++\r
++# TODO: test index-decryption-failed\r
++\r
++test_description='indexing decrypted mail'\r
++. ./test-lib.sh || exit 1\r
++\r
++##################################################\r
++\r
++add_gnupg_home\r
++# get key fingerprint\r
++FINGERPRINT=$($GPG --no-tty --list-secret-keys --with-colons --fingerprint | grep '^fpr:' | cut -d: -f10)\r
++\r
++# create a test encrypted message\r
++test_expect_success 'emacs delivery of encrypted message' \\r
++'emacs_fcc_message \\r
++ "test encrypted message for cleartext index 001" \\r
++ "This is a test encrypted message with a wumpus.\n" \\r
++ "(mml-secure-message-encrypt)"'\r
++\r
++test_begin_subtest "search for unindexed cleartext"\r
++output=$(notmuch search wumpus)\r
++expected=''\r
++test_expect_equal \\r
++ "$output" \\r
++ "$expected"\r
++\r
++# create a test encrypted message that is indexed in the clear\r
++test_expect_success 'emacs delivery of encrypted message' \\r
++'emacs_fcc_message --try-decrypt \\r
++ "test encrypted message for cleartext index 002" \\r
++ "This is a test encrypted message with a wumpus.\n" \\r
++ "(mml-secure-message-encrypt)"'\r
++\r
++test_begin_subtest "emacs delivery of encrypted message, indexed cleartext"\r
++output=$(notmuch search wumpus)\r
++expected='thread:0000000000000002 2000-01-01 [1/1] Notmuch Test Suite; test encrypted message for cleartext index 002 (encrypted inbox index-decrypted)'\r
++test_expect_equal \\r
++ "$output" \\r
++ "$expected"\r
++\r
++test_done\r
+diff --git a/test/test-lib.sh b/test/test-lib.sh\r
+index 8c1f3c6..1fea6c7 100644\r
+--- a/test/test-lib.sh\r
++++ b/test/test-lib.sh\r
+@@ -92,6 +92,21 @@ else\r
+ GPG=gpg\r
+ fi\r
+ \r
++add_gnupg_home ()\r
++{\r
++ local output\r
++ [ -d ${GNUPGHOME} ] && return\r
++ mkdir -m 0700 "$GNUPGHOME"\r
++ $GPG --no-tty --import <$TEST_DIRECTORY/gnupg-secret-key.asc >"$GNUPGHOME"/import.log 2>&1\r
++ test_debug "cat $GNUPGHOME/import.log"\r
++ if ($GPG --quick-random --version >/dev/null 2>&1) ; then\r
++ echo quick-random >> "$GNUPGHOME"/gpg.conf\r
++ elif ($GPG --debug-quick-random --version >/dev/null 2>&1) ; then\r
++ echo debug-quick-random >> "$GNUPGHOME"/gpg.conf\r
++ fi\r
++ echo no-emit-version >> "$GNUPGHOME"/gpg.conf\r
++}\r
++\r
+ # Convenience\r
+ #\r
+ # A regexp to match 5 and 40 hexdigits\r
+@@ -514,8 +529,17 @@ emacs_deliver_message ()\r
+ # Accepts arbitrary extra emacs/elisp functions to modify the message\r
+ # before sending, which is useful to doing things like attaching files\r
+ # to the message and encrypting/signing.\r
++#\r
++# If any GNU-style long-arguments (like --quiet or --try-decrypt) are\r
++# at the head of the argument list, they are sent directly to "notmuch\r
++# new" after message delivery\r
+ emacs_fcc_message ()\r
+ {\r
++ local nmn_args=''\r
++ while [[ "$1" =~ ^-- ]]; do\r
++ nmn_args="$nmn_args $1"\r
++ shift\r
++ done\r
+ local subject="$1"\r
+ local body="$2"\r
+ shift 2\r
+@@ -534,7 +558,7 @@ emacs_fcc_message ()\r
+ (insert \"${body}\")\r
+ $@\r
+ (notmuch-mua-send-and-exit))" || return 1\r
+- notmuch new >/dev/null\r
++ notmuch new $nmn_args >/dev/null\r
+ }\r
+ \r
+ # Generate a corpus of email and add it to the database.\r
+-- \r
+2.7.0.rc3\r
+\r