Created
March 27, 2020 10:43
-
-
Save zmej-serow/4d6292591c690563e7dd205964f8b8ee to your computer and use it in GitHub Desktop.
IMAP multiple FROM query builder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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