Skip to content

Commit

Permalink
fix: change the 'parent' attribute of direct public subfolders so fol…
Browse files Browse the repository at this point in the history
…der traversal finds these folders
  • Loading branch information
Erik Cederstrand committed Jun 6, 2024
1 parent c310c65 commit 6fcaf3a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions exchangelib/folders/roots.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 6fcaf3a

Please sign in to comment.