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 4/9] Add new n_d_add_message_try_decrypt (analogous to to n_d_add_message)
Date: Wed,  9 Dec 2015 22:39:41 -0500	[thread overview]
Message-ID: <1449718786-28000-5-git-send-email-dkg@fifthhorseman.net> (raw)
In-Reply-To: <1449718786-28000-1-git-send-email-dkg@fifthhorseman.net>

When adding a message to the database, optionally try to decrypt the
message and index the cleartext.

Note that when a message is retrieved from the database, it will not
have this flag attached to it necessarily (though users can inspect
the tags that were attached during decryption/indexing)
---
 lib/database.cc | 31 ++++++++++++++++++++++++++++---
 lib/notmuch.h   | 19 +++++++++++++++++++
 2 files changed, 47 insertions(+), 3 deletions(-)

diff --git a/lib/database.cc b/lib/database.cc
index 13b0bad..62bc6d9 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -2429,9 +2429,10 @@ _notmuch_database_get_crypto_for_protocol (notmuch_database_t *notmuch,
 }
 
 notmuch_status_t
-notmuch_database_add_message (notmuch_database_t *notmuch,
-			      const char *filename,
-			      notmuch_message_t **message_ret)
+_notmuch_database_add_message_with_options (notmuch_database_t *notmuch,
+					    const char *filename,
+					    notmuch_bool_t decrypt,
+					    notmuch_message_t **message_ret)
 {
     notmuch_message_file_t *message_file;
     notmuch_message_t *message = NULL;
@@ -2550,6 +2551,8 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
 	    date = _notmuch_message_file_get_header (message_file, "date");
 	    _notmuch_message_set_header_values (message, date, from, subject);
 
+	    notmuch_message_set_flag (message, NOTMUCH_MESSAGE_FLAG_INDEX_DECRYPTED, decrypt);
+
 	    ret = _notmuch_message_index_file (message, message_file);
 	    if (ret)
 		goto DONE;
@@ -2587,6 +2590,28 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
     return ret;
 }
 
+
+notmuch_status_t
+notmuch_database_add_message (notmuch_database_t *notmuch,
+			      const char *filename,
+			      notmuch_message_t **message_ret)
+{
+    return _notmuch_database_add_message_with_options (notmuch, filename,
+						       false,
+						       message_ret);
+    
+}
+notmuch_status_t
+notmuch_database_add_message_try_decrypt (notmuch_database_t *notmuch,
+					  const char *filename,
+					  notmuch_message_t **message_ret)
+{
+    return _notmuch_database_add_message_with_options (notmuch, filename,
+						       true,
+						       message_ret);
+    
+}
+
 notmuch_status_t
 notmuch_database_remove_message (notmuch_database_t *notmuch,
 				 const char *filename)
diff --git a/lib/notmuch.h b/lib/notmuch.h
index e7085b7..809a2ea 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -570,6 +570,25 @@ notmuch_status_t
 notmuch_database_add_message (notmuch_database_t *database,
 			      const char *filename,
 			      notmuch_message_t **message);
+/**
+ * Add a new message to the given notmuch database or associate an
+ * additional filename with an existing message.
+ * 
+ * This does the same thing as notmuch_database_add_message except
+ * that it if part of the message is encrypted, it also tries to
+ * decrypt the message and index the cleartext version if it can.
+ * 
+ * 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 FUNCTION
+ * without considering the security of your index.
+ * 
+ * FIXME: document new error codes here.
+ */
+notmuch_status_t
+notmuch_database_add_message_try_decrypt (notmuch_database_t *database,
+					  const char *filename,
+					  notmuch_message_t **message);
 
 /**
  * Remove a message filename from the given notmuch database. If the
-- 
2.6.2

  parent reply	other threads:[~2015-12-10  3:40 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-10  3:39 allow indexing cleartext of encrypted messages Daniel Kahn Gillmor
2015-12-10  3:39 ` [PATCH 1/9] reorganize indexing of multipart/signed and multipart/encrypted Daniel Kahn Gillmor
2015-12-11 21:53   ` Tomi Ollila
2015-12-10  3:39 ` [PATCH 2/9] Add a lazily-initialized crypto context to notmuch_database_t Daniel Kahn Gillmor
2015-12-11 14:03   ` David Bremner
2015-12-11 14:36     ` Daniel Kahn Gillmor
2015-12-11 21:55   ` Tomi Ollila
2015-12-10  3:39 ` [PATCH 3/9] index encrypted parts when the message is flagged appropriately Daniel Kahn Gillmor
2015-12-10  3:39 ` Daniel Kahn Gillmor [this message]
2015-12-10  3:39 ` [PATCH 5/9] Enable cleartext indexing in python bindings Daniel Kahn Gillmor
2015-12-10  3:39 ` [PATCH 6/9] search for a reasonable gpg implementation Daniel Kahn Gillmor
2015-12-11 21:56   ` Tomi Ollila
2015-12-11 22:18     ` J. Lewis Muir
2015-12-11 22:22       ` Daniel Kahn Gillmor
2015-12-10  3:39 ` [PATCH 7/9] add a gpg_path value for notmuch_database_t Daniel Kahn Gillmor
2015-12-11 22:02   ` Tomi Ollila
2015-12-11 22:25     ` Daniel Kahn Gillmor
2015-12-12 23:25       ` Tomi Ollila
2015-12-13  1:20       ` David Bremner
2015-12-13 11:00         ` Tomi Ollila
2015-12-13 11:17           ` Tomi Ollila
2016-01-15 19:11             ` Daniel Kahn Gillmor
2015-12-11 22:35   ` J. Lewis Muir
2015-12-12  4:10     ` Daniel Kahn Gillmor
2015-12-10  3:39 ` [PATCH 8/9] add --try-decrypt to notmuch insert Daniel Kahn Gillmor
2015-12-10  3:39 ` [PATCH 9/9] add --try-decrypt to notmuch new Daniel Kahn Gillmor
2015-12-11 15:34 ` allow indexing cleartext of encrypted messages Daniel Kahn Gillmor
2015-12-11 22:05   ` Tomi Ollila

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=1449718786-28000-5-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).