class MessageRule
A class representing an Outlook message rule that defines conditions, actions, and exceptions for automatically processing incoming messages in a user's Inbox.
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/outlook/mail/messages/rules/rule.py
6 - 32
moderate
Purpose
This class models Outlook email rules that automatically perform actions on incoming messages when specific conditions are met. It inherits from Entity and provides access to rule configuration including actions to take, conditions that trigger the rule, exception conditions, and read-only status. The class is part of the Office 365 API integration for managing email automation rules programmatically.
Source Code
class MessageRule(Entity):
"""A rule that applies to messages in the Inbox of a user.
In Outlook, you can set up rules for incoming messages in the Inbox to carry out specific internal
upon certain conditions."""
@property
def actions(self):
"""Actions to be taken on a message when the corresponding conditions are fulfilled."""
return self.properties.get("actions", MessageRuleActions())
@property
def conditions(self):
"""Conditions that when fulfilled, will trigger the corresponding actions for that rule."""
return self.properties.get("conditions", MessageRulePredicates())
@property
def exceptions(self):
"""Exception conditions for the rule."""
return self.properties.get("exceptions", MessageRulePredicates())
@property
def is_read_only(self):
"""
Indicates if the rule is read-only and cannot be modified or deleted by the rules REST API.
"""
return self.properties.get("isReadOnly", None)
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
bases |
Entity | - |
Parameter Details
No explicit __init__ parameters: This class inherits from Entity and does not define its own __init__ method. Initialization is handled by the parent Entity class, which likely accepts properties or configuration data to populate the rule's attributes.
Return Value
Instantiation returns a MessageRule object that provides property-based access to rule configuration. The properties (actions, conditions, exceptions, is_read_only) return their respective types: MessageRuleActions, MessageRulePredicates (for conditions and exceptions), and boolean/None (for is_read_only).
Class Interface
Methods
@property actions(self) -> MessageRuleActions
property
Purpose: Returns the actions to be taken on a message when the corresponding conditions are fulfilled
Returns: MessageRuleActions object containing the configured actions for this rule, or an empty MessageRuleActions() if not set
@property conditions(self) -> MessageRulePredicates
property
Purpose: Returns the conditions that when fulfilled will trigger the corresponding actions for this rule
Returns: MessageRulePredicates object containing the conditions that trigger this rule, or an empty MessageRulePredicates() if not set
@property exceptions(self) -> MessageRulePredicates
property
Purpose: Returns the exception conditions for the rule that prevent actions from being taken even when conditions are met
Returns: MessageRulePredicates object containing the exception conditions, or an empty MessageRulePredicates() if not set
@property is_read_only(self) -> bool | None
property
Purpose: Indicates if the rule is read-only and cannot be modified or deleted by the rules REST API
Returns: Boolean value indicating read-only status, or None if the property is not set
Attributes
| Name | Type | Description | Scope |
|---|---|---|---|
properties |
dict | Inherited from Entity class; stores the underlying data for all rule properties including actions, conditions, exceptions, and isReadOnly flag | instance |
Dependencies
office365
Required Imports
from office365.entity import Entity
from office365.outlook.mail.messages.rules.actions import MessageRuleActions
from office365.outlook.mail.messages.rules.predicates import MessageRulePredicates
Usage Example
# Assuming you have an authenticated Office 365 client
from office365.outlook.mail.messages.rules.rule import MessageRule
# Typically retrieved from Office 365 API, not instantiated directly
# Example: rule = client.me.mail_folders.inbox.message_rules.get().execute_query()[0]
# Access rule properties
if rule.is_read_only:
print("This rule cannot be modified")
# Get rule actions
actions = rule.actions
print(f"Actions configured: {actions}")
# Get rule conditions
conditions = rule.conditions
print(f"Conditions: {conditions}")
# Get rule exceptions
exceptions = rule.exceptions
print(f"Exceptions: {exceptions}")
Best Practices
- This class is typically not instantiated directly but retrieved from the Office 365 API when querying mail rules
- Check the is_read_only property before attempting to modify or delete a rule via the REST API
- The properties use lazy loading with default values (empty MessageRuleActions/MessageRulePredicates objects) if data is not present
- This class represents a read model from the API; modifications should be done through the appropriate Office 365 API methods
- Always verify that actions, conditions, and exceptions are properly configured before relying on rule behavior
- The class inherits from Entity, so it likely has additional methods and properties from the parent class for API operations
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class MessageRulePredicates 72.5% similar
-
class Message 67.9% similar
-
class EventMessage 61.3% similar
-
class MailFolder 59.4% similar
-
class MessageRuleActions 58.5% similar