Skip to content

Change the 'parent' attribute of direct public subfolders #1316

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions exchangelib/folders/roots.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down