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 v4 12/16] add --try-decrypt to notmuch new
Date: Fri,  8 Jul 2016 11:27:23 +0200	[thread overview]
Message-ID: <1467970047-8013-13-git-send-email-dkg@fifthhorseman.net> (raw)
In-Reply-To: <1467970047-8013-1-git-send-email-dkg@fifthhorseman.net>

Try to decrypt any encrypted parts of newly-discovered messages while
indexing them.  The cleartext of any successfully-decrypted messages
will be indexed, with tags applied in the same form as from notmuch
insert --try-decrypt.

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-new.rst           | 10 ++++++++++
 notmuch-new.c                      | 30 +++++++++++++++++++++++++++++-
 3 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/completion/notmuch-completion.bash b/completion/notmuch-completion.bash
index 1e4b2cc..a6a5a60 100644
--- a/completion/notmuch-completion.bash
+++ b/completion/notmuch-completion.bash
@@ -247,7 +247,7 @@ _notmuch_new()
 
     case "${cur}" in
 	-*)
-	    local options="--no-hooks --quiet ${_notmuch_shared_options}"
+	    local options="--no-hooks --try-decrypt --quiet ${_notmuch_shared_options}"
 	    compopt -o nospace
 	    COMPREPLY=( $(compgen -W "${options}" -- ${cur}) )
 	    ;;
diff --git a/doc/man1/notmuch-new.rst b/doc/man1/notmuch-new.rst
index 787ed78..cf08021 100644
--- a/doc/man1/notmuch-new.rst
+++ b/doc/man1/notmuch-new.rst
@@ -43,6 +43,16 @@ Supported options for **new** include
     ``--quiet``
         Do not print progress or results.
 
+    ``--try-decrypt``
+
+        For each message, if it is encrypted, try to decrypt it while
+        indexing.  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 THIS FLAG without considering the
+        security of your index.
+
 SEE ALSO
 ========
 
diff --git a/notmuch-new.c b/notmuch-new.c
index c55dea7..e495557 100644
--- a/notmuch-new.c
+++ b/notmuch-new.c
@@ -49,6 +49,7 @@ typedef struct {
     size_t new_tags_length;
     const char **new_ignore;
     size_t new_ignore_length;
+    notmuch_indexopts_t *indexopts;
 
     int total_files;
     int processed_files;
@@ -260,7 +261,8 @@ add_file (notmuch_database_t *notmuch, const char *filename,
     if (status)
 	goto DONE;
 
-    status = notmuch_database_add_message (notmuch, filename, &message);
+    status = notmuch_database_add_message_with_indexopts (notmuch, filename,
+							  state->indexopts, &message);
     switch (status) {
     /* Success. */
     case NOTMUCH_STATUS_SUCCESS:
@@ -930,6 +932,7 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])
     add_files_state_t add_files_state = {
 	.verbosity = VERBOSITY_NORMAL,
 	.debug = FALSE,
+	.indexopts = NULL,
 	.output_is_a_tty = isatty (fileno (stdout)),
     };
     struct timeval tv_start;
@@ -943,6 +946,7 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])
     unsigned int i;
     notmuch_bool_t timer_is_active = FALSE;
     notmuch_bool_t no_hooks = FALSE;
+    notmuch_bool_t try_decrypt = FALSE;
     notmuch_bool_t quiet = FALSE, verbose = FALSE;
     notmuch_status_t status;
 
@@ -951,6 +955,7 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])
 	{ NOTMUCH_OPT_BOOLEAN,  &verbose, "verbose", 'v', 0 },
 	{ NOTMUCH_OPT_BOOLEAN,  &add_files_state.debug, "debug", 'd', 0 },
 	{ NOTMUCH_OPT_BOOLEAN,  &no_hooks, "no-hooks", 'n', 0 },
+	{ NOTMUCH_OPT_BOOLEAN,  &try_decrypt, "try-decrypt", 0, 0 },
 	{ NOTMUCH_OPT_INHERIT, (void *) &notmuch_shared_options, NULL, 0, 0 },
 	{ 0, 0, 0, 0, 0 }
     };
@@ -1068,6 +1073,28 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])
     if (notmuch == NULL)
 	return EXIT_FAILURE;
 
+    add_files_state.indexopts = notmuch_indexopts_create ();
+    if (!add_files_state.indexopts) {
+	fprintf (stderr, "Error: could not create index options.\n");
+	return EXIT_FAILURE;
+    }
+    status = notmuch_indexopts_set_try_decrypt (add_files_state.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 (add_files_state.indexopts);
+	return EXIT_FAILURE;
+    }
+    if (try_decrypt) {
+	const char* gpg_path = notmuch_config_get_crypto_gpg_path (config);
+	status = notmuch_indexopts_set_gpg_path (add_files_state.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));
+    }
+
+    
     /* Set up our handler for SIGINT. We do this after having
      * potentially done a database upgrade we this interrupt handler
      * won't support. */
