Skip to content

Commit 3c13440

Browse files
ecederstrandErik Cederstrand
andauthored
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 <[email protected]>
1 parent c310c65 commit 3c13440

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

exchangelib/folders/roots.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,19 @@ def __init__(self, **kwargs):
332332
if self._distinguished_id:
333333
self._distinguished_id.mailbox = None # See DistinguishedFolderId.clean()
334334

335+
@property
336+
def _folders_map(self):
337+
# Top-level public folders may point to the root folder of the owning account and not the public folders root
338+
# of this account. This breaks the assumption of get_children(). Fix it by overwriting the parent folder.
339+
fix_parents = self._subfolders is None
340+
res = super()._folders_map
341+
if fix_parents:
342+
with self._subfolders_lock:
343+
for f in res.values():
344+
if f.id != self.id:
345+
f.parent = self
346+
return res
347+
335348
def get_children(self, folder):
336349
# EWS does not allow deep traversal of public folders, so self._folders_map will only populate the top-level
337350
# subfolders. To traverse public folders at arbitrary depth, we need to get child folders on demand.

0 commit comments

Comments
 (0)