Skip to content

Commit

Permalink
Don't exit early on ErrorAccessDenied. We want to raise other excepti…
Browse files Browse the repository at this point in the history
…ons that may follow. Fixes #586
  • Loading branch information
ecederstrand committed May 9, 2019
1 parent cf8c351 commit 0a27d64
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 29 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Change Log

HEAD
----
- Fix bug that left out parts of the folder hierarchy when traversing `account.root`.


1.12.3
Expand Down
59 changes: 30 additions & 29 deletions exchangelib/folders.py
Original file line number Diff line number Diff line change
Expand Up @@ -1724,40 +1724,41 @@ def _folders_map(self):
return self._subfolders

# Map root, and all subfolders of root, at arbitrary depth by folder ID. First get distinguished folders, so we
# are sure to apply the correct Folder class, then fetch all subfolders of this root. AdminAuditLogs folder is
# not retrievable and makes the entire request fail.
# are sure to apply the correct Folder class, then fetch all subfolders of this root.
folders_map = {self.id: self}
distinguished_folders = [
cls(root=self, name=cls.DISTINGUISHED_FOLDER_ID, is_distinguished=True)
for cls in self.WELLKNOWN_FOLDERS
if cls != AdminAuditLogs and cls.supports_version(self.account.version)
if cls.get_folder_allowed and cls.supports_version(self.account.version)
]
try:
for f in FolderCollection(account=self.account, folders=distinguished_folders).resolve():
if isinstance(f, (ErrorFolderNotFound, ErrorNoPublicFolderReplicaAvailable)):
# This is just a distinguished folder the server does not have
continue
if isinstance(f, ErrorInvalidOperation):
# This is probably a distinguished folder the server does not have. We previously tested the exact
# error message (f.value), but some Exchange servers return localized error messages, so that's not
# possible to do reliably.
continue
if isinstance(f, ErrorItemNotFound):
# Another way of telling us that this is a distinguished folder the server does not have
continue
if isinstance(f, Exception):
raise f
folders_map[f.id] = f
for f in SingleFolderQuerySet(account=self.account, folder=self).depth(self.TRAVERSAL_DEPTH).all():
if isinstance(f, Exception):
raise f
if f.id in folders_map:
# Already exists. Probably a distinguished folder
continue
folders_map[f.id] = f
except ErrorAccessDenied:
# We may not have GetFolder or FindFolder access
pass
for f in FolderCollection(account=self.account, folders=distinguished_folders).resolve():
if isinstance(f, (ErrorFolderNotFound, ErrorNoPublicFolderReplicaAvailable)):
# This is just a distinguished folder the server does not have
continue
if isinstance(f, ErrorInvalidOperation):
# This is probably a distinguished folder the server does not have. We previously tested the exact
# error message (f.value), but some Exchange servers return localized error messages, so that's not
# possible to do reliably.
continue
if isinstance(f, ErrorItemNotFound):
# Another way of telling us that this is a distinguished folder the server does not have
continue
if isinstance(f, ErrorAccessDenied):
# We may not have GetFolder access, either to this folder or at all
continue
if isinstance(f, Exception):
raise f
folders_map[f.id] = f
for f in SingleFolderQuerySet(account=self.account, folder=self).depth(self.TRAVERSAL_DEPTH).all():
if isinstance(f, ErrorAccessDenied):
# We may not have FindFolder access, or GetFolder access, either to this folder or at all
continue
if isinstance(f, Exception):
raise f
if f.id in folders_map:
# Already exists. Probably a distinguished folder
continue
folders_map[f.id] = f
self._subfolders = folders_map
return folders_map

Expand Down

0 comments on commit 0a27d64

Please sign in to comment.