move_mail
Moves Mail messages between mailboxes for archiving, filing, or refiling, with a dry-run preview enabled by default and backup plus undo for safe recovery.
Instructions
Move messages between Mail mailboxes — archive, file, or refile. DESTRUCTIVE but
recoverable: every message's bytes are copied to a backup directory and its source
mailbox is logged BEFORE anything moves, so mail_undo puts the batch back.
dry_run DEFAULTS TO TRUE — the preview reads Mail and reports, per id, whether it
is actually present in from_mailbox. Pass dry_run=False to move.
ids are RFC822 message-ids from a mail read, comma-separated; max 25 per call and
the cap is not overridable. BOTH mailboxes are required and are address tokens.
from_mailbox must be the folder value from the read that produced the ids,
passed back VERBATIM (an opaque imap://<uuid>/<path> token, not a name to
retype); a canonical name there is refused. to_mailbox may also be one of the
canonical "inbox"/"sent"/"drafts"/"trash"/"junk", which files into the SOURCE
message's own account (it names Mail's cross-account accessor, not one mailbox),
so it is refused for an On My Mac source — that store has none of the five. A
Gmail label folder is refused as either end (a move out of a label left a copy
on device, so mail_undo cannot reverse a move into one), and a canonical
to_mailbox is refused when the source account has Gmail label folders. Pass a
folder url from mail_overview when in doubt. To archive, move into a mailbox
named Archive — there is no separate archive tool.
Cross-account moves are supported and leave exactly ONE copy (out of a Gmail label
they do not, which is why a label is refused). Verification is
by-ID (#206): each copy's internal reference must go dead after the move, and the
destination's count of that Message-ID must rise — presence alone can't tell a
landed copy from a pre-existing one. A Message-ID with several copies in the
source gets every one of them moved; ok means every copy left. A per-id
status reports what really happened rather than assuming success. If the call
times out mid-batch, the error names the receipt — re-run the same batch, or
mail_undo it.
Returns {op, receipt, count, succeeded, targets, destination, backup_dir, undo} —
keep receipt to undo the batch. Needs Automation access for Mail,
plus Full Disk Access to locate each message's file for the backup.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ids | Yes | ||
| dry_run | No | ||
| to_mailbox | Yes | ||
| from_mailbox | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||