From: Daniel Kahn Gillmor Date: Fri, 8 Jul 2016 09:27:23 +0000 (+0200) Subject: [PATCH v4 12/16] add --try-decrypt to notmuch new X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=5aabec15a93f4b47793df149153fc1cb3261f604;p=notmuch-archives.git [PATCH v4 12/16] add --try-decrypt to notmuch new --- diff --git a/ad/fa71904083e98d6694dfdeff8f385b063d7bad b/ad/fa71904083e98d6694dfdeff8f385b063d7bad new file mode 100644 index 000000000..f41a89596 --- /dev/null +++ b/ad/fa71904083e98d6694dfdeff8f385b063d7bad @@ -0,0 +1,178 @@ +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 6F9926DE0A63 + for ; Fri, 8 Jul 2016 03:14:16 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at cworth.org +X-Spam-Flag: NO +X-Spam-Score: 0.036 +X-Spam-Level: +X-Spam-Status: No, score=0.036 tagged_above=-999 required=5 tests=[AWL=0.036] + 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 ttruo4f05ncQ for ; + Fri, 8 Jul 2016 03:14:08 -0700 (PDT) +Received: from che.mayfirst.org (che.mayfirst.org [162.247.75.118]) + by arlo.cworth.org (Postfix) with ESMTP id 09D376DE091C + for ; Fri, 8 Jul 2016 03:13:16 -0700 (PDT) +Received: from fifthhorseman.net (unknown [88.128.80.54]) + by che.mayfirst.org (Postfix) with ESMTPSA id 488CCF98B + for ; Fri, 8 Jul 2016 06:13:15 -0400 (EDT) +Received: by fifthhorseman.net (Postfix, from userid 1000) + id BCBFE21575; Fri, 8 Jul 2016 11:27:34 +0200 (CEST) +From: Daniel Kahn Gillmor +To: Notmuch Mail +Subject: [PATCH v4 12/16] add --try-decrypt to notmuch new +Date: Fri, 8 Jul 2016 11:27:23 +0200 +Message-Id: <1467970047-8013-13-git-send-email-dkg@fifthhorseman.net> +X-Mailer: git-send-email 2.8.1 +In-Reply-To: <1467970047-8013-1-git-send-email-dkg@fifthhorseman.net> +References: <1467970047-8013-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: Fri, 08 Jul 2016 10:14:16 -0000 + +Try to decrypt any encrypted parts of newly-discovered messages while +indexing them. The cleartext of any successfully-decrypted messages +will be indexed, with tags applied in the same form as from notmuch +insert --try-decrypt. + +If ~/.notmuch-config contains crypto.gpg_path, and gpg is needed for +indexing, the configuration option will be used to find gpg. +--- + completion/notmuch-completion.bash | 2 +- + doc/man1/notmuch-new.rst | 10 ++++++++++ + notmuch-new.c | 30 +++++++++++++++++++++++++++++- + 3 files changed, 40 insertions(+), 2 deletions(-) + +diff --git a/completion/notmuch-completion.bash b/completion/notmuch-completion.bash +index 1e4b2cc..a6a5a60 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 c55dea7..e495557 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_indexopts_t *indexopts; + + int total_files; + int processed_files; +@@ -260,7 +261,8 @@ add_file (notmuch_database_t *notmuch, const char *filename, + if (status) + goto DONE; + +- status = notmuch_database_add_message (notmuch, filename, &message); ++ status = notmuch_database_add_message_with_indexopts (notmuch, filename, ++ state->indexopts, &message); + switch (status) { + /* Success. */ + case NOTMUCH_STATUS_SUCCESS: +@@ -930,6 +932,7 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[]) + add_files_state_t add_files_state = { + .verbosity = VERBOSITY_NORMAL, + .debug = FALSE, ++ .indexopts = NULL, + .output_is_a_tty = isatty (fileno (stdout)), + }; + struct timeval tv_start; +@@ -943,6 +946,7 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[]) + unsigned int i; + notmuch_bool_t timer_is_active = FALSE; + notmuch_bool_t no_hooks = FALSE; ++ notmuch_bool_t try_decrypt = FALSE; + notmuch_bool_t quiet = FALSE, verbose = FALSE; + notmuch_status_t status; + +@@ -951,6 +955,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, &try_decrypt, "try-decrypt", 0, 0 }, + { NOTMUCH_OPT_INHERIT, (void *) ¬much_shared_options, NULL, 0, 0 }, + { 0, 0, 0, 0, 0 } + }; +@@ -1068,6 +1073,28 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[]) + if (notmuch == NULL) + return EXIT_FAILURE; + ++ add_files_state.indexopts = notmuch_indexopts_create (); ++ if (!add_files_state.indexopts) { ++ fprintf (stderr, "Error: could not create index options.\n"); ++ return EXIT_FAILURE; ++ } ++ status = notmuch_indexopts_set_try_decrypt (add_files_state.indexopts, try_decrypt); ++ if (status != NOTMUCH_STATUS_SUCCESS) { ++ fprintf (stderr, "Error: Failed to set try_decrypt to %s. (%s)\n", ++ try_decrypt ? "True" : "False", notmuch_status_to_string (status)); ++ notmuch_indexopts_destroy (add_files_state.indexopts); ++ return EXIT_FAILURE; ++ } ++ if (try_decrypt) { ++ const char* gpg_path = notmuch_config_get_crypto_gpg_path (config); ++ status = notmuch_indexopts_set_gpg_path (add_files_state.indexopts, 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. */ +@@ -1151,5 +1178,6 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[]) + if (!no_hooks && !ret && !interrupted) + ret = notmuch_run_hook (db_path, "post-new"); + ++ notmuch_indexopts_destroy (add_files_state.indexopts); + return ret || interrupted ? EXIT_FAILURE : EXIT_SUCCESS; + } +-- +2.8.1 +