move_email
Move email messages between folders to organize your inbox. Specify source and target folders with message ID or UID for precise email management.
Instructions
Move email to another folder
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| source_folder | Yes | Source folder name | |
| target_folder | Yes | Target folder name | |
| message_id | No | Message ID (sequence number) | |
| uid | No | Unique ID of the message |
Implementation Reference
- src/mail_mcp/operations/move.py:88-143 (handler)The actual logic for moving emails is implemented in the EmailMove.move_email method in src/mail_mcp/operations/move.py, which attempts an IMAP MOVE command with a fallback to COPY and DELETE if MOVE is not supported.
def move_email( self, source_folder: str, uids: int | list[int], destination_folder: str ) -> bool: """ Move emails from one folder to another. Uses IMAP MOVE command (RFC 6851) if available, otherwise falls back to copy + delete. Args: source_folder: Source folder containing the emails uids: Email UID or list of UIDs to move destination_folder: Destination folder Returns: True if successful Raises: EmailMoveError: If operation fails Example: >>> move = EmailMove(conn) >>> move.move_email('INBOX', [1, 2, 3], 'INBOX/Archive') True """ if not source_folder: raise EmailMoveError("Source folder is required") if not destination_folder: raise EmailMoveError("Destination folder is required") if source_folder == destination_folder: raise EmailMoveError("Source and destination folders must be different") # Select source folder to get current state self._select_folder(source_folder) uid_string = self._validate_uids(uids) try: # Try MOVE command first (IMAP4rev2) response = self._conn.uid("MOVE", uid_string, destination_folder) if response[0] == b"OK": return True # If MOVE not supported, fall back to COPY + STORE +DELETED return self._move_fallback(source_folder, uids, destination_folder) except Exception as e: # Try fallback method try: return self._move_fallback(source_folder, uids, destination_folder) except EmailMoveError: raise EmailMoveError(f"Failed to move email: {str(e)}")