Skip to content

Commit

Permalink
Don't override a custom mailbox. Fixes #1325
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Cederstrand committed Sep 2, 2024
1 parent 88d04bf commit 4317e4b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion exchangelib/folders/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,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:
if self._distinguished_id and not self._distinguished_id.mailbox and self.account:
# Ensure that distinguished IDs have a mailbox, but don't override a custom mailbox (e.g. shared folders)
self._distinguished_id.mailbox = Mailbox(email_address=self.account.primary_smtp_address)

@property
Expand Down
12 changes: 12 additions & 0 deletions tests/test_folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,18 @@ def test_get_folders(self):
).get_folders()
)

def test_shared_folders(self):
# Test that the custom 'email_address' is not overwritten. The test account does not have access to any shared
# accounts, so we can't expand the test to actual queries.
shared_folder = Folder(
root=self.account.root,
_distinguished_id=DistinguishedFolderId(
id=Inbox.DISTINGUISHED_FOLDER_ID,
mailbox=Mailbox(email_address="foo@example.com"),
),
)
self.assertEqual(shared_folder._distinguished_id.mailbox.email_address, "foo@example.com")

def test_folder_grouping(self):
# If you get errors here, you probably need to fill out [folder class].LOCALIZED_NAMES for your locale.
for f in self.account.root.walk():
Expand Down

0 comments on commit 4317e4b

Please sign in to comment.