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