Skip to content

Improve IMAP import (folder select and partial success)#497

Draft
sdemagny wants to merge 5 commits into
mainfrom
sdem/enhance_imap_impt
Draft

Improve IMAP import (folder select and partial success)#497
sdemagny wants to merge 5 commits into
mainfrom
sdem/enhance_imap_impt

Conversation

@sdemagny

Copy link
Copy Markdown
Contributor

No description provided.

- Add STARTTLS negotiation for port 143 with use_ssl=True
- Create IMAPSecurityError exception for security violations
- Refuse to continue unencrypted when SSL is required
- Check server STARTTLS capability before attempting upgrade
- Fail fast to prevent credential leakage on security downgrade

Connection behavior:
- Port 993 + use_ssl=True → SSL direct
- Port 143 + use_ssl=True → STARTTLS (mandatory)
- Port 143 + use_ssl=False → unencrypted (explicit choice)

Fixes: SSL WRONG_VERSION_NUMBER error on port 143
Backend improvements:
- Catch SSL handshake failures during IMAP4_SSL connection
- Provide clear error message suggesting port 143 with STARTTLS
- Add authentication failure logging with username context
- Wrap login() in try-except to log auth errors before propagating

Frontend improvements:
- Detect "IMAP authentication failed" message in error responses
- Display user-friendly credential error message in UI

This helps users understand connection failures and authentication
issues with clearer, actionable error messages.
Sentry integration:
- Add capture_exception for all IMAP import errors
- Track folder selection failures, search failures, message processing errors
- Capture errors in MBOX and EML import tasks

Folder selection improvements:
- Use shlex for more robust folder name parsing
- Try exact folder name first with readonly=True
- Simplify variations: remove duplicates and invalid combinations
- Add INBOX.folder variation for servers using dot separator
- Remove unnecessary UTF-7 re-encoding (already handled by server)

Fallback strategy:
- Catch get_selectable_folders exceptions and fallback to INBOX
- Always try INBOX if no folders found
- Warn if no messages imported after processing

Log level adjustments:
- Downgrade folder selection failures from ERROR to WARNING
- Add DEBUG logs for folder parsing and selection attempts
- These failures are expected for container folders without \Noselect flag

Result: More resilient import that continues even when some folders
fail, with better visibility in Sentry for real issues.
Frontend:
- Show success/failure counts in completion modal
- Add warning icon style for partial failures
- Pass task metadata through to StepCompleted component

Backend:
- Report detailed status for partial successes
- Track success_count, failure_count in task result
- Set appropriate task status based on import results
@coderabbitai

coderabbitai Bot commented Jan 20, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sdemagny sdemagny changed the title Improve IMAP import (folder, partial success) Improve IMAP import (folder select and partial success) Jan 20, 2026
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