From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id 2Nn0NWdo0GELLwEAgWs5BA (envelope-from ) for ; Sat, 01 Jan 2022 15:42:47 +0100 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id 2Aw9M2do0GFuBwAA9RJhRA (envelope-from ) for ; Sat, 01 Jan 2022 15:42:47 +0100 Received: from mail.notmuchmail.org (yantan.tethera.net [135.181.149.255]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id A052E1AF54 for ; Sat, 1 Jan 2022 15:42:47 +0100 (CET) Received: from yantan.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 014D05F710; Sat, 1 Jan 2022 14:42:44 +0000 (UTC) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by mail.notmuchmail.org (Postfix) with ESMTP id 27DDB5F5EE for ; Sat, 1 Jan 2022 14:42:41 +0000 (UTC) Received: by fethera.tethera.net (Postfix, from userid 1001) id A0AC95FC42; Sat, 1 Jan 2022 09:42:40 -0500 (EST) Received: (nullmailer pid 161486 invoked by uid 1000); Sat, 01 Jan 2022 14:42:39 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: [PATCH] bindings/python-cffi: add matched property to message objects Date: Sat, 1 Jan 2022 10:42:28 -0400 Message-Id: <20220101144228.161473-1-david@tethera.net> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Message-ID-Hash: 6AJ3OUN4TGQWY74NTERY2YZKURZGQJPV X-Message-ID-Hash: 6AJ3OUN4TGQWY74NTERY2YZKURZGQJPV X-MailFrom: bremner@tethera.net X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.3 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN X-Migadu-Country: DE ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1641048167; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-owner:list-unsubscribe:list-subscribe:list-post; bh=4M7hprg5uzXWYtEM9k/BBtEbQ2VEZ0CDCjPb6OnslL4=; b=ZonFK8jBpqBaLkoxnaHy3nNLC/hO2PeI2rHdJLWCrC7bUKqcEMqfnj8q6DJSzYAMnVGPDn bqd0oL6MEHwPFqh2RQOKgMj3AtdqTUzxLOHg6lPcjJ+pFIlcUOSHSNue0FDD7oe/1APSKg zl6895izlPzw3J05Sl3ZESBKNWGs1qHv6jdS88si7YhhTNnhCGmrHTPi99sbUKWWi6Nvms NUJzucriQ9u5xlnafk9O2Rs8F+48a6wyuAPUn7hQuWKFsxo1bgBFoR7EB56CjWNVLxIs6X YFTV50Juzi58gE+nz7uODh7YLogoDoOJ1witvDVzvDx+j6lOMxSQK/+v6KpI0w== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1641048167; a=rsa-sha256; cv=none; b=MMswEbrJuGNORFQj9XcVTI0AvWu5bHAL10sZ2+nal6m5NhrI8yswyCNajMcsZy7jf2etFV /H8OtcmKmTIfFwC6dyQyz3u9z5SOy0rB5SNN7UZ3jtp5xjZEu/e63NSywFSTEQR5qFEH/F qaMuZYbtZBvv7R6ZwTlSC7qlnlNVT2H8tA05fng9xaRQ+qOKmTcNBtVy5ikDWFH080GknV ord9/vYc1kMa2rSey5YoIfT3UvoSs5gDJVO8xRSevRvywKDKX2EERFK9xApCt1ZAdwpbpz Bv7ebEr1t9DYM0pQ426sPh+a/2zvQPVE6UcxXWk+6UAZCVhTmxd/hht/to5xEg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 135.181.149.255 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: -1.27 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 135.181.149.255 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: A052E1AF54 X-Spam-Score: -1.27 X-Migadu-Scanner: scn1.migadu.com X-TUID: i2HE8w5vDQQt 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 | 14 ++++++++++++++ bindings/python-cffi/tests/test_message.py | 3 +++ bindings/python-cffi/tests/test_thread.py | 7 +++++++ 3 files changed, 24 insertions(+) diff --git a/bindings/python-cffi/notmuch2/_message.py b/bindings/python-cffi/notmuch2/_message.py index 2f232076..a460d8c1 100644 --- a/bindings/python-cffi/notmuch2/_message.py +++ b/bindings/python-cffi/notmuch2/_message.py @@ -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. diff --git a/bindings/python-cffi/tests/test_message.py b/bindings/python-cffi/tests/test_message.py index 532bf921..56701d05 100644 --- a/bindings/python-cffi/tests/test_message.py +++ b/bindings/python-cffi/tests/test_message.py @@ -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. diff --git a/bindings/python-cffi/tests/test_thread.py b/bindings/python-cffi/tests/test_thread.py index 1f44b35d..fbef73ac 100644 --- a/bindings/python-cffi/tests/test_thread.py +++ b/bindings/python-cffi/tests/test_thread.py @@ -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) -- 2.34.1