From 6fcaf3a9057be3c95c2f07921d2c437049ae78f5 Mon Sep 17 00:00:00 2001 From: Erik Cederstrand Date: Thu, 6 Jun 2024 10:36:58 +0200 Subject: [PATCH] fix: change the 'parent' attribute of direct public subfolders so folder traversal finds these folders --- exchangelib/folders/roots.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/exchangelib/folders/roots.py b/exchangelib/folders/roots.py index 2de25b74..7c3a771f 100644 --- a/exchangelib/folders/roots.py +++ b/exchangelib/folders/roots.py @@ -332,6 +332,17 @@ def __init__(self, **kwargs): if self._distinguished_id: self._distinguished_id.mailbox = None # See DistinguishedFolderId.clean() + def _folders_map(self): + # Top-level public folders may point to the root folder of the owning account and not the public folders root + # of this account. This breaks the assumption of get_children(). Fix it by overwriting the parent folder. + fix_parents = self._subfolders is None + res = super()._folders_map() + if fix_parents: + with self._subfolders_lock: + for f in res.values(): + f.parent = None if f.id == self.id else self + return res + def get_children(self, folder): # EWS does not allow deep traversal of public folders, so self._folders_map will only populate the top-level # subfolders. To traverse public folders at arbitrary depth, we need to get child folders on demand.