Add email flags and unsubscribe features
All checks were successful
Build And Test / publish (push) Successful in 48s

- Add set_email_flags tool for IMAP flags (standard + custom keywords)
- Add unsubscribe_email tool with List-Unsubscribe header parsing
- Support RFC 8058 one-click unsubscribe
- Add UnsubscribeInfo model to email responses
- Add data field to OperationResult for extra context
- Include test.sh script for MCP server testing

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2025-12-30 17:23:49 -08:00
parent 47f483ea1b
commit ba57c5fba4
5 changed files with 321 additions and 2 deletions

View File

@@ -132,3 +132,42 @@ def register_email_tools(mcp: FastMCP, service: EmailService):
"""
result = await service.send_email(to, subject, body, cc, bcc, reply_to, html_body)
return result.model_dump()
@mcp.tool(description="Set or remove IMAP flags on an email. Standard flags: \\Seen, \\Answered, \\Flagged, \\Deleted, \\Draft. Custom keywords are also supported.")
def set_email_flags(
email_id: str,
mailbox: str,
add_flags: Optional[list[str]] = None,
remove_flags: Optional[list[str]] = None,
) -> dict:
"""
Set or remove flags on an email.
Args:
email_id: The unique ID of the email
mailbox: The mailbox containing the email
add_flags: Flags to add (e.g., ["\\Flagged", "important"])
remove_flags: Flags to remove (e.g., ["\\Seen"])
"""
result = service.set_flags(email_id, mailbox, add_flags, remove_flags)
return result.model_dump()
@mcp.tool(description="Unsubscribe from a mailing list. Parses List-Unsubscribe headers and attempts automatic unsubscribe via HTTP or provides mailto instructions.")
async def unsubscribe_email(
email_id: str,
mailbox: str = "INBOX",
) -> dict:
"""
Unsubscribe from a mailing list based on email headers.
Args:
email_id: The unique ID of the email containing unsubscribe info
mailbox: The mailbox containing the email (default: INBOX)
Returns:
Result with unsubscribe status. For HTTP unsubscribe, it attempts
automatic unsubscription. For mailto, it returns the email details
to send.
"""
result = await service.unsubscribe(mailbox, email_id)
return result.model_dump()