create_rule
Create an Apple Mail rule that automatically files incoming mail from specified sender domains into a chosen folder, with optional sorting of existing messages.
Instructions
Create a native Apple Mail rule that files incoming mail from given sender domains into a folder. This is a REAL Mail rule: Mail applies it to new incoming mail automatically while Mail is running — no background process. Multiple domains are OR-combined into one rule. Native rules do not touch existing mail; set apply_to_existing=true to also sort what is already in the mailbox now. Idempotent: an existing rule with the same name is replaced. The destination folder must already exist (use create_folder).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Rule name — also the identity key for replace/delete, e.g. "Newsletters". | |
| account | No | Account whose folder is the destination. Defaults to "iCloud". | iCloud |
| domains | Yes | Sender domains to match, e.g. ["newsletter.com","shop.de"]. Mail is filed if its sender contains ANY of them. | |
| src_mailbox | No | Mailbox to sort when apply_to_existing is true. Defaults to "INBOX". | INBOX |
| dest_mailbox | Yes | Existing destination folder in the account, e.g. "Newsletters". | |
| apply_to_existing | No | Also move matching mail already in the source mailbox now (one pass per domain). Default false = future mail only. |