diff --git a/docs/exchangelib/fields.html b/docs/exchangelib/fields.html index 252253d4..0ef39cd5 100644 --- a/docs/exchangelib/fields.html +++ b/docs/exchangelib/fields.html @@ -1358,6 +1358,9 @@
exchangelib.fields
exchangelib.fields
exchangelib.fields
A base class for all indexed fields.
A base class for all single-field indexed fields.
class EmailAddressesField(IndexedField):
- is_list = True
- is_complex = True
-
+class EmailAddressesField(SingleFieldIndexedField):
PARENT_ELEMENT_NAME = "EmailAddresses"
def __init__(self, *args, **kwargs):
from .indexed_properties import EmailAddress
kwargs["value_cls"] = EmailAddress
- super().__init__(*args, **kwargs)
-
- def clean(self, value, version=None):
- if value is not None:
- default_labels = self.value_cls.LABEL_CHOICES
- if len(value) > len(default_labels):
- raise ValueError(f"This field can handle at most {len(default_labels)} values (value: {value})")
- tmp = []
- for s, default_label in zip(value, default_labels):
- if not isinstance(s, str):
- tmp.append(s)
- continue
- tmp.append(self.value_cls(email=s, label=default_label))
- value = tmp
- return super().clean(value, version=version)
+ super().__init__(*args, **kwargs)
var is_complex
var is_list
-def clean(self, value, version=None)
-
def clean(self, value, version=None):
- if value is not None:
- default_labels = self.value_cls.LABEL_CHOICES
- if len(value) > len(default_labels):
- raise ValueError(f"This field can handle at most {len(default_labels)} values (value: {value})")
- tmp = []
- for s, default_label in zip(value, default_labels):
- if not isinstance(s, str):
- tmp.append(s)
- continue
- tmp.append(self.value_cls(email=s, label=default_label))
- value = tmp
- return super().clean(value, version=version)
-
+class ImAddressField
+(*args, **kwargs)
+
A base class for all single-field indexed fields.
class ImAddressField(SingleFieldIndexedField):
+ PARENT_ELEMENT_NAME = "ImAddresses"
+
+ def __init__(self, *args, **kwargs):
+ from .indexed_properties import ImAddress
+
+ kwargs["value_cls"] = ImAddress
+ super().__init__(*args, **kwargs)
+var PARENT_ELEMENT_NAME
SingleFieldIndexedField
:
+
+
class ImportanceField
(*args, **kwargs)
@@ -5155,6 +5169,9 @@ Inherited members
class IndexedField(EWSElementField, metaclass=abc.ABCMeta):
"""A base class for all indexed fields."""
+ is_list = True
+ is_complex = True
+
PARENT_ELEMENT_NAME = None
def __init__(self, *args, **kwargs):
@@ -5183,9 +5200,8 @@ Ancestors
Subclasses
Class variables
@@ -5193,6 +5209,14 @@ Class variables
-
+var is_complex
+-
+
+
+var is_list
+-
+
+
Methods
@@ -6083,15 +6107,12 @@ Inherited members
(*args, **kwargs)
A base class for all indexed fields.
A base class for all single-field indexed fields.
class PhoneNumberField(IndexedField):
- is_list = True
- is_complex = True
-
+class PhoneNumberField(SingleFieldIndexedField):
PARENT_ELEMENT_NAME = "PhoneNumbers"
def __init__(self, *args, **kwargs):
@@ -6102,6 +6123,7 @@ Inherited members
var is_complex
var is_list
+class SingleFieldIndexedField
+(*args, **kwargs)
+
A base class for all single-field indexed fields.
class SingleFieldIndexedField(IndexedField):
+ """A base class for all single-field indexed fields."""
+
+ def __init__(self, *args, **kwargs):
+ from .indexed_properties import SingleFieldIndexedElement
+
+ value_cls = kwargs["value_cls"]
+ if not issubclass(value_cls, SingleFieldIndexedElement):
+ raise TypeError(f"'value_cls' {value_cls!r} must be a subclass of type {SingleFieldIndexedElement}")
+ super().__init__(*args, **kwargs)
+
+ def clean(self, value, version=None):
+ if value is not None:
+ default_labels = self.value_cls.LABEL_CHOICES
+ if len(value) > len(default_labels):
+ raise ValueError(f"This field can handle at most {len(default_labels)} values (value: {value})")
+ tmp = []
+ value_field_name = self.value_cls.value_field(version=version).name
+ for s, default_label in zip(value, default_labels):
+ if not isinstance(s, str):
+ tmp.append(s)
+ continue
+ tmp.append(self.value_cls(**{"label": default_label, value_field_name: s}))
+ value = tmp
+ return super().clean(value, version=version)
+
+def clean(self, value, version=None)
+
def clean(self, value, version=None):
+ if value is not None:
+ default_labels = self.value_cls.LABEL_CHOICES
+ if len(value) > len(default_labels):
+ raise ValueError(f"This field can handle at most {len(default_labels)} values (value: {value})")
+ tmp = []
+ value_field_name = self.value_cls.value_field(version=version).name
+ for s, default_label in zip(value, default_labels):
+ if not isinstance(s, str):
+ tmp.append(s)
+ continue
+ tmp.append(self.value_cls(**{"label": default_label, value_field_name: s}))
+ value = tmp
+ return super().clean(value, version=version)
+IndexedField
:
+
+
class StringAttributedValueField
(*args, **kwargs)
@@ -7528,9 +7630,6 @@ EmailAddressesField
@@ -7631,12 +7730,20 @@ IdField
+ImAddressField
+
+
+
ImportanceField
IndexedField
@@ -7731,8 +7838,6 @@ PhoneNumberField
@@ -7768,6 +7873,12 @@ SensitivityField
+SingleFieldIndexedField
+
+clean
+
+
+
StringAttributedValueField
diff --git a/docs/exchangelib/folders/base.html b/docs/exchangelib/folders/base.html
index 9ba89d1b..8c39d417 100644
--- a/docs/exchangelib/folders/base.html
+++ b/docs/exchangelib/folders/base.html
@@ -122,6 +122,8 @@ Module exchangelib.folders.base
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
@@ -241,6 +243,15 @@ Module exchangelib.folders.base
tree += f" {node}\n"
return tree.strip()
+ @classmethod
+ def _get_distinguished(cls, folder):
+ if not cls.DISTINGUISHED_FOLDER_ID:
+ raise ValueError(f"Class {cls} must have a DISTINGUISHED_FOLDER_ID value")
+ try:
+ return cls.resolve(account=folder.account, folder=folder)
+ except MISSING_FOLDER_ERRORS as e:
+ raise ErrorFolderNotFound(f"Could not find distinguished folder {cls.DISTINGUISHED_FOLDER_ID!r} ({e})")
+
@property
def has_distinguished_name(self):
return self.name and self.DISTINGUISHED_FOLDER_ID and self.name.lower() == self.DISTINGUISHED_FOLDER_ID.lower()
@@ -852,7 +863,7 @@ Module exchangelib.folders.base
if parent.root != self.root:
raise ValueError("'parent.root' must match 'root'")
else:
- self.root = parent.root
+ self._root = parent.root
if "parent_folder_id" in kwargs and parent.id != kwargs["parent_folder_id"]:
raise ValueError("'parent_folder_id' must match 'parent' ID")
kwargs["parent_folder_id"] = ParentFolderId(id=parent.id, changekey=parent.changekey)
@@ -868,10 +879,6 @@ Module exchangelib.folders.base
def root(self):
return self._root
- @root.setter
- def root(self, value):
- self._root = value
-
@classmethod
def register(cls, *args, **kwargs):
if cls is not Folder:
@@ -884,24 +891,6 @@ Module exchangelib.folders.base
raise TypeError("For folders, custom fields must be registered on the Folder class")
return super().deregister(*args, **kwargs)
- @classmethod
- def get_distinguished(cls, account):
- """Get the distinguished folder for this folder class.
-
- :param account:
- :return:
- """
- try:
- return cls.resolve(
- account=account,
- folder=DistinguishedFolderId(
- id=cls.DISTINGUISHED_FOLDER_ID,
- mailbox=Mailbox(email_address=account.primary_smtp_address),
- ),
- )
- except MISSING_FOLDER_ERRORS:
- raise ErrorFolderNotFound(f"Could not find distinguished folder {cls.DISTINGUISHED_FOLDER_ID!r}")
-
@property
def parent(self):
if not self.parent_folder_id:
@@ -918,7 +907,7 @@ Module exchangelib.folders.base
else:
if not isinstance(value, BaseFolder):
raise InvalidTypeError("value", value, BaseFolder)
- self.root = value.root
+ self._root = value.root
self.parent_folder_id = ParentFolderId(id=value.id, changekey=value.changekey)
def clean(self, version=None):
@@ -928,6 +917,23 @@ Module exchangelib.folders.base
if self.root and not isinstance(self.root, RootOfHierarchy):
raise InvalidTypeError("root", self.root, RootOfHierarchy)
+ @classmethod
+ def get_distinguished(cls, root):
+ """Get the distinguished folder for this folder class.
+
+ :param root:
+ :return:
+ """
+ return cls._get_distinguished(
+ folder=cls(
+ _distinguished_id=DistinguishedFolderId(
+ id=cls.DISTINGUISHED_FOLDER_ID,
+ mailbox=Mailbox(email_address=root.account.primary_smtp_address),
+ ),
+ root=root,
+ )
+ )
+
@classmethod
def from_xml_with_root(cls, elem, root):
folder = cls.from_xml(elem=elem, account=root.account)
@@ -1025,6 +1031,8 @@ Classes
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
@@ -1144,6 +1152,15 @@ Classes
tree += f" {node}\n"
return tree.strip()
+ @classmethod
+ def _get_distinguished(cls, folder):
+ if not cls.DISTINGUISHED_FOLDER_ID:
+ raise ValueError(f"Class {cls} must have a DISTINGUISHED_FOLDER_ID value")
+ try:
+ return cls.resolve(account=folder.account, folder=folder)
+ except MISSING_FOLDER_ERRORS as e:
+ raise ErrorFolderNotFound(f"Could not find distinguished folder {cls.DISTINGUISHED_FOLDER_ID!r} ({e})")
+
@property
def has_distinguished_name(self):
return self.name and self.DISTINGUISHED_FOLDER_ID and self.name.lower() == self.DISTINGUISHED_FOLDER_ID.lower()
@@ -2975,7 +2992,7 @@ Inherited members
if parent.root != self.root:
raise ValueError("'parent.root' must match 'root'")
else:
- self.root = parent.root
+ self._root = parent.root
if "parent_folder_id" in kwargs and parent.id != kwargs["parent_folder_id"]:
raise ValueError("'parent_folder_id' must match 'parent' ID")
kwargs["parent_folder_id"] = ParentFolderId(id=parent.id, changekey=parent.changekey)
@@ -2991,10 +3008,6 @@ Inherited members
def root(self):
return self._root
- @root.setter
- def root(self, value):
- self._root = value
-
@classmethod
def register(cls, *args, **kwargs):
if cls is not Folder:
@@ -3007,24 +3020,6 @@ Inherited members
raise TypeError("For folders, custom fields must be registered on the Folder class")
return super().deregister(*args, **kwargs)
- @classmethod
- def get_distinguished(cls, account):
- """Get the distinguished folder for this folder class.
-
- :param account:
- :return:
- """
- try:
- return cls.resolve(
- account=account,
- folder=DistinguishedFolderId(
- id=cls.DISTINGUISHED_FOLDER_ID,
- mailbox=Mailbox(email_address=account.primary_smtp_address),
- ),
- )
- except MISSING_FOLDER_ERRORS:
- raise ErrorFolderNotFound(f"Could not find distinguished folder {cls.DISTINGUISHED_FOLDER_ID!r}")
-
@property
def parent(self):
if not self.parent_folder_id:
@@ -3041,7 +3036,7 @@ Inherited members
else:
if not isinstance(value, BaseFolder):
raise InvalidTypeError("value", value, BaseFolder)
- self.root = value.root
+ self._root = value.root
self.parent_folder_id = ParentFolderId(id=value.id, changekey=value.changekey)
def clean(self, version=None):
@@ -3051,6 +3046,23 @@ Inherited members
if self.root and not isinstance(self.root, RootOfHierarchy):
raise InvalidTypeError("root", self.root, RootOfHierarchy)
+ @classmethod
+ def get_distinguished(cls, root):
+ """Get the distinguished folder for this folder class.
+
+ :param root:
+ :return:
+ """
+ return cls._get_distinguished(
+ folder=cls(
+ _distinguished_id=DistinguishedFolderId(
+ id=cls.DISTINGUISHED_FOLDER_ID,
+ mailbox=Mailbox(email_address=root.account.primary_smtp_address),
+ ),
+ root=root,
+ )
+ )
+
@classmethod
def from_xml_with_root(cls, elem, root):
folder = cls.from_xml(elem=elem, account=root.account)
@@ -3173,33 +3185,32 @@ Static methods
-def get_distinguished(account)
+def get_distinguished(root)
Get the distinguished folder for this folder class.
-:param account:
+
:param root:
:return:
Expand source code
@classmethod
-def get_distinguished(cls, account):
+def get_distinguished(cls, root):
"""Get the distinguished folder for this folder class.
- :param account:
+ :param root:
:return:
"""
- try:
- return cls.resolve(
- account=account,
- folder=DistinguishedFolderId(
+ return cls._get_distinguished(
+ folder=cls(
+ _distinguished_id=DistinguishedFolderId(
id=cls.DISTINGUISHED_FOLDER_ID,
- mailbox=Mailbox(email_address=account.primary_smtp_address),
+ mailbox=Mailbox(email_address=root.account.primary_smtp_address),
),
+ root=root,
)
- except MISSING_FOLDER_ERRORS:
- raise ErrorFolderNotFound(f"Could not find distinguished folder {cls.DISTINGUISHED_FOLDER_ID!r}")
+ )
diff --git a/docs/exchangelib/folders/index.html b/docs/exchangelib/folders/index.html
index 44e7b377..556e1f7c 100644
--- a/docs/exchangelib/folders/index.html
+++ b/docs/exchangelib/folders/index.html
@@ -1545,6 +1545,8 @@
-def get_distinguished(account)
+def get_distinguished(root)
Get the distinguished folder for this folder class.
-:param account: +
:param root: :return:
@classmethod
-def get_distinguished(cls, account):
+def get_distinguished(cls, root):
"""Get the distinguished folder for this folder class.
- :param account:
+ :param root:
:return:
"""
- try:
- return cls.resolve(
- account=account,
- folder=DistinguishedFolderId(
+ return cls._get_distinguished(
+ folder=cls(
+ _distinguished_id=DistinguishedFolderId(
id=cls.DISTINGUISHED_FOLDER_ID,
- mailbox=Mailbox(email_address=account.primary_smtp_address),
+ mailbox=Mailbox(email_address=root.account.primary_smtp_address),
),
+ root=root,
)
- except MISSING_FOLDER_ERRORS:
- raise ErrorFolderNotFound(f"Could not find distinguished folder {cls.DISTINGUISHED_FOLDER_ID!r}")
+ )
Get the distinguished folder for this folder class.
-:param account:
:param account: +:return:
exchangelib.folders.queryset
exchangelib.folders.roots
exchangelib.folders.roots
exchangelib.folders.roots
exchangelib.folders.roots
exchangelib.folders.roots
Get the distinguished folder for this folder class.
-:param account:
:param account: +:return:
exchangelib
-def get_distinguished(account)
+def get_distinguished(root)
Get the distinguished folder for this folder class.
-:param account: +
:param root: :return:
@classmethod
-def get_distinguished(cls, account):
+def get_distinguished(cls, root):
"""Get the distinguished folder for this folder class.
- :param account:
+ :param root:
:return:
"""
- try:
- return cls.resolve(
- account=account,
- folder=DistinguishedFolderId(
+ return cls._get_distinguished(
+ folder=cls(
+ _distinguished_id=DistinguishedFolderId(
id=cls.DISTINGUISHED_FOLDER_ID,
- mailbox=Mailbox(email_address=account.primary_smtp_address),
+ mailbox=Mailbox(email_address=root.account.primary_smtp_address),
),
+ root=root,
)
- except MISSING_FOLDER_ERRORS:
- raise ErrorFolderNotFound(f"Could not find distinguished folder {cls.DISTINGUISHED_FOLDER_ID!r}")
+ )
Get the distinguished folder for this folder class.
-:param account:
:param account: +:return:
exchangelib.indexed_properties
+class ImAddress
+(**kwargs)
+
MSDN: https://docs.microsoft.com/en-us/exchange/client-developer/web-service-reference/entry-imaddress
class ImAddress(SingleFieldIndexedElement):
+ """MSDN: https://docs.microsoft.com/en-us/exchange/client-developer/web-service-reference/entry-imaddress"""
+
+ ELEMENT_NAME = "Entry"
+ LABEL_CHOICES = ("ImAddress1", "ImAddress2", "ImAddress3")
+
+ label = LabelField(field_uri="Key", choices={Choice(c) for c in LABEL_CHOICES}, default=LABEL_CHOICES[0])
+ im_address = SubField(is_required=True)
+var ELEMENT_NAME
var FIELDS
var LABEL_CHOICES
var im_address
var label
class IndexedElement
(**kwargs)
@@ -480,6 +553,7 @@ Ancestors
Subclasses
Static methods
@@ -541,6 +615,16 @@ ImAddress
+
+
+
IndexedElement
LABEL_CHOICES
@@ -589,4 +673,4 @@ Generated by pdoc 0.10.0.