New Python bindings (notmuch2 module) fail to exclude tags

2020-11-20 Thread Jorge P. de Morais Neto
Hi.  I am trying to migrate my Python3 script to the new Python bindings
(notmuch2 module).  However, I cannot obtain a count of messages
matching a query excluding messages that have an exclude tag.  From the
command line:
$ notmuch count 'is:.bf_spam'
0

The CLI command correctly counts zero messages having '.bf_spam' tag,
because all such messages also have the excluded 'spam' tag.  But from
Python:

$ python3
Python 3.7.3 (default, Jul 25 2020, 13:03:44) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import notmuch2
>>> nm_db=notmuch2.Database()
>>> nm_db.count_messages('is:.bf_spam', exclude_tags=('spam',))
379
>>> nm_db.count_messages('is:.bf_spam', exclude_tags=('spam',), 
>>> omit_excluded=nm_db.EXCLUDE.FALSE)
379
>>> nm_db.count_messages('is:.bf_spam', exclude_tags=('spam',), 
>>> omit_excluded=nm_db.EXCLUDE.TRUE)
379
>>> nm_db.count_messages('is:.bf_spam', exclude_tags=('spam',), 
>>> omit_excluded=nm_db.EXCLUDE.ALL)
379
>>> nm_db.count_messages('is:.bf_spam', exclude_tags=('spam',), 
>>> omit_excluded=nm_db.EXCLUDE.FLAG)
379

Am I doing something wrong?

Regards

