move_email
Transfer an email to a different folder or label using its message ID and target folder. Supports multiple accounts.
Instructions
Move an email to another folder/label.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| message_id | Yes | ||
| target_folder | Yes | ||
| account | No | ||
| folder | No | INBOX |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/productivity_mcp/server.py:237-247 (handler)Tool handler for 'move_email'. Decorated with @mcp.tool() and @_logged, it resolves the email provider via _email(account) and calls provider.move_message() to perform the move.
@mcp.tool() @_logged def move_email( message_id: str, target_folder: str, account: str | None = None, folder: str = "INBOX", ) -> dict[str, str]: """Move an email to another folder/label.""" _email(account).move_message(message_id, target_folder, folder=folder) return {"status": "moved", "message_id": message_id, "target": target_folder} - Abstract base class defining the move_message interface that all email providers must implement.
@abstractmethod def move_message(self, message_id: str, target_folder: str, folder: str = "INBOX") -> None: ... - Gmail provider implementation of move_message. Uses Gmail API's modify() to add/remove labels (since Gmail has labels, not folders).
def move_message(self, message_id: str, target_folder: str, folder: str = "INBOX") -> None: # Gmail has labels, not folders. "Move" = add target label, remove source. body = {"addLabelIds": [target_folder]} if folder and folder != target_folder: body["removeLabelIds"] = [folder] self._svc().users().messages().modify(userId="me", id=message_id, body=body).execute() - IMAP provider implementation of move_message. Uses IMAP UID MOVE if available, otherwise falls back to COPY + STORE \Deleted + EXPUNGE.
def move_message(self, message_id: str, target_folder: str, folder: str = "INBOX") -> None: with self._lock: conn = self._select(folder, readonly=False) typ, _ = conn.uid("MOVE", message_id, target_folder) if typ != "OK": conn.uid("COPY", message_id, target_folder) conn.uid("STORE", message_id, "+FLAGS", "(\\Deleted)") conn.expunge()