Skip to content

feat: add forward_email MCP tool#104

Closed
jkp wants to merge 11 commits intoai-zerolab:mainfrom
jkp:feat/forward-email
Closed

feat: add forward_email MCP tool#104
jkp wants to merge 11 commits intoai-zerolab:mainfrom
jkp:feat/forward-email

Conversation

@jkp
Copy link

@jkp jkp commented Jan 17, 2026

Summary

  • Add forward_email MCP tool to forward emails to new recipients with original body and attachments preserved
  • Support custom sender address override for accounts with multiple email addresses
  • Include optional additional message before forwarded content
  • Automatically detect and preserve existing "Fwd:" prefix in subject lines

Test plan

  • Unit tests for ClassicEmailHandler.forward_email() method
  • Unit tests for get_email_for_forward() IMAP fetch helper
  • MCP tool tests for forward_email with various options
  • Test handling of email not found scenario
  • All 33 tests passing

🤖 Generated with Claude Code

@codecov
Copy link

codecov bot commented Jan 17, 2026

Codecov Report

❌ Patch coverage is 81.35593% with 33 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
mcp_email_server/emails/classic.py 79.7% 21 Missing and 12 partials ⚠️

📢 Thoughts on this report? Let us know!

Jamie Kirkpatrick and others added 11 commits January 17, 2026 09:52
Add MCP_EMAIL_SERVER_SMTP_VERIFY_SSL environment variable to disable
SSL certificate verification for SMTP connections. Useful for local
mail servers with self-signed certificates (e.g., ProtonMail Bridge).

Defaults to true (verify certificates).

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add MCP_EMAIL_SERVER_SMTP_VERIFY_SSL to environment variables table
- Add usage section for self-signed certificates (e.g., ProtonMail Bridge)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add _create_smtp_ssl_context() module-level helper for creating
  permissive SSL context when verify_ssl=False
- Add _get_smtp_ssl_context() method to EmailClient
- Pass tls_context to aiosmtplib.SMTP in send_email()
- Add tests for SSL context creation

This enables the verify_ssl config option (added in ccb2c0b) to actually
take effect when sending emails, allowing use of self-signed certificates
like those from Proton Mail Bridge.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add ability to forward emails to new recipients with original body
and attachments preserved. Supports custom sender address override
and optional additional message before forwarded content.

- Add ForwardEmailResponse model
- Add forward_email abstract method to EmailHandler
- Implement get_email_for_forward in EmailClient for IMAP fetch
- Implement forward_email in ClassicEmailHandler with SMTP send
- Add forward_email MCP tool with full parameter support
- Add comprehensive tests for handler and MCP tool

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Extract html_body from emails alongside plain text body
- Forward HTML-only emails as HTML with proper formatting
- Use justhtml to convert HTML to clean text for multipart emails
- Add RFC 5322 Date header to forwarded emails
- Add tests for HTML, plain text, multipart, and Date header

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Tests cover:
- Plain text email extraction
- HTML-only email extraction with is_html flag
- Multipart email (both plain and HTML)
- Email with attachments
- Email not found case
- Raw email extraction failure
- Custom mailbox parameter

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Extract helper methods to reduce cyclomatic complexity:
- _decode_part_content: decode MIME part with charset handling
- _extract_attachment_part: extract attachment as MIMEApplication
- _extract_forward_parts: extract body, html_body, attachments
- _build_html_forward_content: build HTML forward body
- _build_plain_forward_content: build plain text forward body
- _create_forward_message: create MIME message with attachments
- _set_header_with_encoding: set header with UTF-8 if needed

Also use ternary operator for forward_body assignment (SIM108).

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Pass tls_context to forward_email's SMTP connection to respect
the verify_ssl configuration, enabling self-signed certificate
support when forwarding emails.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@jkp jkp force-pushed the feat/forward-email branch from 13c2efa to 3986414 Compare January 17, 2026 13:26
@Wh1isper
Copy link
Member

I don't think we need this tool... Close for now.

Welcome to raise an issue!

@Wh1isper Wh1isper closed this Jan 19, 2026
@jkp
Copy link
Author

jkp commented Jan 20, 2026

Confused...is there another way to forward an email using the server?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants