-2

I am working on a script that needs to filter subject using regex. Does exchangelib support that? If so, can I get some examples?

Erik Cederstrand
  • 9,643
  • 8
  • 39
  • 63
Ladu anand
  • 646
  • 2
  • 8
  • 30

1 Answers1

0

Regular expressions are not supported in EWS, so you can't do the filtering server-side. You'll have to pull all items and do the filtering client-side:

for item in account.inbox.all():
    if re.match(r'some_regexp', item.subject):
        # Do something

If you expect to match only very few items, you could optimize by first fetching only the subject field, and then full items:

matches = []
for item in account.inbox.all().only('subject'):
    if re.match(r'some_regexp', item.subject):
        matches.append(item)
full_items = account.fetch(matches)
Erik Cederstrand
  • 9,643
  • 8
  • 39
  • 63