mail_run_bulk_action
Move, archive, trash, or mark read all messages in an iCloud Mail folder matching filters. Preview the matches first, confirm to run, and undo within 30 days.
Instructions
Move, archive, trash or mark read every message in one folder that matches filters, in two steps (preview, then confirmed run) with a 30-day undo.
Use when: the owner wants a cleanup such as 'archive everything from news@example.org before March'. Not for a few known messages (use mail_move_messages, mail_delete_messages or mail_mark_messages), for flagging or marking unread (use mail_mark_messages), or for stopping future mail (use mail_unsubscribe_from_list). Parameters:
At least one filter (from_address, subject, text, since, before, unread) is required; filters combine with AND.
from_address, subject and text match substrings; text covers headers and body. since is inclusive, before exclusive.
destination is required for move and ignored otherwise; archive and trash use the special folders.
max_messages is clamped to 1..1000 and takes the newest matches.
The dry_run=false call must repeat the preview's folder, action, destination, filters and max_messages, plus its confirm_token. Behavior:
The dry run changes nothing. Show the owner the count and sample and run only on their yes.
The token is valid 15 minutes, until the server restarts, and only for exactly the previewed messages: if the matching set changed (new mail, other filters), the run is refused and you preview again.
Messages without a Message-ID are left alone and counted.
Each run is logged before it starts and can be reversed with mail_undo_bulk_action.
Nothing is deleted permanently: trash on Trash, and a destination equal to the source, are refused.
MAIL_MAX_AGE_DAYS, if set, limits how far back it reaches. Returns:
dry run: {folder, action, destination, total_matches, would_handle, confirm_token (null when nothing matches), sample of up to 10 {from, subject, date}, note when more match than max_messages, safety_warnings}.
run: the same counts plus done, action_id and undo. Errors: no filter, move without destination, an unknown action or folder, or a bad or stale token (run the dry run again).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | No | Only messages containing this text. | |
| since | No | Only messages on or after this date, YYYY-MM-DD. | |
| action | Yes | move, archive, trash (to the Trash, recoverable) or mark_read. | |
| before | No | Only messages before this date, YYYY-MM-DD. | |
| folder | No | Mail folder, e.g. INBOX, Sent, Archive or a custom name. | INBOX |
| unread | No | true = only unread, false = only read. | |
| dry_run | No | true (default) = only preview: count, sample and a confirm_token. Nothing changes. | |
| subject | No | Only messages whose subject contains this. | |
| destination | No | Destination folder, only for action 'move'. | |
| from_address | No | Only messages from this address or name (partial match). | |
| max_messages | No | Handle at most this many, newest first (default 200, max 1000). | |
| confirm_token | No | From the dry run; required when dry_run=false. |