Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
IMAP multiple FROM query builder
def build_multiple_from_query(emails: List[str]) -> str:
# IMAP query composition: (OR (OR (FROM a@a.ru) (FROM b@b.ru)) (FROM c@c.ru))
def gather(a: str, b: str) -> str:
if 'FROM' not in a:
return f'OR (FROM "{a}") (FROM "{b}")'
else:
return f'OR ({a}) (FROM "{b}")'
return f'({reduce(gather, emails)})' if len(emails) > 1 else f'FROM {emails[0]}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.