1

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

如何使用 exchangelib 从所有文件夹中获取最新的电子邮件?

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

目前我尝试了以下方法:

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.
4

1 回答 1

2

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

于 2019-01-22T10:03:20.737 回答