list_folders
Retrieve all email folders to organize and manage messages within the Mail MCP Server.
Instructions
List all email folders
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/mail_mcp/folders/manager.py:124-164 (handler)The list_folders method in FolderManager handles the IMAP list command to retrieve folders.
def list_folders(self, directory: str = "", pattern: str = "*") -> list[str]: """ List all folders matching the pattern. Uses IMAP LIST command to retrieve all mailboxes. Args: directory: Directory prefix (e.g., 'INBOX') pattern: Mailbox pattern (default '*' matches all) Returns: List of folder names Raises: FolderError: If the operation fails Example: >>> folders = manager.list_folders() >>> print(folders) ['INBOX', 'INBOX/Sent', 'INBOX/Drafts', 'Archive'] """ try: response = self._conn.list(directory, pattern) # 检查状态 (可能是 'OK' 或 b'OK') status = response[0] if status not in ("OK", b"OK"): error_msg = ( response[1][0].decode("utf-8", errors="replace") if response[1] else "Unknown error" ) raise FolderError(f"Failed to list folders: {error_msg}") return self._parse_folder_list(response) except Exception as e: if isinstance(e, FolderError): raise raise FolderError(f"Failed to list folders: {str(e)}")