jeremyephron / simplegmail

A simple Gmail API client for applications in Python
MIT License
339 stars 73 forks source link

"exclude_<keyword>" does not work with "exact_phrase" #35

Closed dagz214 closed 3 years ago

dagz214 commented 3 years ago

Using exclude_<keyword> to negate a term works with starred (e.g exclude_starred),
but when trying to use exclude_exact_phrase nothing happens.
So no way to filter out important messages from large group of messages based on a text parameter.

jeremyephron commented 3 years ago

@dagz214 Thanks for posting the issue, will look into this bug.

jeremyephron commented 3 years ago

@dagz214 The following works for me (for example):

from simplegmail import Gmail
from simplegmail.query import construct_query

gmail = Gmail()
msgs = gmail.get_unread_inbox(query=construct_query(exact_phrase='some text', exclude_exact_phrase=True))

Can you double check your code, or include it here if it still does not work?

I admit this isn't the cleanest interface, so I may be modifying this in the future.

dagz214 commented 3 years ago

Hi @jeremyephron thanks for replying. Ok, so that explains why it worked with booleans.
I misread the docstring and passed it as exclude_exact_phrase='some text'.

I'm actualy passing the arguments with a yaml file to automate repeating tasks.
I'd appreciate if you'd check it out

jeremyephron commented 3 years ago

@dagz214 It looks very cool from what I've seen so far, I'm glad you could make use of the library!

I've changed the behavior of exclude_<keyword> in v4.0.0 so be aware before updating, but it also should make things simpler and more expressive. See #37 for some examples I provided there in the last comment (that begins with mentioning the new v4.0.0). Basically, now instead of having exclude_<keyword> negate the values of <keyword> it just negates its own values, so construct_query(labels='homework', exclude_labels='cs') will match message that have the 'homework' label and not the 'cs' label.