--- /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 EF9FE6DE1603\r
+ for <notmuch@notmuchmail.org>; Wed, 9 Dec 2015 19:40:13 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.033\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.033 tagged_above=-999 required=5\r
+ tests=[AWL=-0.033] 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 l707XKEmuUEW for <notmuch@notmuchmail.org>;\r
+ Wed, 9 Dec 2015 19:40:12 -0800 (PST)\r
+Received: from che.mayfirst.org (che.mayfirst.org [209.234.253.108])\r
+ by arlo.cworth.org (Postfix) with ESMTP id F3EF46DE1811\r
+ for <notmuch@notmuchmail.org>; Wed, 9 Dec 2015 19:40:05 -0800 (PST)\r
+Received: from fifthhorseman.net (unknown [38.109.115.130])\r
+ by che.mayfirst.org (Postfix) with ESMTPSA id 7A89AF98C\r
+ for <notmuch@notmuchmail.org>; Wed, 9 Dec 2015 22:40:04 -0500 (EST)\r
+Received: by fifthhorseman.net (Postfix, from userid 1000)\r
+ id C683E212DC; Wed, 9 Dec 2015 22:40:03 -0500 (EST)\r
+From: Daniel Kahn Gillmor <dkg@fifthhorseman.net>\r
+To: Notmuch Mail <notmuch@notmuchmail.org>\r
+Subject: [PATCH 9/9] add --try-decrypt to notmuch new\r
+Date: Wed, 9 Dec 2015 22:39:46 -0500\r
+Message-Id: <1449718786-28000-10-git-send-email-dkg@fifthhorseman.net>\r
+X-Mailer: git-send-email 2.6.2\r
+In-Reply-To: <1449718786-28000-1-git-send-email-dkg@fifthhorseman.net>\r
+References: <1449718786-28000-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: Thu, 10 Dec 2015 03:40:14 -0000\r
+\r
+Try to decrypt newly-discovered messages while indexing them.\r
+\r
+If ~/.notmuch-config contains crypto.gpg_path, and gpg is needed, it\r
+will be used to find gpg while indexing.\r
+---\r
+ completion/notmuch-completion.bash | 2 +-\r
+ doc/man1/notmuch-new.rst | 10 ++++++++++\r
+ notmuch-new.c | 18 +++++++++++++++++-\r
+ 3 files changed, 28 insertions(+), 2 deletions(-)\r
+\r
+diff --git a/completion/notmuch-completion.bash b/completion/notmuch-completion.bash\r
+index 4bc9040..214f776 100644\r
+--- a/completion/notmuch-completion.bash\r
++++ b/completion/notmuch-completion.bash\r
+@@ -247,7 +247,7 @@ _notmuch_new()\r
+ \r
+ case "${cur}" in\r
+ -*)\r
+- local options="--no-hooks --quiet ${_notmuch_shared_options}"\r
++ local options="--no-hooks --try-decrypt --quiet ${_notmuch_shared_options}"\r
+ compopt -o nospace\r
+ COMPREPLY=( $(compgen -W "${options}" -- ${cur}) )\r
+ ;;\r
+diff --git a/doc/man1/notmuch-new.rst b/doc/man1/notmuch-new.rst\r
+index 787ed78..cf08021 100644\r
+--- a/doc/man1/notmuch-new.rst\r
++++ b/doc/man1/notmuch-new.rst\r
+@@ -43,6 +43,16 @@ Supported options for **new** include\r
+ ``--quiet``\r
+ Do not print progress or results.\r
+ \r
++ ``--try-decrypt``\r
++\r
++ For each message, if it is encrypted, try to decrypt it while\r
++ indexing. If decryption is successful, index the cleartext\r
++ itself. Be aware that the index is likely sufficient to\r
++ reconstruct the cleartext of the message itself, so please\r
++ ensure that the notmuch message index is adequately\r
++ protected. DO NOT USE THIS FLAG without considering the\r
++ security of your index.\r
++\r
+ SEE ALSO\r
+ ========\r
+ \r
+diff --git a/notmuch-new.c b/notmuch-new.c\r
+index d45d0af..e5903b8 100644\r
+--- a/notmuch-new.c\r
++++ b/notmuch-new.c\r
+@@ -49,6 +49,7 @@ typedef struct {\r
+ size_t new_tags_length;\r
+ const char **new_ignore;\r
+ size_t new_ignore_length;\r
++ notmuch_bool_t try_decrypt;\r
+ \r
+ int total_files;\r
+ int processed_files;\r
+@@ -260,7 +261,10 @@ add_file (notmuch_database_t *notmuch, const char *filename,\r
+ if (status)\r
+ goto DONE;\r
+ \r
+- status = notmuch_database_add_message (notmuch, filename, &message);\r
++ if (state->try_decrypt)\r
++ status = notmuch_database_add_message_try_decrypt (notmuch, filename, &message);\r
++ else\r
++ status = notmuch_database_add_message (notmuch, filename, &message);\r
+ switch (status) {\r
+ /* Success. */\r
+ case NOTMUCH_STATUS_SUCCESS:\r
+@@ -930,6 +934,7 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])\r
+ add_files_state_t add_files_state = {\r
+ .verbosity = VERBOSITY_NORMAL,\r
+ .debug = FALSE,\r
++ .try_decrypt = FALSE,\r
+ .output_is_a_tty = isatty (fileno (stdout)),\r
+ };\r
+ struct timeval tv_start;\r
+@@ -951,6 +956,7 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])\r
+ { NOTMUCH_OPT_BOOLEAN, &verbose, "verbose", 'v', 0 },\r
+ { NOTMUCH_OPT_BOOLEAN, &add_files_state.debug, "debug", 'd', 0 },\r
+ { NOTMUCH_OPT_BOOLEAN, &no_hooks, "no-hooks", 'n', 0 },\r
++ { NOTMUCH_OPT_BOOLEAN, &add_files_state.try_decrypt, "try-decrypt", 0, 0 },\r
+ { NOTMUCH_OPT_INHERIT, (void *) ¬much_shared_options, NULL, 0, 0 },\r
+ { 0, 0, 0, 0, 0 }\r
+ };\r
+@@ -1068,6 +1074,16 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])\r
+ if (notmuch == NULL)\r
+ return EXIT_FAILURE;\r
+ \r
++ if (add_files_state.try_decrypt) {\r
++ const char* gpg_path = notmuch_config_get_crypto_gpg_path (config);\r
++ status = notmuch_database_set_gpg_path(notmuch, gpg_path);\r
++ if (status)\r
++ fprintf (stderr, "Warning: failed to set database gpg_path to '%s' (%s)\n",\r
++ gpg_path ? gpg_path : "(NULL)",\r
++ notmuch_status_to_string (status));\r
++ }\r
++\r
++ \r
+ /* Set up our handler for SIGINT. We do this after having\r
+ * potentially done a database upgrade we this interrupt handler\r
+ * won't support. */\r
+-- \r
+2.6.2\r
+\r