Skip to content

feat: add mailbox parameter to download_attachment method#90

Merged
Wh1isper merged 1 commit intomainfrom
feat/download-attachment-mailbox-param
Dec 31, 2025
Merged

feat: add mailbox parameter to download_attachment method#90
Wh1isper merged 1 commit intomainfrom
feat/download-attachment-mailbox-param

Conversation

@Wh1isper
Copy link
Member

Summary

This PR adds a mailbox parameter to the download_attachment method, enabling users to download attachments from any mailbox instead of being restricted to INBOX.

Problem

Previously, download_attachment was hardcoded to use INBOX:

await imap.select(_quote_mailbox("INBOX"))

However, other methods in the same class accept a mailbox parameter with INBOX as the default:

  • get_email_count(mailbox: str = "INBOX")
  • get_emails_metadata_stream(mailbox: str = "INBOX")
  • get_email_body_by_id(mailbox: str = "INBOX")
  • delete_emails(email_ids, mailbox: str = "INBOX")

This inconsistency prevents users from downloading attachments from other mailboxes like "All Mail", "Sent", or "[Gmail]/Sent Mail".

Solution

Add consistent mailbox parameter support to download_attachment across all layers:

  1. EmailClient.download_attachment() - Core implementation with mailbox parameter
  2. ClassicEmailHandler.download_attachment() - Handler layer with mailbox parameter
  3. Abstract EmailHandler.download_attachment() - Interface definition with mailbox parameter
  4. MCP tool download_attachment() - Exposed to AI agents with mailbox parameter

Changes

Code Changes

  • mcp_email_server/emails/classic.py:

    • Added mailbox: str = "INBOX" parameter to EmailClient.download_attachment()
    • Added mailbox: str = "INBOX" parameter to ClassicEmailHandler.download_attachment()
    • Updated docstrings with Args section
  • mcp_email_server/emails/init.py:

    • Added mailbox: str = "INBOX" parameter to abstract EmailHandler.download_attachment()
    • Updated docstring
  • mcp_email_server/app.py:

    • Added mailbox parameter to MCP tool download_attachment()

Test Changes

  • tests/test_email_attachments.py: Added 3 new tests for mailbox parameter
  • tests/test_classic_handler.py: Updated assertion for new parameter
  • tests/test_mcp_tools.py: Updated assertion for new parameter

Testing

  • ✅ All 101 tests pass
  • make check passes (ruff formatting, linting, dependency checks)

Backward Compatibility

Fully backward compatible. The new parameter has a default value of "INBOX", so existing code will continue to work unchanged.

Usage Example

# Download from INBOX (default, existing behavior)
await handler.download_attachment("123", "document.pdf", "/path/to/save")

# Download from a custom mailbox (new capability)
await handler.download_attachment("456", "report.pdf", "/path/to/save", mailbox="All Mail")
await handler.download_attachment("789", "invoice.pdf", "/path/to/save", mailbox="[Gmail]/Sent Mail")

Checklist

  • Code follows project style guidelines
  • Tests added for new functionality
  • All tests passing (101/101)
  • make check passes
  • Backward compatibility maintained
  • Documentation updated (docstrings)

Previously download_attachment was hardcoded to use INBOX, while other
methods (get_email_count, get_emails_metadata_stream, get_email_body_by_id,
delete_emails) accept a mailbox parameter with INBOX as default.

This change adds consistent mailbox parameter support to download_attachment,
allowing users to download attachments from any mailbox (e.g., All Mail,
Sent, [Gmail]/Sent Mail).

Changes:
- Add mailbox parameter to EmailClient.download_attachment() with default "INBOX"
- Add mailbox parameter to ClassicEmailHandler.download_attachment()
- Add mailbox parameter to abstract EmailHandler.download_attachment()
- Add mailbox parameter to MCP tool download_attachment()
- Add comprehensive tests for mailbox parameter functionality
- Update existing test assertions for new parameter
@codecov
Copy link

codecov bot commented Dec 31, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@Wh1isper Wh1isper marked this pull request as ready for review December 31, 2025 10:40
@Wh1isper Wh1isper merged commit da5cefe into main Dec 31, 2025
16 checks passed
@Wh1isper Wh1isper deleted the feat/download-attachment-mailbox-param branch December 31, 2025 10:40
rrroyal pushed a commit to rrroyal/mcp-email-server-auth that referenced this pull request Jan 9, 2026
)

Previously download_attachment was hardcoded to use INBOX, while other
methods (get_email_count, get_emails_metadata_stream, get_email_body_by_id,
delete_emails) accept a mailbox parameter with INBOX as default.

This change adds consistent mailbox parameter support to download_attachment,
allowing users to download attachments from any mailbox (e.g., All Mail,
Sent, [Gmail]/Sent Mail).

Changes:
- Add mailbox parameter to EmailClient.download_attachment() with default "INBOX"
- Add mailbox parameter to ClassicEmailHandler.download_attachment()
- Add mailbox parameter to abstract EmailHandler.download_attachment()
- Add mailbox parameter to MCP tool download_attachment()
- Add comprehensive tests for mailbox parameter functionality
- Update existing test assertions for new parameter
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.

1 participant