unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
To: Notmuch Mail <notmuch@notmuchmail.org>
Subject: [PATCH 5/5] cli/show: enable --decrypt=stash
Date: Mon, 11 Dec 2017 21:52:25 -0500	[thread overview]
Message-ID: <20171212025225.11854-6-dkg@fifthhorseman.net> (raw)
In-Reply-To: <20171212025225.11854-1-dkg@fifthhorseman.net>

Add fancy new feature, which makes "notmuch show" capable of actually
indexing messages that it just decrypted.

This enables a workflow where messages can come in in the background
and be indexed using "--decrypt=auto".  But when showing an encrypted
message for the first time, it gets automatically indexed.

This is something of a departure for "notmuch show" -- in particular,
because it requires read/write access to the database.  However, this
might be a common use case -- people get mail delivered and indexed in
the background, but only want access to their secret key to happen
when they're directly interacting with notmuch itself.

In such a scenario, they couldn't search newly-delivered, encrypted
messages, but they could search for them once they've read them.

Documentation of this new feature also uses a table form, similar to
that found in the description of index.decrypt in notmuch-config(1).

A notmuch UI that wants to facilitate this workflow while also
offering an interactive search interface might instead make use of
these additional commands while the user is at the console:

Count received encrypted messages (if > 0, there are some things we
haven't yet tried to index, and therefore can't yet search):

     notmuch count tag:encrypted and \
         not property:index.decryption=success and \
         not property:index.decryption=failure

Reindex those messages:

     notmuch reindex --try-decrypt=true tag:encrypted and \
         not property:index.decryption=success and \
         not property:index.decryption=failure
---
 completion/notmuch-completion.bash |  2 +-
 doc/man1/notmuch-show.rst          | 35 ++++++++++++++++++++++++++++++++---
 notmuch-show.c                     |  9 +++++++--
 test/T357-index-decryption.sh      | 18 ++++++++++++++++++
 4 files changed, 58 insertions(+), 6 deletions(-)

diff --git a/completion/notmuch-completion.bash b/completion/notmuch-completion.bash
index a24b8a08..16ae3992 100644
--- a/completion/notmuch-completion.bash
+++ b/completion/notmuch-completion.bash
@@ -522,7 +522,7 @@ _notmuch_show()
 	    return
 	    ;;
         --decrypt)
-	    COMPREPLY=( $( compgen -W "true auto false" -- "${cur}" ) )
+	    COMPREPLY=( $( compgen -W "true auto false stash" -- "${cur}" ) )
 	    return
 	    ;;
     esac
diff --git a/doc/man1/notmuch-show.rst b/doc/man1/notmuch-show.rst
index 7d2b38cb..5fd9876e 100644
--- a/doc/man1/notmuch-show.rst
+++ b/doc/man1/notmuch-show.rst
@@ -115,7 +115,7 @@ 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=(false|auto|true)``
+    ``--decrypt=(false|auto|true|stash)``
         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
@@ -123,17 +123,46 @@ Supported options for **show** include
         decryption the multipart/encrypted part will be replaced by
         the decrypted content.
 
+        ``stash`` behaves like ``true``, but upon successful
+        decryption it will also stash the message's session key in the
+        database, and index the cleartext of the message, enabling
+        automatic decryption in the future.
+
         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
+        Non-automatic decryption (``stash`` or ``true``, in the
+        absence of a stashed session key) expects a functioning
         **gpg-agent(1)** to provide any needed credentials. Without
         one, the decryption will fail.
 
