]> git.notmuchmail.org Git - notmuch/commitdiff
bindings/python-cffi: add matched property to message objects
authorDavid Bremner <david@tethera.net>
Sat, 1 Jan 2022 14:36:43 +0000 (10:36 -0400)
committerDavid Bremner <david@tethera.net>
Sat, 1 Jan 2022 15:48:40 +0000 (11:48 -0400)
Existing users of the legacy python bindings use
message.get_flags(Message.FLAG.MATCH) to determine which messages in a
thread matched. Since the bindings don't provide get_flags anymore,
they should provide a property analogous to the existing "excluded"
property.

bindings/python-cffi/notmuch2/_message.py
bindings/python-cffi/tests/test_message.py
bindings/python-cffi/tests/test_thread.py

index 2f2320766ce9805ca88e0ea81c34c36050263a2c..a460d8c14c2d06d62c84679e5b2b2f79d7d0e604 100644 (file)
@@ -205,6 +205,20 @@ class Message(base.NotmuchObject):
             self._msg_p, capi.lib.NOTMUCH_MESSAGE_FLAG_EXCLUDED)
         return bool(ret)
 
+    @property
+    def matched(self):
+        """Indicates whether this message was matched by the query.
+
+        When a thread is created from a search, some of the
+        messages may not match the original query.  This property
+        is set to *True* for those that do match.
+
+        :raises ObjectDestroyedError: if used after destroyed.
+        """
+        ret = capi.lib.notmuch_message_get_flag(
+            self._msg_p, capi.lib.NOTMUCH_MESSAGE_FLAG_MATCH)
+        return bool(ret)
+
     @property
     def date(self):
         """The message date as an integer.
index 532bf92159dd86cb23c5cd50133fa5444c4418dd..56701d056de5ff6d1cda5e7fc0c53b1cdd8a6de5 100644 (file)
@@ -97,6 +97,9 @@ class TestMessage:
     def test_ghost_no(self, msg):
         assert not msg.ghost
 
+    def test_matched_no(self,msg):
+        assert not msg.matched
+
     def test_date(self, msg):
         # XXX Someone seems to treat things as local time instead of
         #     UTC or the other way around.
index 1f44b35d2c9e1a798ddeefe597643fb52c4eb30a..fbef73ac262c960c2196f971b92cff2b5b90c95c 100644 (file)
@@ -57,6 +57,13 @@ def test_iter(thread):
 def test_matched(thread):
     assert thread.matched == 1
 
+def test_matched_iter(thread):
+    count = 0
+    msgs = list(iter(thread))
+    for msg in msgs:
+        if msg.matched:
+            count += 1
+    assert count == thread.matched
 
 def test_authors_type(thread):
     assert isinstance(thread.authors, notmuch2.BinString)