From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 7CB706DE0962 for ; Mon, 11 Dec 2017 16:19:11 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.029 X-Spam-Level: X-Spam-Status: No, score=-0.029 tagged_above=-999 required=5 tests=[AWL=-0.029] 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 ZBReb1sKXhv3 for ; Mon, 11 Dec 2017 16:19:10 -0800 (PST) Received: from che.mayfirst.org (che.mayfirst.org [162.247.75.118]) by arlo.cworth.org (Postfix) with ESMTPS id D15176DE0941 for ; Mon, 11 Dec 2017 16:19:09 -0800 (PST) Received: from fifthhorseman.net (unknown [38.109.115.130]) by che.mayfirst.org (Postfix) with ESMTPSA id 839A6F99B for ; Mon, 11 Dec 2017 19:19:09 -0500 (EST) Received: by fifthhorseman.net (Postfix, from userid 1000) id BE3E62089D; Mon, 11 Dec 2017 19:19:04 -0500 (EST) From: Daniel Kahn Gillmor To: Notmuch Mail Subject: [PATCH 2/3] cli/show: make --decrypt take a keyword. Date: Mon, 11 Dec 2017 19:18:57 -0500 Message-Id: <20171212001858.706-3-dkg@fifthhorseman.net> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20171212001858.706-1-dkg@fifthhorseman.net> References: <20171212001858.706-1-dkg@fifthhorseman.net> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.23 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: Tue, 12 Dec 2017 00:19:11 -0000 We also expand tab completion for it, and update T357 to match. Make use of the bool-to-keyword backward-compatibility feature. --- completion/notmuch-completion.bash | 6 +++++- doc/man1/notmuch-show.rst | 37 +++++++++++++++++++++---------------- notmuch-show.c | 27 +++++++++++++-------------- test/T357-index-decryption.sh | 6 +++--- 4 files changed, 42 insertions(+), 34 deletions(-) diff --git a/completion/notmuch-completion.bash b/completion/notmuch-completion.bash index fb093de8..4ab2e5f6 100644 --- a/completion/notmuch-completion.bash +++ b/completion/notmuch-completion.bash @@ -517,10 +517,14 @@ _notmuch_show() COMPREPLY=( $( compgen -W "text json sexp mbox raw" -- "${cur}" ) ) return ;; - --exclude|--body|--decrypt) + --exclude|--body) COMPREPLY=( $( compgen -W "true false" -- "${cur}" ) ) return ;; + --decrypt) + COMPREPLY=( $( compgen -W "true auto false" -- "${cur}" ) ) + return + ;; esac ! $split && diff --git a/doc/man1/notmuch-show.rst b/doc/man1/notmuch-show.rst index 64caa7a6..7d2b38cb 100644 --- a/doc/man1/notmuch-show.rst +++ b/doc/man1/notmuch-show.rst @@ -115,22 +115,27 @@ Supported options for **show** include supported with --format=json and --format=sexp), and the multipart/signed part will be replaced by the signed data. - ``--decrypt`` - Decrypt any MIME encrypted parts found in the selected content - (ie. "multipart/encrypted" parts). Status of the decryption will - be reported (currently only supported with --format=json and - --format=sexp) and on successful decryption the - multipart/encrypted part will be replaced by the decrypted - content. - - If a session key is already known for the message, then it - will be decrypted automatically unless the user explicitly - sets ``--decrypt=false``. - - Decryption expects a functioning **gpg-agent(1)** to provide any - needed credentials. Without one, the decryption will fail. - - Implies --verify. + ``--decrypt=(false|auto|true)`` + If ``true``, decrypt any MIME encrypted parts found in the + selected content (i.e. "multipart/encrypted" parts). Status of + the decryption will be reported (currently only supported + with --format=json and --format=sexp) and on successful + decryption the multipart/encrypted part will be replaced by + the decrypted content. + + If ``auto``, and a session key is already known for the + message, then it will be decrypted, but notmuch will not try + to access the user's keys. + + Use ``false`` to avoid even automatic decryption. + + Non-automatic decryption expects a functioning + **gpg-agent(1)** to provide any needed credentials. Without + one, the decryption will fail. + + Note: ``true`` implies --verify. + + Default: ``auto`` ``--exclude=(true|false)`` Specify whether to omit threads only matching diff --git a/notmuch-show.c b/notmuch-show.c index d5adc370..ddd3c8c5 100644 --- a/notmuch-show.c +++ b/notmuch-show.c @@ -1085,8 +1085,6 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[]) bool exclude = true; bool entire_thread_set = false; bool single_message; - bool decrypt = false; - bool decrypt_set = false; notmuch_opt_desc_t options[] = { { .opt_keyword = &format, .name = "format", .keywords = @@ -1101,7 +1099,12 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[]) { .opt_bool = ¶ms.entire_thread, .name = "entire-thread", .present = &entire_thread_set }, { .opt_int = ¶ms.part, .name = "part" }, - { .opt_bool = &decrypt, .name = "decrypt", .present = &decrypt_set }, + { .opt_keyword = (int*)(¶ms.crypto.decrypt), .name = "decrypt", + .keyword_no_arg_value = "true", .keywords = + (notmuch_keyword_t []){ { "false", NOTMUCH_DECRYPT_FALSE }, + { "auto", NOTMUCH_DECRYPT_AUTO }, + { "true", NOTMUCH_DECRYPT_NOSTASH }, + { 0, 0 } } }, { .opt_bool = ¶ms.crypto.verify, .name = "verify" }, { .opt_bool = ¶ms.output_body, .name = "body" }, { .opt_bool = ¶ms.include_html, .name = "include-html" }, @@ -1115,16 +1118,9 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[]) notmuch_process_shared_options (argv[0]); - if (decrypt_set) { - if (decrypt) { - /* we do not need or want to ask for session keys */ - params.crypto.decrypt = NOTMUCH_DECRYPT_NOSTASH; - /* decryption implies verification */ - params.crypto.verify = true; - } else { - params.crypto.decrypt = NOTMUCH_DECRYPT_FALSE; - } - } + /* explicit decryption implies verification */ + if (params.crypto.decrypt == NOTMUCH_DECRYPT_NOSTASH) + params.crypto.verify = true; /* specifying a part implies single message display */ single_message = params.part >= 0; @@ -1186,8 +1182,11 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[]) params.crypto.gpgpath = notmuch_config_get_crypto_gpg_path (config); #endif + notmuch_database_mode_t mode = NOTMUCH_DATABASE_MODE_READ_ONLY; + if (params.crypto.decrypt == NOTMUCH_DECRYPT_TRUE) + mode = NOTMUCH_DATABASE_MODE_READ_WRITE; if (notmuch_database_open (notmuch_config_get_database_path (config), - NOTMUCH_DATABASE_MODE_READ_ONLY, ¬much)) + mode, ¬much)) return EXIT_FAILURE; notmuch_exit_if_unmatched_db_uuid (notmuch); diff --git a/test/T357-index-decryption.sh b/test/T357-index-decryption.sh index 6b8a8261..2b8e05b8 100755 --- a/test/T357-index-decryption.sh +++ b/test/T357-index-decryption.sh @@ -197,14 +197,14 @@ test_expect_equal \ "$output" \ "$expected" -test_begin_subtest "show one of the messages with --decrypt" -output=$(notmuch show --decrypt thread:0000000000000001 | awk '/^\014part}/{ f=0 }; { if (f) { print $0 } } /^\014part{ ID: 3/{ f=1 }') +test_begin_subtest "show one of the messages with --decrypt=true" +output=$(notmuch show --decrypt=true thread:0000000000000001 | awk '/^\014part}/{ f=0 }; { if (f) { print $0 } } /^\014part{ ID: 3/{ f=1 }') expected='This is a test encrypted message with a wumpus.' test_expect_equal \ "$output" \ "$expected" -test_begin_subtest "Ensure that we cannot show the message without --decrypt" +test_begin_subtest "Ensure that we cannot show the message with --decrypt=auto" output=$(notmuch show thread:0000000000000001 | awk '/^\014part}/{ f=0 }; { if (f) { print $0 } } /^\014part{ ID: 3/{ f=1 }') expected='Non-text part: application/octet-stream' test_expect_equal \ -- 2.15.1