Skip to content

Commit

Permalink
Only request DistinguishedFolderId on servers that support that field.
Browse files Browse the repository at this point in the history
…Fixes #1306
  • Loading branch information
Erik Cederstrand committed May 13, 2024
1 parent ae3bff0 commit 1de9757
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
6 changes: 4 additions & 2 deletions exchangelib/folders/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
)
from ..queryset import DoesNotExist, SearchableMixIn
from ..util import TNS, is_iterable, require_id
from ..version import EXCHANGE_2007_SP1, EXCHANGE_2010, SupportedVersionClassMixIn
from ..version import EXCHANGE_2007_SP1, EXCHANGE_2010, EXCHANGE_2016, SupportedVersionClassMixIn
from .collections import FolderCollection, PullSubscription, PushSubscription, StreamingSubscription, SyncCompleted
from .queryset import DEEP as DEEP_FOLDERS
from .queryset import MISSING_FOLDER_ERRORS
Expand Down Expand Up @@ -77,7 +77,9 @@ class BaseFolder(RegisterMixIn, SearchableMixIn, SupportedVersionClassMixIn, met
ID_ELEMENT_CLS = FolderId

_id = IdElementField(field_uri="folder:FolderId", value_cls=ID_ELEMENT_CLS)
_distinguished_id = IdElementField(field_uri="folder:DistinguishedFolderId", value_cls=DistinguishedFolderId)
_distinguished_id = IdElementField(
field_uri="folder:DistinguishedFolderId", value_cls=DistinguishedFolderId, supported_from=EXCHANGE_2016
)
parent_folder_id = EWSElementField(field_uri="folder:ParentFolderId", value_cls=ParentFolderId, is_read_only=True)
folder_class = CharField(field_uri="folder:FolderClass", is_required_after_save=True)
name = CharField(field_uri="folder:DisplayName")
Expand Down
13 changes: 9 additions & 4 deletions exchangelib/services/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,12 @@ def attachment_ids_element(items, version, tag="m:AttachmentIds"):

def parse_folder_elem(elem, folder):
if isinstance(folder, RootOfHierarchy):
return folder.from_xml(elem=elem, account=folder.account)
if isinstance(folder, Folder):
return folder.from_xml_with_root(elem=elem, root=folder.root)
raise ValueError(f"Unsupported folder class: {folder}")
res = folder.from_xml(elem=elem, account=folder.account)
elif isinstance(folder, Folder):
res = folder.from_xml_with_root(elem=elem, root=folder.root)
else:
raise ValueError(f"Unsupported folder class: {folder}")
# Not all servers support fetching the DistinguishedFolderId field. Add it back here.
if folder._distinguished_id and not res._distinguished_id:
res._distinguished_id = folder._distinguished_id
return res

0 comments on commit 1de9757

Please sign in to comment.