-        Note: ``true`` implies --verify.
+        Note: setting either ``true`` or ``stash`` here implies
+        ``--verify``.
+
+        Here is a table that summarizes each of these policies:
+
+        +------------------------+-------+------+------+-------+
+        |                        | false | auto | true | stash |
+        +========================+=======+======+======+=======+
+        | Show cleartext if      |       |  X   |  X   |   X   |
+        | session key is         |       |      |      |       |
+        | already known          |       |      |      |       |
+        +------------------------+-------+------+------+-------+
+        | Use secret keys to     |       |      |  X   |   X   |
+        | show cleartext         |       |      |      |       |
+        +------------------------+-------+------+------+-------+
+        | Stash any newly        |       |      |      |   X   |
+        | recovered session keys,|       |      |      |       |
+        | reindexing message if  |       |      |      |       |
+        | found                  |       |      |      |       |
+        +------------------------+-------+------+------+-------+
+
+        Note: ``--decrypt=stash`` requires a writable database.
+        Otherwise, ``notmuch show`` operates entirely in read-only
+        mode.
 
         Default: ``auto``
 
diff --git a/notmuch-show.c b/notmuch-show.c
index 90e45cd9..b09d1f4b 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -1124,6 +1124,7 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
 	  (notmuch_keyword_t []){ { "false", NOTMUCH_DECRYPT_FALSE },
 				  { "auto", NOTMUCH_DECRYPT_AUTO },
 				  { "true", NOTMUCH_DECRYPT_NOSTASH },
+				  { "stash", NOTMUCH_DECRYPT_TRUE },
 				  { 0, 0 } } },
 	{ .opt_bool = &params.crypto.verify, .name = "verify" },
 	{ .opt_bool = &params.output_body, .name = "body" },
@@ -1139,7 +1140,8 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
     notmuch_process_shared_options (argv[0]);
 
     /* explicit decryption implies verification */
-    if (params.crypto.decrypt == NOTMUCH_DECRYPT_NOSTASH)
+    if (params.crypto.decrypt == NOTMUCH_DECRYPT_NOSTASH ||
+	params.crypto.decrypt == NOTMUCH_DECRYPT_TRUE)
 	params.crypto.verify = true;
 
     /* specifying a part implies single message display */
@@ -1202,8 +1204,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, &notmuch))
+			       mode, &notmuch))
 	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 2b8e05b8..6e7dc74e 100755
--- a/test/T357-index-decryption.sh
+++ b/test/T357-index-decryption.sh
@@ -80,6 +80,24 @@ test_expect_equal \
     "$output" \
     "$expected"
 
+# show the message using stashing decryption
+test_begin_subtest "stash decryption during show"
+output=$(notmuch show --decrypt=stash tag:encrypted subject:002 | 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 "search should now show the contents"
+output=$(notmuch search wumpus)
+expected='thread:0000000000000003   2000-01-01 [1/1] Notmuch Test Suite; test encrypted message for cleartext index 002 (encrypted inbox unread)'
+if [ $NOTMUCH_HAVE_GMIME_SESSION_KEYS -eq 0 ]; then
+    test_subtest_known_broken
+fi
+test_expect_equal \
+    "$output" \
+    "$expected"
+
 # try reinserting it with decryption, should appear again, but now we
 # have two copies of the message:
 test_begin_subtest "message cleartext is present after reinserting with --decrypt=true"
-- 
2.15.1

      parent reply	other threads:[~2017-12-12  2:52 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-12  2:52 notmuch show --decrypt=stash Daniel Kahn Gillmor
2017-12-12  2:52 ` [PATCH 1/5] lib: expose notmuch_message_get_database() Daniel Kahn Gillmor
2017-12-12  2:52 ` [PATCH 2/5] properties: add notmuch_message_count_properties Daniel Kahn Gillmor
2017-12-12  4:49   ` [PATCH v2] " Daniel Kahn Gillmor
2017-12-12  2:52 ` [PATCH 3/5] cli: write session keys to database, if asked to do so Daniel Kahn Gillmor
2017-12-12  2:52 ` [PATCH 4/5] cli/show: reindex when we learned new session keys about a message Daniel Kahn Gillmor
2017-12-12  2:52 ` Daniel Kahn Gillmor [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171212025225.11854-6-dkg@fifthhorseman.net \
    --to=dkg@fifthhorseman.net \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).