From: Daniel Kahn Gillmor Date: Thu, 10 Dec 2015 03:39:42 +0000 (+1900) Subject: [PATCH 5/9] Enable cleartext indexing in python bindings X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=d6edcfb55e08f456dcd58c17cf4a3b832d8decf7;p=notmuch-archives.git [PATCH 5/9] Enable cleartext indexing in python bindings --- diff --git a/f3/b5b1aaa54bc3ded8824e4e94b978ecfd3d3216 b/f3/b5b1aaa54bc3ded8824e4e94b978ecfd3d3216 new file mode 100644 index 000000000..e26fdc83b --- /dev/null +++ b/f3/b5b1aaa54bc3ded8824e4e94b978ecfd3d3216 @@ -0,0 +1,105 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by arlo.cworth.org (Postfix) with ESMTP id CD5E46DE1601 + for ; Wed, 9 Dec 2015 19:40:10 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at cworth.org +X-Spam-Flag: NO +X-Spam-Score: -0.035 +X-Spam-Level: +X-Spam-Status: No, score=-0.035 tagged_above=-999 required=5 + tests=[AWL=-0.035] 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 zkScRCzV1gyZ for ; + Wed, 9 Dec 2015 19:40:09 -0800 (PST) +Received: from che.mayfirst.org (che.mayfirst.org [209.234.253.108]) + by arlo.cworth.org (Postfix) with ESMTP id 49A856DE1603 + 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 2D023F986 + for ; Wed, 9 Dec 2015 22:40:04 -0500 (EST) +Received: by fifthhorseman.net (Postfix, from userid 1000) + id B564220DD2; Wed, 9 Dec 2015 22:40:03 -0500 (EST) +From: Daniel Kahn Gillmor +To: Notmuch Mail +Subject: [PATCH 5/9] Enable cleartext indexing in python bindings +Date: Wed, 9 Dec 2015 22:39:42 -0500 +Message-Id: <1449718786-28000-6-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:11 -0000 + +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 +