Skip to content

Fix: Quote mailbox names and add IMAP flag detection for Sent folder#93

Merged
Wh1isper merged 2 commits intoai-zerolab:mainfrom
KonstiDoll:fix/ionos-sent-folder-spaces
Jan 7, 2026
Merged

Fix: Quote mailbox names and add IMAP flag detection for Sent folder#93
Wh1isper merged 2 commits intoai-zerolab:mainfrom
KonstiDoll:fix/ionos-sent-folder-spaces

Conversation

@KonstiDoll
Copy link
Contributor

Fixes #92

Changes

  1. Quote mailbox names in IMAP APPEND (critical fix)

    • Use existing _quote_mailbox() helper in APPEND command
    • Fixes RFC 3501 compliance for folder names with spaces/special chars
  2. Auto-detect Sent folder via IMAP \Sent flag (enhancement)

    • Add _find_sent_folder_by_flag() method
    • Uses RFC 6154 IMAP flag to reliably find Sent folder
    • Works across all providers and locales
  3. Improved error handling

    • Wrap append_to_sent() in try-except
    • Log errors instead of silently failing

Testing

  • ✅ IONOS: Fixed - emails now saved to "Gesendete Objekte"
  • ✅ Gmail: Backward compatible - still works
  • ✅ Auto-detection: Successfully finds Sent folder via \Sent flag

Technical Details

The issue affected providers like IONOS that use folder names with spaces. The IMAP APPEND command requires quoted mailbox names per RFC 3501, but this wasn't enforced.

Example: IONOS uses "Gesendete Objekte" which failed without quoting.

The IMAP flag-based detection makes the server more robust for international users and various providers.

Fixes emails not being saved to Sent folder for providers like IONOS
that use folder names with spaces (e.g., "Gesendete Objekte").

Changes:
- Use _quote_mailbox() in IMAP APPEND command (RFC 3501 compliance)
- Add _find_sent_folder_by_flag() to detect Sent folder via IMAP \Sent flag
- Add error handling around append_to_sent()

Tested with:
- IONOS: Now works correctly
- Gmail: Backward compatible, still works
@codecov
Copy link

codecov bot commented Jan 7, 2026

Codecov Report

❌ Patch coverage is 95.23810% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
mcp_email_server/emails/classic.py 95.2% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

- Test _find_sent_folder_by_flag() with various folder names (IONOS, Gmail, etc.)
- Test integration with append_to_sent()
- Test error handling when append_to_sent fails
- All 9 new tests passing, total 27/27 tests in test_save_to_sent.py
@KonstiDoll
Copy link
Contributor Author

Added comprehensive tests for the new functionality:

Test Coverage:

  • 9 new tests covering _find_sent_folder_by_flag() method
  • Tests for IONOS case (folders with spaces), Gmail-style folders, and error handling
  • Integration tests for flag detection with append_to_sent()
  • Error handling test ensuring email is sent even if append fails

Results:

  • ✅ All 27 tests in test_save_to_sent.py passing
  • ✅ New functionality fully covered
  • ✅ Backward compatible with existing tests

This should address the code coverage concerns from Codecov.

Copy link
Member

@Wh1isper Wh1isper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks

@Wh1isper Wh1isper merged commit 4f8b616 into ai-zerolab:main Jan 7, 2026
9 checks passed
@KonstiDoll KonstiDoll deleted the fix/ionos-sent-folder-spaces branch January 7, 2026 22:54
@KonstiDoll KonstiDoll restored the fix/ionos-sent-folder-spaces branch January 7, 2026 22:55
rrroyal pushed a commit to rrroyal/mcp-email-server-auth that referenced this pull request Jan 9, 2026
…i-zerolab#93)

* Fix: Quote mailbox names and add IMAP flag detection for Sent folder

Fixes emails not being saved to Sent folder for providers like IONOS
that use folder names with spaces (e.g., "Gesendete Objekte").

Changes:
- Use _quote_mailbox() in IMAP APPEND command (RFC 3501 compliance)
- Add _find_sent_folder_by_flag() to detect Sent folder via IMAP \Sent flag
- Add error handling around append_to_sent()

Tested with:
- IONOS: Now works correctly
- Gmail: Backward compatible, still works

* Add comprehensive tests for IMAP flag detection and error handling

- Test _find_sent_folder_by_flag() with various folder names (IONOS, Gmail, etc.)
- Test integration with append_to_sent()
- Test error handling when append_to_sent fails
- All 9 new tests passing, total 27/27 tests in test_save_to_sent.py

---------

Co-authored-by: KonstiDoll <konstantin.doll@urban-codesign.com>
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.

Bug: Emails not saved to Sent folder with IONOS and similar providers

2 participants