[PATCH 4/9] Add new n_d_add_message_try_decrypt (analogous to to n_d_add_message)
authorDaniel Kahn Gillmor <dkg@fifthhorseman.net>
Thu, 10 Dec 2015 03:39:41 +0000 (22:39 +1900)
committerW. Trevor King <wking@tremily.us>
Sat, 20 Aug 2016 21:50:09 +0000 (14:50 -0700)
ae/de0053f4cbf83dc48c17c25dbd4cad0f809ad9 [new file with mode: 0644]

diff --git a/ae/de0053f4cbf83dc48c17c25dbd4cad0f809ad9 b/ae/de0053f4cbf83dc48c17c25dbd4cad0f809ad9
new file mode 100644 (file)
index 0000000..8e4b4dc
--- /dev/null
@@ -0,0 +1,147 @@
+Return-Path: <dkg@fifthhorseman.net>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by arlo.cworth.org (Postfix) with ESMTP id 6A7A46DE1603\r
+ for <notmuch@notmuchmail.org>; Wed,  9 Dec 2015 19:40:12 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.034\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.034 tagged_above=-999 required=5\r
+ tests=[AWL=-0.034] autolearn=disabled\r
+Received: from arlo.cworth.org ([127.0.0.1])\r
+ by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id Xwybk9hgZA-V for <notmuch@notmuchmail.org>;\r
+ Wed,  9 Dec 2015 19:40:10 -0800 (PST)\r
+Received: from che.mayfirst.org (che.mayfirst.org [209.234.253.108])\r
+ by arlo.cworth.org (Postfix) with ESMTP id 021F56DE1829\r
+ for <notmuch@notmuchmail.org>; Wed,  9 Dec 2015 19:40:05 -0800 (PST)\r
+Received: from fifthhorseman.net (unknown [38.109.115.130])\r
+ by che.mayfirst.org (Postfix) with ESMTPSA id 34C69F985\r
+ for <notmuch@notmuchmail.org>; Wed,  9 Dec 2015 22:40:03 -0500 (EST)\r
+Received: by fifthhorseman.net (Postfix, from userid 1000)\r
+ id AF15320C0C; Wed,  9 Dec 2015 22:40:03 -0500 (EST)\r
+From: Daniel Kahn Gillmor <dkg@fifthhorseman.net>\r
+To: Notmuch Mail <notmuch@notmuchmail.org>\r
+Subject: [PATCH 4/9] Add new n_d_add_message_try_decrypt (analogous to to\r
+ n_d_add_message)\r
+Date: Wed,  9 Dec 2015 22:39:41 -0500\r
+Message-Id: <1449718786-28000-5-git-send-email-dkg@fifthhorseman.net>\r
+X-Mailer: git-send-email 2.6.2\r
+In-Reply-To: <1449718786-28000-1-git-send-email-dkg@fifthhorseman.net>\r
+References: <1449718786-28000-1-git-send-email-dkg@fifthhorseman.net>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.20\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Thu, 10 Dec 2015 03:40:13 -0000\r
+\r
+When adding a message to the database, optionally try to decrypt the\r
+message and index the cleartext.\r
+\r
+Note that when a message is retrieved from the database, it will not\r
+have this flag attached to it necessarily (though users can inspect\r
+the tags that were attached during decryption/indexing)\r
+---\r
+ lib/database.cc | 31 ++++++++++++++++++++++++++++---\r
+ lib/notmuch.h   | 19 +++++++++++++++++++\r
+ 2 files changed, 47 insertions(+), 3 deletions(-)\r
+\r
+diff --git a/lib/database.cc b/lib/database.cc\r
+index 13b0bad..62bc6d9 100644\r
+--- a/lib/database.cc\r
++++ b/lib/database.cc\r
+@@ -2429,9 +2429,10 @@ _notmuch_database_get_crypto_for_protocol (notmuch_database_t *notmuch,\r
+ }\r
\r
+ notmuch_status_t\r
+-notmuch_database_add_message (notmuch_database_t *notmuch,\r
+-                            const char *filename,\r
+-                            notmuch_message_t **message_ret)\r
++_notmuch_database_add_message_with_options (notmuch_database_t *notmuch,\r
++                                          const char *filename,\r
++                                          notmuch_bool_t decrypt,\r
++                                          notmuch_message_t **message_ret)\r
+ {\r
+     notmuch_message_file_t *message_file;\r
+     notmuch_message_t *message = NULL;\r
+@@ -2550,6 +2551,8 @@ notmuch_database_add_message (notmuch_database_t *notmuch,\r
+           date = _notmuch_message_file_get_header (message_file, "date");\r
+           _notmuch_message_set_header_values (message, date, from, subject);\r
\r
++          notmuch_message_set_flag (message, NOTMUCH_MESSAGE_FLAG_INDEX_DECRYPTED, decrypt);\r
++\r
+           ret = _notmuch_message_index_file (message, message_file);\r
+           if (ret)\r
+               goto DONE;\r
+@@ -2587,6 +2590,28 @@ notmuch_database_add_message (notmuch_database_t *notmuch,\r
+     return ret;\r
+ }\r
\r
++\r
++notmuch_status_t\r
++notmuch_database_add_message (notmuch_database_t *notmuch,\r
++                            const char *filename,\r
++                            notmuch_message_t **message_ret)\r
++{\r
++    return _notmuch_database_add_message_with_options (notmuch, filename,\r
++                                                     false,\r
++                                                     message_ret);\r
++    \r
++}\r
++notmuch_status_t\r
++notmuch_database_add_message_try_decrypt (notmuch_database_t *notmuch,\r
++                                        const char *filename,\r
++                                        notmuch_message_t **message_ret)\r
++{\r
++    return _notmuch_database_add_message_with_options (notmuch, filename,\r
++                                                     true,\r
++                                                     message_ret);\r
++    \r
++}\r
++\r
+ notmuch_status_t\r
+ notmuch_database_remove_message (notmuch_database_t *notmuch,\r
+                                const char *filename)\r
+diff --git a/lib/notmuch.h b/lib/notmuch.h\r
+index e7085b7..809a2ea 100644\r
+--- a/lib/notmuch.h\r
++++ b/lib/notmuch.h\r
+@@ -570,6 +570,25 @@ notmuch_status_t\r
+ notmuch_database_add_message (notmuch_database_t *database,\r
+                             const char *filename,\r
+                             notmuch_message_t **message);\r
++/**\r
++ * Add a new message to the given notmuch database or associate an\r
++ * additional filename with an existing message.\r
++ * \r
++ * This does the same thing as notmuch_database_add_message except\r
++ * that it if part of the message is encrypted, it also tries to\r
++ * decrypt the message and index the cleartext version if it can.\r
++ * \r
++ * Be aware that the index is likely sufficient to reconstruct the\r
++ * cleartext of the message itself, so please ensure that the notmuch\r
++ * message index is adequately protected. DO NOT USE THIS FUNCTION\r
++ * without considering the security of your index.\r
++ * \r
++ * FIXME: document new error codes here.\r
++ */\r
++notmuch_status_t\r
++notmuch_database_add_message_try_decrypt (notmuch_database_t *database,\r
++                                        const char *filename,\r
++                                        notmuch_message_t **message);\r
\r
+ /**\r
+  * Remove a message filename from the given notmuch database. If the\r
+-- \r
+2.6.2\r
+\r