Skip to main content
Glama

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
NameRequiredDescriptionDefault
source_folderYesSource folder name
target_folderYesTarget folder name
message_idNoMessage ID (sequence number)
uidNoUnique ID of the message

Implementation Reference

  • 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)}")

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/AdJIa/mail-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server