From 3c13440a7e619f169fdca9b8c6a357755ba733ab Mon Sep 17 00:00:00 2001 From: Erik Cederstrand Date: Sun, 9 Jun 2024 17:06:01 +0200 Subject: [PATCH] Change the 'parent' attribute of direct public subfolders (#1316) * fix: change the 'parent' attribute of direct public subfolders so folder traversal finds these folders * fix: parent method is a property * fix: roots do not have a setter --------- Co-authored-by: Erik Cederstrand --- exchangelib/folders/roots.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/exchangelib/folders/roots.py b/exchangelib/folders/roots.py index 2de25b74..ee4eb15e 100644 --- a/exchangelib/folders/roots.py +++ b/exchangelib/folders/roots.py @@ -332,6 +332,19 @@ def __init__(self, **kwargs): if self._distinguished_id: self._distinguished_id.mailbox = None # See DistinguishedFolderId.clean() + @property + 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(): + if f.id != self.id: + f.parent = 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.