-- 
- 
- If an email of mine arrives at your spam box, please notify me.
- Please adopt free/libre formats like PDF, ODF, Org, LaTeX, Opus, WebM and 7z.
- Free/libre software for Replicant, LineageOS and Android: https://f-droid.org
- [[https://www.gnu.org/philosophy/free-sw.html][What is free software?]]
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: New Python bindings (notmuch2 module) fail to exclude tags

2020-11-20 Thread Floris Bruynooghe
Hi Jorge,

On Fri 20 Nov 2020 at 12:54 -0300, Jorge P. de Morais Neto wrote:

> Hi.  I am trying to migrate my Python3 script to the new Python bindings
> (notmuch2 module).  However, I cannot obtain a count of messages
> matching a query excluding messages that have an exclude tag.  From the
> command line:
> $ notmuch count 'is:.bf_spam'
> 0
>
> The CLI command correctly counts zero messages having '.bf_spam' tag,
> because all such messages also have the excluded 'spam' tag.  But from
> Python:
>
> $ python3
> Python 3.7.3 (default, Jul 25 2020, 13:03:44) 
> [GCC 8.3.0] on linux
> Type "help", "copyright", "credits" or "license" for more information.
 import notmuch2
 nm_db=notmuch2.Database()
 nm_db.count_messages('is:.bf_spam', exclude_tags=('spam',))
> 379
 nm_db.count_messages('is:.bf_spam', exclude_tags=('spam',), 
 omit_excluded=nm_db.EXCLUDE.FALSE)
> 379
 nm_db.count_messages('is:.bf_spam', exclude_tags=('spam',), 
 omit_excluded=nm_db.EXCLUDE.TRUE)
> 379
 nm_db.count_messages('is:.bf_spam', exclude_tags=('spam',), 
 omit_excluded=nm_db.EXCLUDE.ALL)
> 379
 nm_db.count_messages('is:.bf_spam', exclude_tags=('spam',), 
 omit_excluded=nm_db.EXCLUDE.FLAG)
> 379

Personally I find the description of these flags in notmuch.h not very
clear and don't claim to understand them (this probably explains the
really bad docstring, we should improve those).  But I expected to at
least see the EXCLUDE.TRUE one, the default, to work.

Looking at the implementation I don't seem much that could have gone
wrong.  However I did notice the bindings fail to check the return code
in one call where it probably should, you could try with this patch?

diff --git a/bindings/python-cffi/notmuch2/_database.py 
b/bindings/python-cffi/notmuch2/_database.py
index 5ab0f20a..5dbfe68e 100644
--- a/bindings/python-cffi/notmuch2/_database.py
+++ b/bindings/python-cffi/notmuch2/_database.py
@@ -579,7 +579,10 @@ class Database(base.NotmuchObject):
 for tag in exclude_tags:
 if isinstance(tag, str):
 tag = str.encode('utf-8')
-capi.lib.notmuch_query_add_tag_exclude(query_p, tag)
+ret = capi.lib.notmuch_query_add_tag_exclude(query_p, tag)
+if ret not in [capi.lib.NOTMUCH_STATUS_SUCCESS,
+   capi.lib.NOTMUCH_STATUS_IGNORED]:
+raise errors.NotmuchError(ret)
 return querymod.Query(self, query_p)
 
 def messages(self, query, *,

To experiment you could also raise the exception for
NOTMUCH_STATUS_IGNORED, even though for the bindings to silently swallow
this is probably the best (this is really the bindings being more
limiting than the C lib, if this bothers ppl we could add another
keyword arg to let this raise as well).

While the above patch is probably good, I feel like it's clutching at
straws and unlikely to solve your problem.  Could you try to reproduce
this in plain C or maybe even in pretend-plain-c by using the
capi.lib.notmuch_* calls directly?


Cheers,
Floris
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: New Python bindings (notmuch2 module) fail to exclude tags

2020-11-20 Thread David Bremner
"Jorge P. de Morais Neto"  writes:

> Hi.  I am trying to migrate my Python3 script to the new Python bindings
> (notmuch2 module).  However, I cannot obtain a count of messages
> matching a query excluding messages that have an exclude tag.  From the
> command line:
> $ notmuch count 'is:.bf_spam'
> 0
>
> The CLI command correctly counts zero messages having '.bf_spam' tag,
> because all such messages also have the excluded 'spam' tag.  But from
> Python:
>
> $ python3
> Python 3.7.3 (default, Jul 25 2020, 13:03:44) 
> [GCC 8.3.0] on linux
> Type "help", "copyright", "credits" or "license" for more information.
 import notmuch2
 nm_db=notmuch2.Database()
 nm_db.count_messages('is:.bf_spam', exclude_tags=('spam',))
> 379
 nm_db.count_messages('is:.bf_spam', exclude_tags=('spam',), 
 omit_excluded=nm_db.EXCLUDE.FALSE)
> 379
 nm_db.count_messages('is:.bf_spam', exclude_tags=('spam',), 
 omit_excluded=nm_db.EXCLUDE.TRUE)
> 379
 nm_db.count_messages('is:.bf_spam', exclude_tags=('spam',), 
 omit_excluded=nm_db.EXCLUDE.ALL)
> 379
 nm_db.count_messages('is:.bf_spam', exclude_tags=('spam',), 
 omit_excluded=nm_db.EXCLUDE.FLAG)
> 379
>

It looks like a bug, but I'm not very expert with the python bindings,
so I've CCed the author of the new bindings. It would be great if you
could make a small test case that does not rely on your mail store.

d
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: listing all the tags I've been using

2020-11-20 Thread Alan Schmitt
On 2020-11-20 15:33, Kim Minh Kaplan  writes:

> Alan Schmitt writes:
>
>> I would like to list all
>> the tags I've used. Is there a way to do it?
>
> notmuch search --output=tags '*'

Thanks a lot Ralph and Kim. For the record, I refined Ralph's solution
to:

notmuch dump | tail -n +2 | gawk -F '--' '{print $1}' | gawk -F ' ' '{ for(i=1; 
i<=NF; i+=1) {printf "%s\n", $i;}}' | sort -u

which I can now happily throw away ;)

Best,

Alan


signature.asc
Description: PGP signature
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: listing all the tags I've been using

2020-11-20 Thread Ralph Seichter
* Kim Minh Kaplan:

> notmuch search --output=tags '*'

That's much nicer than my idea. Thanks.

-Ralph
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: listing all the tags I've been using

2020-11-20 Thread Kim Minh Kaplan
Alan Schmitt writes:

> I would like to list all
> the tags I've used. Is there a way to do it?

notmuch search --output=tags '*'

Kim Minh.
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: listing all the tags I've been using

2020-11-20 Thread Ralph Seichter
* Alan Schmitt:

> I'm trying to document the tags I'm using for notmuch [...]

The following should get you started (untested, from memory):

  notmuch dump | gawk -F '--' '{print $1}' | sort -u

Feel free to add some more AWK magic instead of the "sort -u" to
group/count by tag name.

-Ralph
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


listing all the tags I've been using

2020-11-20 Thread Alan Schmitt
Hello,

I'm trying to document the tags I'm using for notmuch and make sure I
have not introduced duplication or typos. So I would like to list all
the tags I've used. Is there a way to do it?

Thanks,

Alan


signature.asc
Description: PGP signature
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org