python-o365 icon indicating copy to clipboard operation
python-o365 copied to clipboard

Query: Or condition breaking date ranges.

Open Aens opened this issue 3 years ago • 3 comments

So, this is pretty straightforward query for a mailbox object, take a look at the query:

query = mailbox.new_query()
(query
.on_attribute("from")
.contains("[email protected]")
# .chain('or')
# .contains("[email protected]")
.chain('and')
.on_attribute('receivedDateTime')
.greater_equal(datetime(2021, 6, 14))
.chain('and')
.on_attribute('receivedDateTime')
.less_equal(datetime(2021, 6, 23)))

When I un-comment those 2 lines, the code gets mails from outside of that date range. Is it a bug?

Aens avatar Jun 24 '21 14:06 Aens

Update: A workaround has been adding the date ranges for EACH address, but isn't that a bit... annoying?

query = mailbox.new_query()
(query
.on_attribute("from")
.contains("[email protected]")
.chain('and')
.on_attribute('receivedDateTime')
.greater_equal(datetime(2021, 6, 14))
.chain('and')
.on_attribute('receivedDateTime')
.less_equal(datetime(2021, 6, 23))
.chain('or')
.contains("[email protected]")
.chain('and')
.on_attribute('receivedDateTime')
.greater_equal(datetime(2021, 6, 14))
.chain('and')
.on_attribute('receivedDateTime')
.less_equal(datetime(2021, 6, 23))
)

I can see this becoming very obnoxious once we have many different addresses.

Aens avatar Jun 25 '21 09:06 Aens

Try with open_group and close_group.

Those effectively add parenthesis to the ODATA formula.

alejcas avatar Jun 28 '21 08:06 alejcas

Try with open_group and close_group.

Does this worked for you?

alejcas avatar Sep 03 '21 09:09 alejcas