Skip to main content
Glama

copy_email

Move email messages between folders in your mailbox. Specify source and target folders with message ID or UID to organize your email efficiently.

Instructions

Copy 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 implementation of the copy_email logic inside the EmailMove class.
    def copy_email(
        self, source_folder: str, uids: int | list[int], destination_folder: str
    ) -> bool:
        """
        Copy emails to another folder.
    
        Unlike move, this preserves the original emails.
    
        Args:
            source_folder: Source folder containing the emails
            uids: Email UID or list of UIDs to copy
            destination_folder: Destination folder
    
        Returns:
            True if successful
    
        Raises:
            EmailMoveError: If operation fails
    
        Example:
            >>> move = EmailMove(conn)
            >>> move.copy_email('INBOX', [1, 2], 'INBOX/Backup')
            True
        """
        if not source_folder:
            raise EmailMoveError("Source folder is required")
    
        if not destination_folder:
            raise EmailMoveError("Destination folder is required")
    
        # Select source folder
        self._select_folder(source_folder)
    
        uid_string = self._validate_uids(uids)
    
        try:
            response = self._conn.uid("COPY", uid_string, destination_folder)
    
            status = response[0]
            if status not in ("OK", b"OK") and not isinstance(status, int):
                error_msg = (
                    response[1][0].decode("utf-8", errors="replace")
                    if response[1] and response[1][0]
                    else "Unknown error"
                )
    
                if "does not exist" in error_msg.lower():
                    raise EmailMoveError(
                        f"Destination folder '{destination_folder}' does not exist"
                    )
    
                raise EmailMoveError(f"Failed to copy email: {error_msg}")
    
            return True
    
        except EmailMoveError:
            raise
        except Exception as e:
            raise EmailMoveError(f"Failed to copy 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