trash_mail
Move Mail messages to Trash for recoverable soft deletion, with a dry-run preview, backup, and undo support.
Instructions
Move Mail messages to Trash — soft delete, and the ONLY delete there is.
Mail's scripting layer cannot permanently erase a message: delete moves it to the
owning account's Trash, and nothing in the dictionary empties Trash from a script.
Emptying Trash is something the user does in Mail.app. So this is always
recoverable, and there is no permanent-delete tool to ask for.
DESTRUCTIVE but recoverable: every message's bytes are copied to a backup directory
and its source mailbox logged BEFORE anything is deleted, so mail_undo moves the
batch back out of Trash. dry_run DEFAULTS TO TRUE — the preview reports, per id,
whether it is actually present in mailbox. Pass dry_run=False to delete.
ids are RFC822 message-ids from a mail read, comma-separated; max 25 per call and
the cap is not overridable. mailbox is REQUIRED and must be the folder url from
the read that produced the ids, passed back VERBATIM — not one of the canonical
names: Mail files a deleted message in its OWNING account's Trash, and a unified
name ("inbox") cannot say which account that is. A Gmail label folder is refused
(a delete there is not a delete of the message, #287); use the message's
[Gmail]/All Mail folder.
Returns {op, receipt, count, succeeded, targets, destination, backup_dir, undo} —
keep receipt to undo the batch. Each copy is deleted by Mail's internal id and
verified by the account Trash's count rising, or every one of its copies' source
reference going gone within a bounded wait (12 checks, 0.5s apart — up to 5.5s) —
Mail's delete clears the source ASYNCHRONOUSLY, so "gone from the source" alone is
not a signal that can be read straight after the call. A message with several
stored copies gets every one of them trashed. If the call times out mid-batch,
re-run the same batch or
mail_undo the receipt. 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 | ||
| mailbox | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||