fix(email): send IMAP ID extension to support 163/NetEase mailbox#22528
Closed
wesleysimplicio wants to merge 2 commits into
Closed
fix(email): send IMAP ID extension to support 163/NetEase mailbox#22528wesleysimplicio wants to merge 2 commits into
wesleysimplicio wants to merge 2 commits into
Conversation
163/NetEase IMAP servers reject every UID SEARCH/FETCH with `BYE Unsafe Login` unless the client first identifies itself via the RFC 2971 ID command after LOGIN. Without this, the email gateway logs in OK but then fails on the very first poll and the connection is torn down. Send the ID payload best-effort after both `imap.login()` sites (`EmailAdapter.connect` and `_fetch_new_messages`). Failures are swallowed at debug level so non-supporting IMAP servers (Gmail, Outlook, Fastmail, Yahoo, etc.) keep working unchanged. Closes NousResearch#22271
Contributor
There was a problem hiding this comment.
Pull request overview
Adds best-effort support for NetEase/163 IMAP servers that require an RFC 2971 ID command after LOGIN, preventing immediate BYE Unsafe Login disconnects during subsequent UID SEARCH/UID FETCH operations in the email gateway.
Changes:
- Introduces a reusable
_send_imap_id(imap)helper that attempts to send an IMAPIDpayload and swallows failures for non-supporting servers. - Calls
_send_imap_id()immediately afterimap.login()in bothEmailAdapter.connect()andEmailAdapter._fetch_new_messages(). - Adds regression tests asserting
IDis sent after login in both the initial connect path and the polling path, plus a test ensuring failures are non-fatal.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
gateway/platforms/email.py |
Adds _send_imap_id() and invokes it after IMAP login in both connection-check and polling sessions. |
tests/gateway/test_email.py |
Adds regression tests for sending RFC 2971 ID after login and for swallowing unsupported-server errors. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+77
to
+82
| imap.xatom( | ||
| "ID", | ||
| '("name" "hermes-agent" "version" "1.0" ' | ||
| '"vendor" "NousResearch" ' | ||
| '"support-email" "noreply@nousresearch.com")', | ||
| ) |
Contributor
|
Merged via salvage PR #22796. salvage cherry-picked your commits; authorship preserved. Thanks for the contribution! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
163/NetEase IMAP servers reject every
UID SEARCH/UID FETCHwithBYE Unsafe Loginunless the client first identifies itself via the RFC 2971IDcommand afterLOGIN. Without this, the email gateway authenticates OK but then fails on the very first poll and the connection is torn down — repeatedly.This PR sends the
IDpayload best-effort after eachimap.login():EmailAdapter.connect()— initial connection checkEmailAdapter._fetch_new_messages()— every poll cycle (opens its own session)The send is wrapped in try/except so non-supporting IMAP servers (Gmail, Outlook, Fastmail, Yahoo, …) keep working unchanged — they either honor the command silently or reply
BAD, which we log at debug.Why a tiny helper
_send_imap_id(imap)lives at module level so it can be tested in isolation and reused by both login sites without duplicating the literal payload.Test plan
New
TestImapIdExtensionForNetEaseclass covers:test_connect_sends_imap_id_after_login— assertsxatom("ID", ...)is called afterLOGINfromconnect(), payload contains client nametest_fetch_new_messages_sends_imap_id_after_login— same assertion for the polling path (which opens a separate IMAP session)test_send_imap_id_swallows_errors_for_non_supporting_servers— feeds the helper a server that raises onxatom, verifies it does not propagateStash-verified: all three tests fail without the source change, pass with it. Existing 60-test
test_email.pysuite continues to pass.Closes #22271
🤖 Generated with Claude Code