From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id mDrsLDt+9V8yUwAA0tVLHw (envelope-from ) for ; Wed, 06 Jan 2021 09:09:15 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id eFndKDt+9V8VGAAA1q6Kng (envelope-from ) for ; Wed, 06 Jan 2021 09:09:15 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [IPv6:2607:5300:201:3100::1657]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (2048 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 57C769404E7 for ; Wed, 6 Jan 2021 09:09:15 +0000 (UTC) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id B8E5329D63; Wed, 6 Jan 2021 04:09:01 -0500 (EST) Received: from mailproxy01.manitu.net (mailproxy01.manitu.net [217.11.48.65]) by mail.notmuchmail.org (Postfix) with ESMTPS id 577E429D7E for ; Wed, 6 Jan 2021 04:08:58 -0500 (EST) Received: from localhost (200116b86027b40061b67b8d208c5aed.dip.versatel-1u1.de [IPv6:2001:16b8:6027:b400:61b6:7b8d:208c:5aed]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: michael@grubix.eu) by mailproxy01.manitu.net (Postfix) with ESMTPSA id DC18C1262989; Wed, 6 Jan 2021 10:08:44 +0100 (CET) From: Michael J Gruber To: notmuch@notmuchmail.org Subject: [PATCH 3/3] python/notmuch2: provide binding for collect_tags() Date: Wed, 6 Jan 2021 10:08:42 +0100 Message-Id: <9c89dfcf04606c9f5c1d4514096499f3ae7323d0.1609347527.git.git@grubix.eu> X-Mailer: git-send-email 2.30.0.287.g27f67507f7 In-Reply-To: References: MIME-Version: 1.0 Message-ID-Hash: L2WI6L3KUDGLOUSSZWQFK2ZES432R2VD X-Message-ID-Hash: L2WI6L3KUDGLOUSSZWQFK2ZES432R2VD X-MailFrom: git@grubix.eu 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; suspicious-header X-Mailman-Version: 3.2.1 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: 0.60 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2607:5300:201:3100::1657 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: 57C769404E7 X-Spam-Score: 0.60 X-Migadu-Scanner: scn0.migadu.com X-TUID: 5Tc5bQLmEIXa collect_tags() is accessible in the legacy bindings as a method on the messages object returned by searches. In the cffi bindings, neither queries nor their internal values are exposed, so provide a binding analogous to count_messages(). Signed-off-by: Michael J Gruber --- bindings/python-cffi/notmuch2/_database.py | 17 +++++++++++++++++ bindings/python-cffi/notmuch2/_query.py | 12 ++++++++++++ 2 files changed, 29 insertions(+) diff --git a/bindings/python-cffi/notmuch2/_database.py b/bindings/python-cffi/notmuch2/_database.py index 7592956a..f3452e11 100644 --- a/bindings/python-cffi/notmuch2/_database.py +++ b/bindings/python-cffi/notmuch2/_database.py @@ -618,6 +618,23 @@ class Database(base.NotmuchObject): exclude_tags=exclude_tags) return query.count_messages() + def collect_tags(self, query, *, + omit_excluded=EXCLUDE.TRUE, + sort=SORT.UNSORTED, # Check this default + exclude_tags=None): + """Search the database for messages and collect tags. + + :returns: The tags of all messages found. + :rtype: ImmutableTagset + + :raises ObjectDestroyedError: if used after destroyed. + """ + query = self._create_query(query, + omit_excluded=omit_excluded, + sort=sort, + exclude_tags=exclude_tags) + return query.collect_tags() + def threads(self, query, *, omit_excluded=EXCLUDE.TRUE, sort=SORT.UNSORTED, # Check this default diff --git a/bindings/python-cffi/notmuch2/_query.py b/bindings/python-cffi/notmuch2/_query.py index 1db6ec96..a1310944 100644 --- a/bindings/python-cffi/notmuch2/_query.py +++ b/bindings/python-cffi/notmuch2/_query.py @@ -2,6 +2,7 @@ from notmuch2 import _base as base from notmuch2 import _capi as capi from notmuch2 import _errors as errors from notmuch2 import _message as message +from notmuch2 import _tags as tags from notmuch2 import _thread as thread @@ -66,6 +67,17 @@ class Query(base.NotmuchObject): raise errors.NotmuchError(ret) return count_p[0] + def collect_tags(self): + """Return the tags of messages matching this query.""" + msgs_pp = capi.ffi.new('notmuch_messages_t**') + ret = capi.lib.notmuch_query_search_messages(self._query_p, msgs_pp) + if ret != capi.lib.NOTMUCH_STATUS_SUCCESS: + raise errors.NotmuchError(ret) + self._msgs_p = msgs_pp[0] + tagset = tags.ImmutableTagSet( + self, '_msgs_p', capi.lib.notmuch_messages_collect_tags) + return tags.ImmutableTagSet._from_iterable(tagset) + def threads(self): """Return an iterator over all the threads found by the query.""" threads_pp = capi.ffi.new('notmuch_threads_t **') -- 2.30.0.rc0.297.gbcca948854