[PATCH 5/9] Enable cleartext indexing in python bindings

Daniel Kahn Gillmor dkg at fifthhorseman.net
Wed Dec 9 19:39:42 PST 2015


The python add_message function now includes a try_decrypt flag to
permit indexing the cleartext of the mail where possible.
---
 bindings/python/notmuch/database.py | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/bindings/python/notmuch/database.py b/bindings/python/notmuch/database.py
index 5b58e09..8e25a05 100644
--- a/bindings/python/notmuch/database.py
+++ b/bindings/python/notmuch/database.py
@@ -388,8 +388,13 @@ class Database(object):
     _add_message.argtypes = [NotmuchDatabaseP, c_char_p,
                              POINTER(NotmuchMessageP)]
     _add_message.restype = c_uint
-
-    def add_message(self, filename, sync_maildir_flags=False):
+    
+    _add_message_try_decrypt = nmlib.notmuch_database_add_message_try_decrypt
+    _add_message_try_decrypt.argtypes = [NotmuchDatabaseP, c_char_p,
+                                         POINTER(NotmuchMessageP)]
+    _add_message_try_decrypt.restype = c_uint
+    
+    def add_message(self, filename, sync_maildir_flags=False, try_decrypt=False):
         """Adds a new message to the database
 
         :param filename: should be a path relative to the path of the
@@ -410,6 +415,13 @@ class Database(object):
             API. You might want to look into the underlying method
             :meth:`Message.maildir_flags_to_tags`.
 
+        :param try_decrypt: If the message hasn't been seen by the
+            index before, and it includes any encrypted parts, try to
+            index the cleartext if set to `True`.  Note that this
+            means that the cleartext of the message is effectively
+            stored in the database index, so DO NOT SET THIS FLAG
+            without considering the security of your index.
+
         :returns: On success, we return
 
            1) a :class:`Message` object that can be used for things
@@ -437,10 +449,14 @@ class Database(object):
               :attr:`STATUS`.READ_ONLY_DATABASE
                       Database was opened in read-only mode so no message can
                       be added.
+
         """
         self._assert_db_is_initialized()
         msg_p = NotmuchMessageP()
-        status = self._add_message(self._db, _str(filename), byref(msg_p))
+        if (try_decrypt):
+            status = self._add_message_try_decrypt(self._db, _str(filename), byref(msg_p))
+        else:
+            status = self._add_message(self._db, _str(filename), byref(msg_p))
 
         if not status in [STATUS.SUCCESS, STATUS.DUPLICATE_MESSAGE_ID]:
             raise NotmuchError(status)
-- 
2.6.2



More information about the notmuch mailing list