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
| 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:177-236 (handler)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)}")