gpt4 book ai didi

python - 使用 Exchangelib 过滤帐户中所有文件夹中的邮件

转载 作者:太空宇宙 更新时间:2023-11-03 21:21:29 30 4
gpt4 key购买 nike

我正在尝试使用 Exchangelib 从与特定主题匹配\开头的帐户中检索消息。这必须包括来自所有文件夹而不仅仅是“收件箱”文件夹的邮件。我在这里遇到了几个类似的问题

How can I get the latest emails from all folders with exchangelib?

这让我使用了FolderCollection。但是,我不清楚如何创建所有文件夹的列表并将其传递给“folders”参数。

目前我尝试了以下方法:

conf = Configuration(server=ex_srv, credentials=cred)
acct = Account(primary_smtp_address=email,
config=conf,
autodiscover=False,
credentials=cred,
access_type=IMPERSONATION
)

from exchangelib.folders import Messages, FolderCollection
all_folder_list = acct.folders[Messages]
all_folder_collection = FolderCollection(account=acct, folders=all_folder_list)

all_folder_collection.filter(subject__startswith='test')

我似乎在这里犯了一个愚蠢的错误,但无法抽出时间来捕捉它。

有人可以告诉我实现这个用例的最佳方法吗?

编辑:

我看到的错误是

Traceback (most recent call last):

File "queryset.py", line 298, in __iter__
for val in self._format_items(items=self._query(), return_format=self.return_format):
File "queryset.py", line 375, in _item_yielder
for i in iterable:
File "account.py", line 580, in fetch
shape=ID_ONLY,
File "account.py", line 302, in _consume_item_service
is_empty, items = peek(items)
File "util.py", line 118, in peek
first = next(iterable)
File "folders.py", line 250, in find_items
for i in items:
File "services.py", line 432, in _paged_call
parsed_pages = [self._get_page(message) for message in response]
File "services.py", line 432, in <listcomp>
parsed_pages = [self._get_page(message) for message in response]
File "services.py", line 481, in _get_page
rootfolder = self._get_element_container(message=message, name='{%s}RootFolder' % MNS)
File "services.py", line 345, in _get_element_container
raise self._get_exception(code=response_code, text=msg_text, msg_xml=msg_xml)
exchangelib.errors.ErrorInvalidOperation: Shared folder search cannot be performed on multiple folders.

最佳答案

问题是您的FolderCollection 包含多个共享文件夹。 EWS 不允许一次查询多个共享文件夹。如果您不需要搜索共享文件夹,则必须从搜索中排除它们,或者一次搜索一个共享文件夹。

关于python - 使用 Exchangelib 过滤帐户中所有文件夹中的邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54203657/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com