cli/reindex: add --try-decrypt=(true|false)

Enable override of the index.try_decrypt setting on a per-run basis
when invoking "notmuch reindex".  This allows the possibility of (for
example) an emacs keybinding that adds the cleartext of the currently
shown decrypted message to the index, making it searchable in the
future.

It also enables one-time indexing of all messages matching some query,
like so:

    notmuch reindex tag:encrypted and\
       not property:index.decryption=success and\
       from:alice@example.org

We also update the documentation and tab completion, and add a few
more tests.
This commit is contained in:
Daniel Kahn Gillmor 2017-10-20 22:25:48 -04:00 committed by David Bremner
parent c5356b9ed5
commit 8116891744
4 changed files with 96 additions and 3 deletions

View file

@ -435,10 +435,18 @@ _notmuch_reindex()
local cur prev words cword split
_init_completion -s || return
$split &&
case "${prev}" in
--try-decrypt)
COMPREPLY=( $( compgen -W "true false" -- "${cur}" ) )
return
;;
esac
! $split &&
case "${cur}" in
-*)
local options="${_notmuch_shared_options}"
local options="--try-decrypt= ${_notmuch_shared_options}"
compopt -o nospace
COMPREPLY=( $(compgen -W "$options" -- ${cur}) )
;;

View file

@ -19,6 +19,20 @@ The **reindex** command searches for all messages matching the
supplied search terms, and re-creates the full-text index on these
messages using the supplied options.
Supported options for **reindex** include
``--try-decrypt=(true|false)``
If true, when encountering an encrypted message, try to
decrypt it while reindexing. 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 ``--try-decrypt=true`` without
considering the security of your index.
See also ``index.try_decrypt`` in **notmuch-config(1)**.
SEE ALSO
========

View file

@ -89,7 +89,7 @@ notmuch_reindex_command (notmuch_config_t *config, int argc, char *argv[])
struct sigaction action;
int opt_index;
int ret;
notmuch_indexopts_t *indexopts = NULL;
notmuch_status_t status;
/* Set up our handler for SIGINT */
memset (&action, 0, sizeof (struct sigaction));
@ -99,6 +99,7 @@ notmuch_reindex_command (notmuch_config_t *config, int argc, char *argv[])
sigaction (SIGINT, &action, NULL);
notmuch_opt_desc_t options[] = {
{ .opt_inherit = notmuch_shared_indexing_options },
{ .opt_inherit = notmuch_shared_options },
{ }
};
@ -115,6 +116,13 @@ notmuch_reindex_command (notmuch_config_t *config, int argc, char *argv[])
notmuch_exit_if_unmatched_db_uuid (notmuch);
status = notmuch_process_shared_indexing_options (notmuch, config);
if (status != NOTMUCH_STATUS_SUCCESS) {
fprintf (stderr, "Error: Failed to process index options. (%s)\n",
notmuch_status_to_string (status));
return EXIT_FAILURE;
}
query_string = query_string_from_args (config, argc-opt_index, argv+opt_index);
if (query_string == NULL) {
fprintf (stderr, "Out of memory\n");
@ -126,7 +134,7 @@ notmuch_reindex_command (notmuch_config_t *config, int argc, char *argv[])
return EXIT_FAILURE;
}
ret = reindex_query (notmuch, query_string, indexopts);
ret = reindex_query (notmuch, query_string, indexing_cli_choices.opts);
notmuch_database_destroy (notmuch);

View file

@ -102,6 +102,69 @@ test_expect_equal \
"$expected"
# add a tag to all messages to ensure that it stays after reindexing
test_begin_subtest 'tagging all messages'
test_expect_success 'notmuch tag +blarney "encrypted message"'
test_begin_subtest "verify that tags have not changed"
output=$(notmuch search tag:blarney)
expected='thread:0000000000000001 2000-01-01 [1/1] Notmuch Test Suite; test encrypted message for cleartext index 001 (blarney encrypted inbox)
thread:0000000000000005 2000-01-01 [1/1] Notmuch Test Suite; test encrypted message for cleartext index 002 (blarney encrypted inbox unread)'
test_expect_equal \
"$output" \
"$expected"
# see if first message shows up after reindexing with --try-decrypt=true (same $expected, untouched):
test_begin_subtest 'reindex old messages'
test_expect_success 'notmuch reindex --try-decrypt=true tag:encrypted and not property:index.decryption=success'
test_begin_subtest "reindexed encrypted message, including cleartext"
output=$(notmuch search wumpus)
test_expect_equal \
"$output" \
"$expected"
# and the same search, but by property ($expected is untouched):
test_begin_subtest "emacs search by property for both messages"
output=$(notmuch search property:index.decryption=success)
test_expect_equal \
"$output" \
"$expected"
# try to remove cleartext indexing
test_begin_subtest 'reindex without cleartext'
test_expect_success 'notmuch reindex tag:encrypted and property:index.decryption=success'
test_begin_subtest "reindexed encrypted messages, without cleartext"
output=$(notmuch search wumpus)
expected=''
test_expect_equal \
"$output" \
"$expected"
# and the same search, but by property ($expected is untouched):
test_begin_subtest "emacs search by property with both messages unindexed"
output=$(notmuch search property:index.decryption=success)
test_expect_equal \
"$output" \
"$expected"
# ensure that the tags remain even when we are dropping the cleartext.
test_begin_subtest "verify that tags remain without cleartext"
output=$(notmuch search tag:blarney)
expected='thread:0000000000000001 2000-01-01 [1/1] Notmuch Test Suite; test encrypted message for cleartext index 001 (blarney encrypted inbox)
thread:0000000000000005 2000-01-01 [1/1] Notmuch Test Suite; test encrypted message for cleartext index 002 (blarney encrypted inbox unread)'
test_expect_equal \
"$output" \
"$expected"
# TODO: test removal of a message from the message store between
# indexing and reindexing.
# TODO: insert the same message into the message store twice, index,
# remove one of them from the message store, and then reindex.
# reindexing should return a failure but the message should still be
# present? -- or what should the semantics be if you ask to reindex a
# message whose underlying files have been renamed or moved or
# removed?
test_done