From bf8bf66572186bf9d8753219839fc37639ad12fc Mon Sep 17 00:00:00 2001 From: Daniel Kahn Gillmor Date: Fri, 8 Jul 2016 11:27:22 +0200 Subject: [PATCH] [PATCH v4 11/16] add --try-decrypt to notmuch insert --- 7a/2ba5c14dec155c186b466794052ce6c955d2cb | 182 ++++++++++++++++++++++ 1 file changed, 182 insertions(+) create mode 100644 7a/2ba5c14dec155c186b466794052ce6c955d2cb diff --git a/7a/2ba5c14dec155c186b466794052ce6c955d2cb b/7a/2ba5c14dec155c186b466794052ce6c955d2cb new file mode 100644 index 000000000..37e2fb5d6 --- /dev/null +++ b/7a/2ba5c14dec155c186b466794052ce6c955d2cb @@ -0,0 +1,182 @@ +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 2C4A06DE092C + for ; Fri, 8 Jul 2016 03:15:14 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at cworth.org +X-Spam-Flag: NO +X-Spam-Score: 0.018 +X-Spam-Level: +X-Spam-Status: No, score=0.018 tagged_above=-999 required=5 tests=[AWL=0.018] + 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 VQHSFU_TcCPl for ; + Fri, 8 Jul 2016 03:15:06 -0700 (PDT) +Received: from che.mayfirst.org (che.mayfirst.org [162.247.75.118]) + by arlo.cworth.org (Postfix) with ESMTP id 6771C6DE092D + for ; Fri, 8 Jul 2016 03:13:18 -0700 (PDT) +Received: from fifthhorseman.net (unknown [88.128.80.54]) + by che.mayfirst.org (Postfix) with ESMTPSA id 1844AF98B + for ; Fri, 8 Jul 2016 06:13:17 -0400 (EDT) +Received: by fifthhorseman.net (Postfix, from userid 1000) + id B857D214EB; Fri, 8 Jul 2016 11:27:34 +0200 (CEST) +From: Daniel Kahn Gillmor +To: Notmuch Mail +Subject: [PATCH v4 11/16] add --try-decrypt to notmuch insert +Date: Fri, 8 Jul 2016 11:27:22 +0200 +Message-Id: <1467970047-8013-12-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:15:14 -0000 + +allow an incoming message to be delivered while indexing the +cleartext. + +This requires the secret keys for the message to be available. For +the moment, the most functional approach is to ensure that gpg-agent +is running and knows about any secret keys that might be useful to +decrypt incoming mail. + +Any additional recommendations for how to phrase the caveat for this +option are welcome. + +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-insert.rst | 11 +++++++++++ + notmuch-insert.c | 32 +++++++++++++++++++++++++++++--- + 3 files changed, 41 insertions(+), 4 deletions(-) + +diff --git a/completion/notmuch-completion.bash b/completion/notmuch-completion.bash +index 78047b5..1e4b2cc 100644 +--- a/completion/notmuch-completion.bash ++++ b/completion/notmuch-completion.bash +@@ -224,7 +224,7 @@ _notmuch_insert() + ! $split && + case "${cur}" in + --*) +- local options="--create-folder --folder= --keep --no-hooks ${_notmuch_shared_options}" ++ local options="--create-folder --folder= --keep --no-hooks --try-decrypt ${_notmuch_shared_options}" + compopt -o nospace + COMPREPLY=( $(compgen -W "$options" -- ${cur}) ) + return +diff --git a/doc/man1/notmuch-insert.rst b/doc/man1/notmuch-insert.rst +index 2c9c0d0..9c76b30 100644 +--- a/doc/man1/notmuch-insert.rst ++++ b/doc/man1/notmuch-insert.rst +@@ -50,6 +50,17 @@ Supported options for **insert** include + ``--no-hooks`` + Prevent hooks from being run. + ++ ``--try-decrypt`` ++ ++ If the message is encrypted, try to decrypt the message while ++ indexing. If decryption is successful, index the cleartext ++ itself. The message is stored to disk in its original form ++ (ciphertext). 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. ++ + EXIT STATUS + =========== + +diff --git a/notmuch-insert.c b/notmuch-insert.c +index 131f09e..eec0eb5 100644 +--- a/notmuch-insert.c ++++ b/notmuch-insert.c +@@ -378,12 +378,13 @@ FAIL: + */ + static notmuch_status_t + add_file (notmuch_database_t *notmuch, const char *path, tag_op_list_t *tag_ops, +- notmuch_bool_t synchronize_flags, notmuch_bool_t keep) ++ notmuch_bool_t synchronize_flags, notmuch_bool_t keep, ++ notmuch_indexopts_t *indexopts) + { + notmuch_message_t *message; + notmuch_status_t status; + +- status = notmuch_database_add_message (notmuch, path, &message); ++ status = notmuch_database_add_message_with_indexopts (notmuch, path, indexopts, &message); + if (status == NOTMUCH_STATUS_SUCCESS) { + status = tag_op_list_apply (message, tag_ops, 0); + if (status) { +@@ -455,17 +456,20 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[]) + notmuch_bool_t create_folder = FALSE; + notmuch_bool_t keep = FALSE; + notmuch_bool_t no_hooks = FALSE; ++ notmuch_bool_t try_decrypt = FALSE; + notmuch_bool_t synchronize_flags; + const char *maildir; + char *newpath; + int opt_index; + unsigned int i; ++ notmuch_indexopts_t *indexopts; + + notmuch_opt_desc_t options[] = { + { NOTMUCH_OPT_STRING, &folder, "folder", 0, 0 }, + { NOTMUCH_OPT_BOOLEAN, &create_folder, "create-folder", 0, 0 }, + { NOTMUCH_OPT_BOOLEAN, &keep, "keep", 0, 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 }, + { NOTMUCH_OPT_END, 0, 0, 0, 0 } + }; +@@ -545,8 +549,29 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[]) + return EXIT_FAILURE; + } + ++ indexopts = notmuch_indexopts_create (); ++ if (!indexopts) { ++ fprintf (stderr, "Error: could not create index options.\n"); ++ return EXIT_FAILURE; ++ } ++ status = notmuch_indexopts_set_try_decrypt (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 (indexopts); ++ return EXIT_FAILURE; ++ } ++ if (try_decrypt) { ++ const char* gpg_path = notmuch_config_get_crypto_gpg_path (config); ++ status = notmuch_indexopts_set_gpg_path (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)); ++ } ++ + /* Index the message. */ +- status = add_file (notmuch, newpath, tag_ops, synchronize_flags, keep); ++ status = add_file (notmuch, newpath, tag_ops, synchronize_flags, keep, indexopts); + + /* Commit changes. */ + close_status = notmuch_database_destroy (notmuch); +@@ -577,5 +602,6 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[]) + notmuch_run_hook (db_path, "post-insert"); + } + ++ notmuch_indexopts_destroy (indexopts); + return status ? EXIT_FAILURE : EXIT_SUCCESS; + } +-- +2.8.1 + -- 2.26.2