From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 6A7A46DE1603 for ; Wed, 9 Dec 2015 19:40:12 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.034 X-Spam-Level: X-Spam-Status: No, score=-0.034 tagged_above=-999 required=5 tests=[AWL=-0.034] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Xwybk9hgZA-V for ; Wed, 9 Dec 2015 19:40:10 -0800 (PST) Received: from che.mayfirst.org (che.mayfirst.org [209.234.253.108]) by arlo.cworth.org (Postfix) with ESMTP id 021F56DE1829 for ; Wed, 9 Dec 2015 19:40:05 -0800 (PST) Received: from fifthhorseman.net (unknown [38.109.115.130]) by che.mayfirst.org (Postfix) with ESMTPSA id 34C69F985 for ; Wed, 9 Dec 2015 22:40:03 -0500 (EST) Received: by fifthhorseman.net (Postfix, from userid 1000) id AF15320C0C; Wed, 9 Dec 2015 22:40:03 -0500 (EST) From: Daniel Kahn Gillmor To: Notmuch Mail 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 Message-Id: <1449718786-28000-5-git-send-email-dkg@fifthhorseman.net> X-Mailer: git-send-email 2.6.2 In-Reply-To: <1449718786-28000-1-git-send-email-dkg@fifthhorseman.net> References: <1449718786-28000-1-git-send-email-dkg@fifthhorseman.net> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 10 Dec 2015 03:40:13 -0000 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