conditional count of ews inbox - exchangelib query

531 views Asked by At

I have a requirement to know how many Messages(preferably) exist in an Inbox since a certain date, before actually retrieving them. I read about and experimented with account.inbox.total_count via the Exchangelib PyPI site. However, I am unable to make it work - it does not seem to take parameters. Is there a way to do a conditional retrieval of email count please? The context: Need to compute the increments of a progress bar to display to user via Yield / javascript eventstream. With thanks. Patrick

1

There are 1 answers

1
Erik Cederstrand On BEST ANSWER

Folder.total_count is a read-only property that the server sends along with other information on the folder. It's an approximate count on all items contained in the folder. You can't use that for your purposes because you only want the count since some date.

To do what you want, have a look at the QuerySet.count() method:

# Get number of messages in the inbox messages since some date
n = account.inbox.filter(datetime_received__gt=some_date).count()