Search code examples
pythonpython-re

Using expression matching inside a string


I'm using imap_tools package to download attachments from my mail. To search for emails that I want to be included I use the function as described in documentation.

messages = mb.fetch(criteria=AND(seen=False, from_="email@test.com"), mark_seen=True, bulk=True)

How can I use expression matching in that case to find any mail from @test.com domain? I mean something like below but working:

messages = mb.fetch(criteria=AND(seen=False, from_="\w+@test.com"), mark_seen=True, bulk=True)

Solution

  • AND(from_="@test.com")