python-o365
python-o365 copied to clipboard
Query: Or condition breaking date ranges.
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?
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.
Try with open_group
and close_group
.
Those effectively add parenthesis to the ODATA formula.
Try with
open_group
andclose_group
.
Does this worked for you?