]> git.notmuchmail.org Git - notmuch/commitdiff
cli/show: use decryption policy "auto" by default.
authorDaniel Kahn Gillmor <dkg@fifthhorseman.net>
Fri, 8 Dec 2017 06:23:55 +0000 (01:23 -0500)
committerDavid Bremner <david@tethera.net>
Fri, 8 Dec 2017 12:08:46 +0000 (08:08 -0400)
When showing a message, if the user doesn't specify --decrypt= at all,
but a stashed session key is known to notmuch, notmuch should just go
ahead and try to decrypt the message with the session key (without
bothering the user for access to their asymmetric secret key).

The user can disable this at the command line with --decrypt=false if
they really don't want to look at the e-mail that they've asked
notmuch to show them.

and of course, "notmuch show --decrypt" still works for accessing the
user's secret keys if necessary.

completion/notmuch-completion.bash
doc/man1/notmuch-show.rst
notmuch-show.c
test/T357-index-decryption.sh

index 1cd616b31314f78fbbc74fd4b1105d7d5496359c..f94dbeed66bdef7a4f757d8cb346fa008b1e6e88 100644 (file)
@@ -517,7 +517,7 @@ _notmuch_show()
            COMPREPLY=( $( compgen -W "text json sexp mbox raw" -- "${cur}" ) )
            return
            ;;
            COMPREPLY=( $( compgen -W "text json sexp mbox raw" -- "${cur}" ) )
            return
            ;;
-       --exclude|--body)
+       --exclude|--body|--decrypt)
            COMPREPLY=( $( compgen -W "true false" -- "${cur}" ) )
            return
            ;;
            COMPREPLY=( $( compgen -W "true false" -- "${cur}" ) )
            return
            ;;
@@ -526,7 +526,7 @@ _notmuch_show()
     ! $split &&
     case "${cur}" in
        -*)
     ! $split &&
     case "${cur}" in
        -*)
-           local options="--entire-thread= --format= --exclude= --body= --format-version= --part= --verify --decrypt --include-html ${_notmuch_shared_options}"
+           local options="--entire-thread= --format= --exclude= --body= --format-version= --part= --verify --decrypt= --include-html ${_notmuch_shared_options}"
            compopt -o nospace
            COMPREPLY=( $(compgen -W "$options" -- ${cur}) )
            ;;
            compopt -o nospace
            COMPREPLY=( $(compgen -W "$options" -- ${cur}) )
            ;;
index 7ba091cf57c3ce3a76784b7b663c73cc5914d774..64caa7a6f02063961dffbf632637b922f04612b3 100644 (file)
@@ -123,6 +123,10 @@ Supported options for **show** include
         multipart/encrypted part will be replaced by the decrypted
         content.
 
         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.
 
         Decryption expects a functioning **gpg-agent(1)** to provide any
         needed credentials. Without one, the decryption will fail.
 
index 7ee9685aad0f9dca3701972b54d0efef24bfcd8f..c8f5a48f78312744505e4637683a1a5fdeab6377 100644 (file)
@@ -1083,13 +1083,14 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
        .part = -1,
        .omit_excluded = true,
        .output_body = true,
        .part = -1,
        .omit_excluded = true,
        .output_body = true,
-       .crypto = { .decrypt = NOTMUCH_DECRYPT_FALSE },
+       .crypto = { .decrypt = NOTMUCH_DECRYPT_AUTO },
     };
     int format = NOTMUCH_FORMAT_NOT_SPECIFIED;
     bool exclude = true;
     bool entire_thread_set = false;
     bool single_message;
     bool decrypt = false;
     };
     int format = NOTMUCH_FORMAT_NOT_SPECIFIED;
     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 =
 
     notmuch_opt_desc_t options[] = {
        { .opt_keyword = &format, .name = "format", .keywords =
@@ -1104,7 +1105,7 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
        { .opt_bool = &params.entire_thread, .name = "entire-thread",
          .present = &entire_thread_set },
        { .opt_int = &params.part, .name = "part" },
        { .opt_bool = &params.entire_thread, .name = "entire-thread",
          .present = &entire_thread_set },
        { .opt_int = &params.part, .name = "part" },
-       { .opt_bool = &decrypt, .name = "decrypt" },
+       { .opt_bool = &decrypt, .name = "decrypt", .present = &decrypt_set },
        { .opt_bool = &params.crypto.verify, .name = "verify" },
        { .opt_bool = &params.output_body, .name = "body" },
        { .opt_bool = &params.include_html, .name = "include-html" },
        { .opt_bool = &params.crypto.verify, .name = "verify" },
        { .opt_bool = &params.output_body, .name = "body" },
        { .opt_bool = &params.include_html, .name = "include-html" },
@@ -1118,10 +1119,14 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
 
     notmuch_process_shared_options (argv[0]);
 
 
     notmuch_process_shared_options (argv[0]);
 
-    if (decrypt) {
-       params.crypto.decrypt = NOTMUCH_DECRYPT_TRUE;
-       /* decryption implies verification */
-       params.crypto.verify = true;
+    if (decrypt_set) {
+       if (decrypt) {
+           params.crypto.decrypt = NOTMUCH_DECRYPT_TRUE;
+           /* decryption implies verification */
+           params.crypto.verify = true;
+       } else {
+           params.crypto.decrypt = NOTMUCH_DECRYPT_FALSE;
+       }
     }
 
     /* specifying a part implies single message display */
     }
 
     /* specifying a part implies single message display */
index 31991e22be98e158cc8d5ac73f6a12832cf96b9a..c3730488f792c0863ea3d7a3214d2f7b3bd0635c 100755 (executable)
@@ -210,6 +210,23 @@ test_expect_equal \
     "$output" \
     "$expected"
 
     "$output" \
     "$expected"
 
+test_begin_subtest "notmuch show should show cleartext if session key is present"
+output=$(notmuch show id:simple-encrypted@crypto.notmuchmail.org | awk '/^\014part}/{ f=0 }; { if (f) { print $0 } } /^\014part{ ID: 3/{ f=1 }')
+expected='This is a top sekrit message.'
+if [ $NOTMUCH_HAVE_GMIME_SESSION_KEYS -eq 0 ]; then
+    test_subtest_known_broken
+fi
+test_expect_equal \
+    "$output" \
+    "$expected"
+
+test_begin_subtest "notmuch show should show nothing if decryption is explicitly disallowed"
+output=$(notmuch show --decrypt=false id:simple-encrypted@crypto.notmuchmail.org | awk '/^\014part}/{ f=0 }; { if (f) { print $0 } } /^\014part{ ID: 3/{ f=1 }')
+expected='Non-text part: application/octet-stream'
+test_expect_equal \
+    "$output" \
+    "$expected"
+
 
 # TODO: test removal of a message from the message store between
 # indexing and reindexing.
 
 # TODO: test removal of a message from the message store between
 # indexing and reindexing.