save_mail_attachment
Save one email attachment to an approved local folder without overwriting existing files. Fetches the message when needed and reports failures instead of leaving empty files.
Instructions
Save ONE attachment to disk (Automation, plus Full Disk Access to resolve a bare message_id).
List them with mail_attachments first, then address one by name or — when
several on the same message share a name, which is ordinary — by its
attachment_id (the id field on the attachment row). An ambiguous name RAISES
and lists the ids rather than picking one.
dest_dir must be inside the allowed root (~/Downloads by default;
MACOS_APPS_FILE_ROOT moves it) and is created if needed; a path outside it is
REFUSED. The filename is DERIVED from the attachment's name — an attachment name
comes from whoever sent the mail, so it is treated as hostile — and an existing
file is never overwritten. Writes are capped at 25 MiB.
mailbox is optional: the folder value from the read that produced message_id,
verbatim. Omitted, the id resolves on its own through the index.
Saving an attachment Mail has not downloaded makes Mail FETCH the message first, so this can take much longer than a read; if the account is offline the file lands empty, and it is then removed and reported as a failure rather than left behind. Returns {saved, name, original_name, bytes, reported_size, was_downloaded, id, folder}. Additive: writes a new file, never modifies mail.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | No | ||
| mailbox | No | ||
| dest_dir | Yes | ||
| message_id | Yes | ||
| attachment_id | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||