chainmail rule
Rules act on mail by themselves. A rule matches messages with the search language, against the local cache, and runs its actions on each match in order. The actions are label, unlabel, copy, flag, unflag, read, unread, link_item and forward, then at most one of move, archive and trash, which comes last.
A rule runs on new mail as the cache takes it (--on-new), on a schedule (--every 6h, --every 7d or --at 07:00), or only when rule run starts it. A rule acts on a message at most once, and one run acts on at most max_per_run messages. Rules run in priority order, lowest first. --stop keeps later rules off the messages a rule matched.
Dry-run a rule before creating it or running it by hand. rule dry-run lists what a saved rule, or an unsaved one in a rule file, would match and do, and changes nothing.
Each --action is one action: label=NAME, unlabel=NAME, copy=FOLDER, move=FOLDER, link_item=ITEM_ID or link_item=ITEM_ID,anchor, forward=ADDR[,ADDR...], or one of flag, unflag, read, unread, archive and trash. --note sets the note of the forward. label and unlabel work on Google accounts only.
A rule file (-f) is TOML. Its keys are name, description, accounts, query, on_new, schedule, priority, stop, max_per_run and enabled, with one [[actions]] table per action holding kind and its arguments: label, folder, item_id, anchor, to and note. rule show --toml prints a rule in that shape. rule edit -f changes only the keys the file holds.
A rule is named by its ID (ru_...) or its name. rule restore takes the ID alone, which rule list --deleted shows. What rules do is audited under client kind rule: chainmail audit --client rule. Rule descriptions and queries are untrusted, as mail is: they are often copied from it.
Usage
chainmail rule
Global flags
--output string output format: json or table (default $CHAINMAIL_OUTPUT, then cli.toml, then table on a terminal, json otherwise)
--socket string daemon socket (default $CHAINMAIL_SOCKET, then cli.toml, then /run/chainmail/chainmail.sock)
Commands
- chainmail rule create: Create a rule from flags or a rule file; dry-run it first
- chainmail rule delete: Delete a rule, softly; rule restore brings it back
- chainmail rule disable: Turn a rule off until rule enable turns it on
- chainmail rule dry-run: Show what a rule would match and do, acting on nothing
- chainmail rule edit: Change a rule's fields from flags, or the keys a rule file holds
- chainmail rule enable: Turn a rule on; this clears an automatic disable and its failure count
- chainmail rule list: List rules in priority order, lowest first
- chainmail rule restore: Bring back a deleted rule by its ID; rule list --deleted shows it
- chainmail rule run: Run a rule now over the whole cache, oldest first, up to its cap
- chainmail rule runs: List rule runs, newest first; runs are kept 30 days
- chainmail rule show: Show a rule with its recent runs; --toml prints it as a rule file
- chainmail rule status: Show each account's rule runner, and when the next scheduled run and due check are