Python exchangelib 支持过滤路径主题的多个字符串

Python exchangelib support multiple strings for filter path subject

我正在尝试搜索包含多个主题的电子邮件,但它在我的代码中只支持一个主题字符串。如果搜索中缺少主题,我还希望它打印出来。

if not testfolder.filter(
    datetime_received__gt=since, 
    sender='anon@anon.dk',
    subject__icontains=['Backup - no index - Friday','backup - with no index']
    ).exists():
    print('Log mangler.. Sender Ticket til Kayako....')
else:
    print('email found')

ValueError: Value ['Backup - no index - Friday', 'backup - with no index'] for filter on field path "subject" must be a single value

您可以为此使用 Q() 对象和布尔逻辑。参见 https://ecederstrand.github.io/exchangelib/#searching

例如:

.filter(Q(subject__icontains='Backup - no index - Friday') | Q(subject__icontains='backup - with no index'))