🔍 Code Extractor

class MessageRule

Maturity: 47

A class representing an Outlook message rule that defines conditions, actions, and exceptions for automatically processing incoming messages in a user's Inbox.

File:
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/outlook/mail/messages/rules/rule.py
Lines:
6 - 32
Complexity:
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

    A data class representing conditions and exceptions for email message rules in Microsoft Outlook, inheriting from ClientValue.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/outlook/mail/messages/rules/predicates.py
  • class Message 67.9% 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
  • class EventMessage 61.3% similar

    A class representing an event message in Outlook, which can be a meeting request, cancellation, or response (acceptance, tentative acceptance, or decline).

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/outlook/mail/messages/event_message.py
  • class MailFolder 59.4% similar

    Represents a mail folder in a user's mailbox (e.g., Inbox, Drafts) that can contain messages, Outlook items, and child folders. Provides methods for folder operations like copying, emptying, and marking messages as read/unread.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/outlook/mail/folders/folder.py
  • class MessageRuleActions 58.5% similar

    Represents the set of actions that are available to a rule.

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