@@ -1151,5 +1178,6 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])
     if (!no_hooks && !ret && !interrupted)
 	ret = notmuch_run_hook (db_path, "post-new");
 
+    notmuch_indexopts_destroy (add_files_state.indexopts);
     return ret || interrupted ? EXIT_FAILURE : EXIT_SUCCESS;
 }
-- 
2.8.1

  parent reply	other threads:[~2016-07-08 10:14 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-08  9:27 Allow indexing cleartext of encrypted messages (v4) Daniel Kahn Gillmor
2016-07-08  9:27 ` [PATCH v4 01/16] add util/search-path.{c, h} to test for executables in $PATH Daniel Kahn Gillmor
2016-08-12  5:51   ` David Bremner
2016-08-12  6:19     ` Daniel Kahn Gillmor
2016-08-12  7:38       ` David Bremner
2016-08-12 18:46         ` Daniel Kahn Gillmor
2016-08-12 20:01           ` Tomi Ollila
2016-08-12 23:03             ` David Bremner
2016-07-08  9:27 ` [PATCH v4 02/16] Move crypto.c into libutil Daniel Kahn Gillmor
2016-08-07 13:32   ` David Bremner
2016-08-12  6:17   ` David Bremner
2016-08-13  8:01     ` Tomi Ollila
2016-08-13  8:27       ` David Bremner
2016-07-08  9:27 ` [PATCH v4 03/16] make shared crypto code behave library-like Daniel Kahn Gillmor
2016-08-12  7:46   ` David Bremner
2016-07-08  9:27 ` [PATCH v4 04/16] Provide _notmuch_crypto_{set,get}_gpg_path Daniel Kahn Gillmor
2016-08-12  8:04   ` David Bremner
2016-07-08  9:27 ` [PATCH v4 05/16] Choose the default gpg_path with _notmuch_crypto_get_gpg_path (NULL) Daniel Kahn Gillmor
2016-07-08  9:27 ` [PATCH v4 06/16] Prefer gpg2 in the test suite if available Daniel Kahn Gillmor
2016-08-12  8:19   ` David Bremner
2016-07-08  9:27 ` [PATCH v4 07/16] create a notmuch_indexopts_t index options object Daniel Kahn Gillmor
2016-07-08  9:27 ` [PATCH v4 08/16] reorganize indexing of multipart/signed and multipart/encrypted Daniel Kahn Gillmor
2016-08-13  4:30   ` David Bremner
2016-07-08  9:27 ` [PATCH v4 09/16] index encrypted parts when asked Daniel Kahn Gillmor
2016-07-14 13:59   ` David Bremner
2016-07-14 16:22     ` Daniel Kahn Gillmor
2016-07-15  0:23       ` David Bremner
2016-07-15  7:46         ` Daniel Kahn Gillmor
2016-08-13 13:23   ` David Bremner
2016-07-08  9:27 ` [PATCH v4 10/16] Add n_d_add_message_with_indexopts (extension of n_d_add_message) Daniel Kahn Gillmor
2016-08-14  0:08   ` David Bremner
2016-07-08  9:27 ` [PATCH v4 11/16] add --try-decrypt to notmuch insert Daniel Kahn Gillmor
2016-08-14  0:16   ` David Bremner
2016-07-08  9:27 ` Daniel Kahn Gillmor [this message]
2016-08-14  0:22   ` [PATCH v4 12/16] add --try-decrypt to notmuch new David Bremner
2016-07-08  9:27 ` [PATCH v4 13/16] add indexopts to notmuch python bindings Daniel Kahn Gillmor
2016-08-14  0:41   ` David Bremner
2016-07-08  9:27 ` [PATCH v4 14/16] test indexing cleartext version of delivered messages Daniel Kahn Gillmor
2016-08-14  1:14   ` David Bremner
2016-07-08  9:27 ` [PATCH v4 15/16] added notmuch_message_reindex Daniel Kahn Gillmor
2016-08-14 12:43   ` [PATCH] WIP: remove all non-prefixed-terms (and stemmed versions) David Bremner
2017-04-02 14:52     ` David Bremner
2016-07-08  9:27 ` [PATCH v4 16/16] add "notmuch reindex" subcommand Daniel Kahn Gillmor
2016-08-14 22:42   ` David Bremner
2016-08-14 23:41     ` Olly Betts

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=1467970047-8013-13-git-send-email-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).