Skip to content

Commit

Permalink
fix: Ensure that all other distinguished folders than PublicFoldersRo…
Browse files Browse the repository at this point in the history
…ot specify their account mailbox
  • Loading branch information
ecederstrand committed Apr 23, 2024
1 parent 56270b9 commit d9035d0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions exchangelib/folders/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ def __init__(self, **kwargs):
self.item_sync_state = kwargs.pop("item_sync_state", None)
self.folder_sync_state = kwargs.pop("folder_sync_state", None)
super().__init__(**kwargs)
if self._distinguished_id and self.account:
self._distinguished_id.mailbox = Mailbox(email_address=self.account.primary_smtp_address)

@property
@abc.abstractmethod
Expand Down
5 changes: 5 additions & 0 deletions exchangelib/folders/roots.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,11 @@ class PublicFoldersRoot(RootOfHierarchy):
DEFAULT_FOLDER_TRAVERSAL_DEPTH = SHALLOW
supported_from = EXCHANGE_2007_SP1

def __init__(self, **kwargs):
super().__init__(**kwargs)
if self._distinguished_id:
self._distinguished_id.mailbox = None # See DistinguishedFolderId.clean()

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
2 changes: 2 additions & 0 deletions exchangelib/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,8 @@ def clean(self, version=None):
if self.id == PublicFoldersRoot.DISTINGUISHED_FOLDER_ID:
# Avoid "ErrorInvalidOperation: It is not valid to specify a mailbox with the public folder root" from EWS
self.mailbox = None
elif not self.mailbox:
raise ValueError(f"DistinguishedFolderId {self.id} must have a mailbox")


class TimeWindow(EWSElement):
Expand Down

0 comments on commit d9035d0

Please sign in to comment.