Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot negate boolean queries with False #61

Open
MooseV2 opened this issue Apr 14, 2022 · 1 comment
Open

Cannot negate boolean queries with False #61

MooseV2 opened this issue Apr 14, 2022 · 1 comment

Comments

@MooseV2
Copy link

MooseV2 commented Apr 14, 2022

I would like to construct a query with negations, such as finding messages which are NOT starred.

construct_query takes in a dictionary that supports various boolean labels, but setting them to False does not add the negation operator (-).

Actual:

>>> construct_query({"starred": True})
'is:starred'

>>> construct_query({"starred": False})
'is:starred'

>>> construct_query({
    "starred": False,
    "snoozed": False,
    "unread": False,
    "important": False,
    "attachment": False,
    "drive": False,
    "docs": False,
    "sheets": False,
    "slides": False
})
'(is:starred is:snoozed is:unread is:important has:attachment has:drive has:document has:spreadsheet has:presentation)'

Expected:

>>> construct_query({"starred": True})
'is:starred'

>>> construct_query({"starred": False})
'-is:starred'

>>> construct_query({
    "starred": False,
    "snoozed": False,
    "unread": False,
    "important": False,
    "attachment": False,
    "drive": False,
    "docs": False,
    "sheets": False,
    "slides": False
})
'(-is:starred -is:snoozed -is:unread -is:important -has:attachment -has:drive -has:document -has:spreadsheet -has:presentation)'
@MooseV2
Copy link
Author

MooseV2 commented Apr 14, 2022

As a workaround for now, you can compose these queries manually, ie

construct_query({"exact_phrase": "-is:starred"})

This does add quotes to the query string ("-is:starred" vs -is:starred) but Gmail doesn't seem to mind.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant