class MailFolderCollection
A collection class for managing Microsoft Outlook mail folders with delta query support, inheriting from DeltaCollection to provide change tracking capabilities.
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/outlook/mail/folders/collection.py
5 - 7
moderate
Purpose
MailFolderCollection serves as a specialized container for MailFolder objects in the Office 365 Outlook API. It extends DeltaCollection to provide delta query functionality, allowing efficient tracking of changes (additions, modifications, deletions) to mail folders. This class is typically used to retrieve, manage, and monitor collections of mail folders within a user's mailbox or a specific parent folder, with support for incremental synchronization through delta queries.
Source Code
class MailFolderCollection(DeltaCollection[MailFolder]):
def __init__(self, context, resource_path=None):
super(MailFolderCollection, self).__init__(context, MailFolder, resource_path)
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
bases |
DeltaCollection[MailFolder] | - |
Parameter Details
context: The client context object that provides authentication and connection information for making API requests to Office 365 services. This context manages the HTTP client, credentials, and base URL for API calls.
resource_path: Optional string representing the API endpoint path for this collection. If None, the path will be determined by the parent resource or context. This path is used to construct the full URL for API requests targeting this specific mail folder collection.
Return Value
Instantiation returns a MailFolderCollection object that can be used to query, iterate, and manage mail folders. The collection supports delta queries to track changes over time. Methods inherited from DeltaCollection return various types including lists of MailFolder objects, query objects for chaining operations, and delta tokens for incremental synchronization.
Class Interface
Methods
__init__(self, context, resource_path=None)
Purpose: Initializes a new MailFolderCollection instance with the provided context and optional resource path
Parameters:
context: The client context object for API communicationresource_path: Optional API endpoint path for this collection
Returns: None (constructor)
Attributes
| Name | Type | Description | Scope |
|---|---|---|---|
context |
ClientContext | The client context inherited from parent class, used for making API requests | instance |
resource_path |
str or None | The API endpoint path for this collection, inherited from parent class | instance |
delta_token |
str | Token used for delta queries to track changes, inherited from DeltaCollection | instance |
Dependencies
office365
Required Imports
from office365.outlook.mail.folders.folder import MailFolder
from office365.delta_collection import DeltaCollection
Usage Example
from office365.runtime.auth.client_credential import ClientCredential
from office365.graph_client import GraphClient
from office365.outlook.mail.folders.folder import MailFolder
from office365.delta_collection import DeltaCollection
# Setup authentication
client_id = 'your_client_id'
client_secret = 'your_client_secret'
tenant = 'your_tenant_id'
credentials = ClientCredential(client_id, client_secret)
# Create Graph client
client = GraphClient(credentials, tenant)
# Get mail folder collection for a user
user_email = 'user@example.com'
mail_folders = client.users[user_email].mail_folders
# Load the collection
mail_folders.get().execute_query()
# Iterate through folders
for folder in mail_folders:
print(f'Folder: {folder.display_name}, Unread: {folder.unread_item_count}')
# Use delta query to track changes
delta_result = mail_folders.delta().execute_query()
for folder in delta_result:
print(f'Changed folder: {folder.display_name}')
# Get delta token for next sync
delta_token = mail_folders.delta_token
Best Practices
- Always call execute_query() after building query chains to actually fetch data from the API
- Use delta queries for efficient synchronization when tracking changes over time rather than fetching the entire collection repeatedly
- Store and reuse delta tokens between synchronization cycles to only retrieve changes since the last sync
- Ensure proper authentication context is established before instantiating the collection
- Handle pagination for large folder collections using the inherited collection methods
- Be aware that the collection is lazy-loaded; data is not fetched until execute_query() is called
- Check API rate limits and implement appropriate throttling when performing frequent delta queries
- Use appropriate filter and select operations to minimize data transfer and improve performance
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class MessageCollection 77.9% similar
-
class ContactCollection 75.9% similar
-
class MailFolder 74.7% similar
-
class ApplicationCollection 68.1% similar
-
class EventCollection 64.8% similar