create_rule
Automate email handling by creating a Mail.app rule with conditions on sender, subject, or body, and actions like move, delete, forward, or mark read. User confirmation required for destructive actions.
Instructions
Create a new Mail.app rule.
Rules with actions that can move, forward, or delete mail
(delete / forward_to / move_to / copy_to) require user confirmation —
a single create can install automation that auto-forwards or deletes
all future mail (#222). Organizational-only rules (mark_read,
mark_flagged, flag_color) are created without a prompt. Mail.app
appends new rules to the end of the rule list, so the returned
rule_index equals the new total rule count.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Rule display name. Need not be unique. | |
| actions | Yes | Dict with at least one truthy entry from: - move_to: {"account": str, "mailbox": str} - copy_to: {"account": str, "mailbox": str} - mark_read: bool - mark_flagged: bool (with optional flag_color enum) - flag_color: 'none' | 'red' | 'orange' | 'yellow' | 'green' | 'blue' | 'purple' | 'gray' - delete: bool - forward_to: list[str] of email addresses | |
| enabled | No | Whether the rule is enabled on creation. Default True. | |
| conditions | Yes | List of condition dicts (at least one required). Each: - field: 'from' | 'to' | 'subject' | 'body' | 'any_recipient' | 'header_name' - operator: 'contains' | 'does_not_contain' | 'begins_with' | 'ends_with' | 'equals' - value: substring or value to match - header_name: required iff field == 'header_name' | |
| match_logic | No | 'all' (AND across conditions) or 'any' (OR). Default 'all'. | all |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||