Overview
Moves a message from its current mailbox to a destination mailbox within the same account. The message is removed from the source mailbox and appears in the destination mailbox. The server uses the native IMAPMOVE command when available, or falls back to COPY + DELETE + EXPUNGE when the server doesn’t support MOVE.
To move messages between different accounts, use
imap_copy_message followed by imap_delete_message.Common use cases
- Move messages to Archive or Trash folders
- Organize messages into project or category folders
- Move spam to Junk folder
- Relocate drafts to Sent folder after sending
- File messages into date-based folders
Input parameters
Account identifier. Must match pattern
^[A-Za-z0-9_-]{1,64}$.Message identifier in format
imap:{account_id}:{mailbox}:{uidvalidity}:{uid}.The account_id in the message_id must match the account_id parameter.Destination mailbox name (1-256 characters). Must not contain control characters.The mailbox must exist on the IMAP server. Use
imap_list_mailboxes to see available mailboxes.Response
Human-readable one-line outcome:
"Message moved"Example request
Example response
Error responses
Implementation notes
Move strategy selection
The server checks IMAP server capabilities to determine which strategy to use: Native MOVE (preferred):- Connect and authenticate (
steps_attempted=1) - Check server capabilities (
steps_attempted=2, internally tracked) - Execute
UID MOVEcommand (steps_attempted=2)
- Connect and authenticate (
steps_attempted=1) - Check server capabilities (
steps_attempted=2) - Copy message to destination using
UID COPY(steps_attempted=3) - Mark original as deleted using
UID STORE +FLAGS.SILENT (\\Deleted)(steps_attempted=4) - Expunge the deleted message using
UID EXPUNGE(steps_attempted=4)
Atomicity considerations
- Native MOVE: Atomic operation guaranteed by the IMAP server
- COPY+DELETE fallback: Not atomic - if the delete or expunge step fails, the message will exist in both mailboxes
Partial failures
When using COPY+DELETE fallback, partial failures can occur:- Copy succeeds, but delete fails: Message appears in both mailboxes
- Copy and delete succeed, but expunge fails: Message marked as deleted but still visible in source mailbox until next expunge
steps_succeeded and issues to determine the exact failure point.
Message visibility
After a successful move:- The message immediately appears in the destination mailbox
- The message is removed from the source mailbox (or marked as
\Deletedif expunge failed) - The message UID changes in the destination mailbox
- The old message_id from the source mailbox becomes invalid
See also
- imap_copy_message - Copy message without removing from source
- imap_delete_message - Permanently delete a message
- imap_list_mailboxes - List available mailboxes
- Write operations configuration - Enable write operations