exchangelib.indexed_properties API documentation

# Module `exchangelib.indexed_properties`

Expand source code

    import logging

    from .fields import EmailSubField, LabelField, SubField, NamedSubField, Choice
    from .properties import EWSElement, EWSMeta

    log = logging.getLogger(__name__)

    class IndexedElement(EWSElement, metaclass=EWSMeta):
        """Base class for all classes that implement an indexed element."""

        LABEL_CHOICES = ()

    class SingleFieldIndexedElement(IndexedElement, metaclass=EWSMeta):
        """Base class for all classes that implement an indexed element with a single field."""

        @classmethod
        def value_field(cls, version=None):
            fields = cls.supported_fields(version=version)
            if len(fields) != 1:
                raise ValueError('This class must have only one field (found %s)' % (fields,))
            return fields[0]

    class EmailAddress(SingleFieldIndexedElement):
        """MSDN: https://docs.microsoft.com/en-us/exchange/client-developer/web-service-reference/entry-emailaddress"""

        ELEMENT_NAME = 'Entry'
        LABEL_CHOICES = ('EmailAddress1', 'EmailAddress2', 'EmailAddress3')

        label = LabelField(field_uri='Key', choices={Choice(c) for c in LABEL_CHOICES}, default=LABEL_CHOICES[0])
        email = EmailSubField(is_required=True)

    class PhoneNumber(SingleFieldIndexedElement):
        """MSDN: https://docs.microsoft.com/en-us/exchange/client-developer/web-service-reference/entry-phonenumber"""

        ELEMENT_NAME = 'Entry'
        LABEL_CHOICES = (
            'AssistantPhone', 'BusinessFax', 'BusinessPhone', 'BusinessPhone2', 'Callback', 'CarPhone', 'CompanyMainPhone',
            'HomeFax', 'HomePhone', 'HomePhone2', 'Isdn', 'MobilePhone', 'OtherFax', 'OtherTelephone', 'Pager',
            'PrimaryPhone', 'RadioPhone', 'Telex', 'TtyTddPhone'
        )

        label = LabelField(field_uri='Key', choices={Choice(c) for c in LABEL_CHOICES}, default='PrimaryPhone')
        phone_number = SubField(is_required=True)

    class MultiFieldIndexedElement(IndexedElement, metaclass=EWSMeta):
        """Base class for all classes that implement an indexed element with multiple fields."""

    class PhysicalAddress(MultiFieldIndexedElement):
        """MSDN: https://docs.microsoft.com/en-us/exchange/client-developer/web-service-reference/entry-physicaladdress"""

        ELEMENT_NAME = 'Entry'
        LABEL_CHOICES = ('Business', 'Home', 'Other')

        label = LabelField(field_uri='Key', choices={Choice(c) for c in LABEL_CHOICES}, default=LABEL_CHOICES[0])
        street = NamedSubField(field_uri='Street')  # Street, house number, etc.
        city = NamedSubField(field_uri='City')
        state = NamedSubField(field_uri='State')
        country = NamedSubField(field_uri='CountryOrRegion')
        zipcode = NamedSubField(field_uri='PostalCode')

        def clean(self, version=None):
            if isinstance(self.zipcode, int):
                self.zipcode = str(self.zipcode)
            super().clean(version=version)

## Classes

`class EmailAddress (**kwargs)`

  MSDN: https://docs.microsoft.com/en-us/exchange/client-developer/web-service-reference/entry-emailaddress

  Expand source code

      class EmailAddress(SingleFieldIndexedElement):
          """MSDN: https://docs.microsoft.com/en-us/exchange/client-developer/web-service-reference/entry-emailaddress"""

          ELEMENT_NAME = 'Entry'
          LABEL_CHOICES = ('EmailAddress1', 'EmailAddress2', 'EmailAddress3')

          label = LabelField(field_uri='Key', choices={Choice(c) for c in LABEL_CHOICES}, default=LABEL_CHOICES[0])
          email = EmailSubField(is_required=True)

  ### Ancestors

  - SingleFieldIndexedElement
  - IndexedElement
  - EWSElement

  ### Class variables

  `var ELEMENT_NAME`
  `var FIELDS`
  `var LABEL_CHOICES`

  ### Instance variables

  `var email`
  `var label`

  ### Inherited members

  - `SingleFieldIndexedElement`:
    - `add_field`
    - `remove_field`
    - `supported_fields`
    - `validate_field`
`class IndexedElement (**kwargs)`

  Base class for all classes that implement an indexed element.

  Expand source code

      class IndexedElement(EWSElement, metaclass=EWSMeta):
          """Base class for all classes that implement an indexed element."""

          LABEL_CHOICES = ()

  ### Ancestors

  - EWSElement

  ### Subclasses

  - MultiFieldIndexedElement
  - SingleFieldIndexedElement

  ### Class variables

  `var LABEL_CHOICES`

  ### Inherited members

  - `EWSElement`:
    - `add_field`
    - `remove_field`
    - `supported_fields`
    - `validate_field`
