🔍 Code Extractor

class OutlookItem

Maturity: 38

OutlookItem is a base class representing a Microsoft Outlook item entity with common properties like change tracking, categories, and timestamps.

File:
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/outlook/item.py
Lines:
7 - 47
Complexity:
moderate

Purpose

This class serves as a base representation for Outlook items (emails, calendar events, contacts, etc.) in the Microsoft Graph API. It provides common properties and functionality for tracking item versions, categories, creation and modification timestamps. It inherits from Entity and is designed to be extended by specific Outlook item types. The class handles property access with appropriate default values and type conversions for datetime fields.

Source Code

class OutlookItem(Entity):
    @property
    def change_key(self):
        """
        Identifies the version of the item. Every time the item is changed, changeKey changes as well.
        This allows Exchange to apply changes to the correct version of the object.
        :rtype: str
        """
        return self.properties.get("ChangeKey", None)

    @property
    def categories(self):
        """
        The categories associated with the item
        """
        return self.properties.get("categories", StringCollection())

    @property
    def created_datetime(self):
        """
        The Timestamp type represents date and time information using ISO 8601 format and is always in UTC time.
        For example, midnight UTC on Jan 1, 2014 is 2014-01-01T00:00:00Z
        """
        return self.properties.get("createdDateTime", datetime.datetime.min)

    @property
    def last_modified_datetime(self):
        """
        The Timestamp type represents date and time information using ISO 8601 format and is always in UTC time.
        For example, midnight UTC on Jan 1, 2014 is 2014-01-01T00:00:00Z
        """
        return self.properties.get("lastModifiedDateTime", datetime.datetime.min)

    def get_property(self, name, default_value=None):
        if default_value is None:
            property_mapping = {
                "createdDateTime": self.created_datetime,
                "lastModifiedDateTime": self.last_modified_datetime,
            }
            default_value = property_mapping.get(name, None)
        return super(OutlookItem, self).get_property(name, default_value)

Parameters

Name Type Default Kind
bases Entity -

Parameter Details

__init__: Inherits constructor from Entity base class. The exact parameters depend on the Entity parent class implementation, but typically would accept property dictionaries or entity data from Microsoft Graph API responses.

Return Value

Instantiation returns an OutlookItem object. Properties return: change_key (str or None), categories (StringCollection), created_datetime (datetime.datetime), last_modified_datetime (datetime.datetime). The get_property method returns the requested property value with appropriate defaults.

Class Interface

Methods

@property change_key(self) -> str property

Purpose: Gets the version identifier for the item used for optimistic concurrency control

Returns: String representing the change key, or None if not set. Changes every time the item is modified.

@property categories(self) -> StringCollection property

Purpose: Gets the categories/tags associated with the Outlook item

Returns: StringCollection object containing category names, or empty StringCollection if none set

@property created_datetime(self) -> datetime.datetime property

Purpose: Gets the creation timestamp of the item in UTC

Returns: datetime.datetime object in ISO 8601 UTC format, or datetime.datetime.min if not set

@property last_modified_datetime(self) -> datetime.datetime property

Purpose: Gets the last modification timestamp of the item in UTC

Returns: datetime.datetime object in ISO 8601 UTC format, or datetime.datetime.min if not set

get_property(self, name: str, default_value=None) -> Any

Purpose: Retrieves a property value with intelligent defaults for known datetime properties

Parameters:

  • name: The name of the property to retrieve (e.g., 'createdDateTime', 'lastModifiedDateTime')
  • default_value: Optional default value to return if property not found. If None, uses predefined defaults for known properties.

Returns: The property value if found, otherwise the default_value or a predefined default for known properties

Attributes

Name Type Description Scope
properties dict Dictionary storing the raw property data from Microsoft Graph API responses. Inherited from Entity base class. instance

Dependencies

  • datetime
  • office365

Required Imports

import datetime
from office365.entity import Entity
from office365.runtime.types.collections import StringCollection

Usage Example

# Note: OutlookItem is typically not instantiated directly but through subclasses
# Example assumes proper Office365 SDK setup
from office365.outlook.item import OutlookItem
import datetime

# Typically created from API response data
item_data = {
    'ChangeKey': 'CQAAABYAAAD...', 
    'categories': ['Work', 'Important'],
    'createdDateTime': '2024-01-15T10:30:00Z',
    'lastModifiedDateTime': '2024-01-16T14:20:00Z'
}

# Instantiation (actual mechanism depends on Entity base class)
outlook_item = OutlookItem()
outlook_item.properties = item_data

# Access properties
change_key = outlook_item.change_key
categories = outlook_item.categories
created = outlook_item.created_datetime
modified = outlook_item.last_modified_datetime

# Use get_property for flexible access
created_alt = outlook_item.get_property('createdDateTime')
custom_prop = outlook_item.get_property('customField', 'default_value')

Best Practices

  • This class is designed to be inherited by specific Outlook item types (Message, Event, Contact, etc.) rather than instantiated directly
  • The change_key property is critical for optimistic concurrency control - always use the latest change_key when updating items
  • Datetime properties return datetime.datetime.min as default if not set, check for this value before using timestamps
  • Categories are returned as StringCollection objects, not plain lists
  • When extending this class, override get_property to add custom property mappings with appropriate defaults
  • The properties dictionary is the underlying data store - ensure it's properly initialized before accessing properties
  • All datetime values are in UTC (ISO 8601 format) as per Microsoft Graph API standards
  • Use get_property method for safe property access with fallback defaults

Similar Components

AI-powered semantic similarity - components with related functionality:

  • class OutlookCategory 71.3% similar

    Represents an Outlook category used to group and organize Outlook items such as messages and events in a user's mailbox.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/outlook/category.py
  • class OutlookUser 67.7% similar

    Represents the Outlook services available to a user, providing access to user-specific Outlook settings, categories, supported languages, and time zones.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/outlook/user.py
  • class ItemAttachment 67.5% similar

    A class representing an attachment that contains an Outlook item (contact, event, or message) attached to a user event, message, or post.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/outlook/mail/attachments/item.py
  • class AttachmentItem 67.1% similar

    A data class representing metadata attributes of an attachment item, including its type, name, and size.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/outlook/mail/attachments/attachment_item.py
  • class Message 65.8% similar

    Represents an email message in a Microsoft Outlook mailbox folder, providing methods for message operations like sending, replying, forwarding, and managing attachments.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/outlook/mail/messages/message.py
← Back to Browse