simplegmail icon indicating copy to clipboard operation
simplegmail copied to clipboard

Cannot negate boolean queries with False

Open MooseV2 opened this issue 3 years ago • 1 comments

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 avatar Apr 14 '22 15:04 MooseV2

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.

MooseV2 avatar Apr 14 '22 15:04 MooseV2