`class MultiFieldIndexedElement (**kwargs)`

  Base class for all classes that implement an indexed element with multiple fields.

  Expand source code

      class MultiFieldIndexedElement(IndexedElement, metaclass=EWSMeta):
          """Base class for all classes that implement an indexed element with multiple fields."""

  ### Ancestors

  - IndexedElement
  - EWSElement

  ### Subclasses

  - PhysicalAddress

  ### Inherited members

  - `IndexedElement`:
    - `add_field`
    - `remove_field`
    - `supported_fields`
    - `validate_field`
`class PhoneNumber (**kwargs)`

  MSDN: https://docs.microsoft.com/en-us/exchange/client-developer/web-service-reference/entry-phonenumber

  Expand source code

      class PhoneNumber(SingleFieldIndexedElement):
          """MSDN: https://docs.microsoft.com/en-us/exchange/client-developer/web-service-reference/entry-phonenumber"""

          ELEMENT_NAME = 'Entry'
          LABEL_CHOICES = (
              'AssistantPhone', 'BusinessFax', 'BusinessPhone', 'BusinessPhone2', 'Callback', 'CarPhone', 'CompanyMainPhone',
              'HomeFax', 'HomePhone', 'HomePhone2', 'Isdn', 'MobilePhone', 'OtherFax', 'OtherTelephone', 'Pager',
              'PrimaryPhone', 'RadioPhone', 'Telex', 'TtyTddPhone'
          )

          label = LabelField(field_uri='Key', choices={Choice(c) for c in LABEL_CHOICES}, default='PrimaryPhone')
          phone_number = SubField(is_required=True)

  ### Ancestors

  - SingleFieldIndexedElement
  - IndexedElement
  - EWSElement

  ### Class variables

  `var ELEMENT_NAME`
  `var FIELDS`
  `var LABEL_CHOICES`

  ### Instance variables

  `var label`
  `var phone_number`

  ### Inherited members

  - `SingleFieldIndexedElement`:
    - `add_field`
    - `remove_field`
    - `supported_fields`
    - `validate_field`
`class PhysicalAddress (**kwargs)`

  MSDN: https://docs.microsoft.com/en-us/exchange/client-developer/web-service-reference/entry-physicaladdress

  Expand source code

      class PhysicalAddress(MultiFieldIndexedElement):
          """MSDN: https://docs.microsoft.com/en-us/exchange/client-developer/web-service-reference/entry-physicaladdress"""

          ELEMENT_NAME = 'Entry'
          LABEL_CHOICES = ('Business', 'Home', 'Other')

          label = LabelField(field_uri='Key', choices={Choice(c) for c in LABEL_CHOICES}, default=LABEL_CHOICES[0])
          street = NamedSubField(field_uri='Street')  # Street, house number, etc.
          city = NamedSubField(field_uri='City')
          state = NamedSubField(field_uri='State')
          country = NamedSubField(field_uri='CountryOrRegion')
          zipcode = NamedSubField(field_uri='PostalCode')

          def clean(self, version=None):
              if isinstance(self.zipcode, int):
                  self.zipcode = str(self.zipcode)
              super().clean(version=version)

  ### Ancestors

  - MultiFieldIndexedElement
  - IndexedElement
  - EWSElement

  ### Class variables

  `var ELEMENT_NAME`
  `var FIELDS`
  `var LABEL_CHOICES`

  ### Instance variables

  `var city`
  `var country`
  `var label`
  `var state`
  `var street`
  `var zipcode`

  ### Methods

  `def clean(self, version=None)`
    Expand source code

        def clean(self, version=None):
            if isinstance(self.zipcode, int):
                self.zipcode = str(self.zipcode)
            super().clean(version=version)

  ### Inherited members

  - `MultiFieldIndexedElement`:
    - `add_field`
    - `remove_field`
    - `supported_fields`
    - `validate_field`
`class SingleFieldIndexedElement (**kwargs)`

  Base class for all classes that implement an indexed element with a single field.

  Expand source code

      class SingleFieldIndexedElement(IndexedElement, metaclass=EWSMeta):
          """Base class for all classes that implement an indexed element with a single field."""

          @classmethod
          def value_field(cls, version=None):
              fields = cls.supported_fields(version=version)
              if len(fields) != 1:
                  raise ValueError('This class must have only one field (found %s)' % (fields,))
              return fields[0]

  ### Ancestors

  - IndexedElement
  - EWSElement

  ### Subclasses

  - EmailAddress
  - PhoneNumber

  ### Static methods

  `def value_field(version=None)`
    Expand source code

        @classmethod
        def value_field(cls, version=None):
            fields = cls.supported_fields(version=version)
            if len(fields) != 1:
                raise ValueError('This class must have only one field (found %s)' % (fields,))
            return fields[0]

  ### Inherited members

  - `IndexedElement`:
    - `add_field`
    - `remove_field`
    - `supported_fields`
    - `validate_field`