C12.1: ely-mail-engine connects over IMAP, POP3 and SMTP
TLS or STARTTLS with the system trust store; password and XOAUTH2 logins keep the server's words on refusal. IMAP and POP3 are written in the engine (imap-proto parses IMAP replies): async-imap dropped NO/BAD on LIST and FETCH and lost BYE text, async-pop kept dot stuffing and logged passwords. SMTP runs its own transaction with RFC 5321 mailbox checks, full dot transparency, SMTPUTF8 and RSET. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
d7de5619a7
commit
9f47b94714
21 files changed
+2848
-20
No files matched your search
+2
-2
@@ -131,10 +131,10 @@
|
||||
|
||||
第二批发布(用户定,2026-10-08):首版不发布 ElyMail,首版的完整测试与打包不等它。
|
||||
|
||||
用户 2026-10-19 定:后端改为 Rust crate(async-imap、async-pop、mail-send、mail-parser、mail-builder),取代 MailCore 2;Gmail 与 Microsoft 走 OAuth,iCloud 走应用专用密码;正文按块的子集由 GPUI 绘制,写信用 Markdown 文档组件;OAuth 客户端 ID 构建时注入(`oauth.env` 与 CI 机密,注册由用户做)。协议测试一律对本机的替身服务器(测试里按脚本应答的 IMAP、POP3、SMTP 与 OAuth 端点),不靠真网络;真服务器只在用户给出账号或 ID 后另验。界面 120 fps:界面线程不等网络与数据库,长列表只画可见行。
|
||||
用户 2026-10-19 定:后端改为 Rust crate(mail-send、mail-parser、mail-builder,IMAP 与 POP3 由引擎自写),取代 MailCore 2;Gmail 与 Microsoft 走 OAuth,iCloud 走应用专用密码;正文按块的子集由 GPUI 绘制,写信用 Markdown 文档组件;OAuth 客户端 ID 构建时注入(`oauth.env` 与 CI 机密,注册由用户做)。协议测试一律对本机的替身服务器(测试里按脚本应答的 IMAP、POP3、SMTP 与 OAuth 端点),不靠真网络;真服务器只在用户给出账号或 ID 后另验。界面 120 fps:界面线程不等网络与数据库,长列表只画可见行。
|
||||
|
||||
- [x] C12.0 选型修订:PRD §1.1、§12.1、§17.3、§21.2、§23 与 `agents.md` 改为上述选型;删去 MailCore 2 与 libetpan 的取码、构建与探测脚本;`oauth.env` 不入库;`references.sh` 随之(并修上游钉与工作区不一致的组件库钉) — R1 ok
|
||||
- [ ] C12.1 `crates/ely-mail-engine` 与连通(MAIL-01 前半):IMAP、POP3、SMTP 经 TLS(rustls,系统根证书)或 STARTTLS 连接,密码与 XOAUTH2 认证,失败带服务器原话;替身服务器测三协议的登录、拒绝、列邮箱、取信、发信
|
||||
- [x] C12.1 `crates/ely-mail-engine` 与连通(MAIL-01 前半):IMAP、POP3、SMTP 经 TLS(rustls,系统根证书)或 STARTTLS 连接,密码与 XOAUTH2 认证,失败带服务器原话;替身服务器测三协议的登录、拒绝、列邮箱、取信、发信。已做:`Imap`、`Pop`、`Smtp` 三个会话,`Server`(主机、端口、`Security::Tls` 或 `StartTls`,无明文)、`Login`(密码或 OAuth 令牌);系统信任库经 rustls-platform-verifier,测试换入只信测试证书的连接器;每步 60 秒超时;`Error` 分连接、TLS、凭据被拒(服务器原话)、命令被拒、读不懂、超时、发不出(信封地址或登录带换行等)。IMAP 由引擎自写,以 imap-proto 解析(`wire.rs` 收一个个完整回复,含字面量),换下 async-imap(它的 LIST、FETCH 不看结尾的 NO 与 BAD,拒绝成了空结果与“无此 UID”;登录与命令中途的 `* BYE` 被丢掉,只剩断线;trace 日志写出密码与邮件):每条命令看结尾的状态,NO 与 BAD 带原话报出(登录为凭据被拒,其余为命令被拒);问候或任何时候收到 `* BYE`,此后断线即带其原话;非 ASCII 或带换行的参数以字面量发出,等服务器的 `+`;STARTTLS 之后若已有明文字节即拒绝;LIST 里带引号的邮箱名去掉转义(imap-proto 照原样留着),字面量照原样,列出的名字可直接打开;日志只记标签与命令名。POP3 由引擎自写(RFC 1939:问候、STLS、USER/PASS、AUTH XOAUTH2、UIDL、RETR、QUIT),换下 async-pop(它留着点填充、丢末尾 CRLF、吞掉登录后 CAPA 的连接错误、不答 XOAUTH2 的错误挑战、在 trace 日志里写出密码与邮件);STLS 之后若已有明文字节即拒绝;用户名与密码带换行即拒绝。SMTP 的 XOAUTH2 与事务由引擎自走(mail-send 遇错误挑战会重发令牌;它的 DATA 不给首行的点加点,且自加末尾 CRLF):信封地址照 RFC 5321 的 Mailbox 核对(点串或带引号的本地部分,域名或地址字面量;地址或信头有 UTF-8 时,服务器报 SMTPUTF8 才发出并带此参数,否则拒绝(RFC 6531)),不合即拒绝、不发任何命令;DATA 每行开头的点(含首行)加一个点,裸 CR 或 LF 即拒绝。服务器拒绝事务中的一步后发 RSET,会话可再发信。三协议的 XOAUTH2 被拒都以空行答错误挑战、留下服务器最后的原话。34 个测试(`cargo test -p ely-mail-engine`,含以真日志器在 trace 下跑三协议、日志里无密码、令牌与正文),真服务器未连。审查三轮:第 3 轮的两处(带引号的邮箱名、信头的 UTF-8)已修并以测试核对,未再审查(每条至多三轮)
|
||||
- [ ] C12.2 MIME(MAIL-04、05 的基础):mail-parser 读出头、纯文本、HTML、cid 内嵌图片、附件与原始头;mail-builder 写出多部分邮件、附件、Message-ID、In-Reply-To 与 References;样本 EML 往返测试
|
||||
- [ ] C12.3 本地存储(§12.3、§18.1、§18.3):SQLite 索引(账号、邮箱、消息身份为账号加邮箱加 UIDVALIDITY 加 UID、标记、头字段)、原文按内容存进内容目录、FTS5 全文索引(可重建)、结构版本与升级前备份、升级失败只读;各类大小可查
|
||||
- [ ] C12.4 凭据与 OAuth(MAIL-02,§18.2):密码与刷新令牌只进系统凭据库(不可用即只留到本次退出并写明);Gmail 与 Microsoft 的授权码加 PKCE、本机回环、换令牌与刷新;客户端 ID 编进构建,缺 ID 即写明不可用;刷新被拒转为“需重新登录”;替身授权端点测试
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
FAIL
|
||||
|
||||
1. `crates/ely-mail-engine/src/smtp.rs:70` — [P1] SMTP envelope addresses can inject additional commands. `from` and every `to` string reach mail-send's command formatting without validation. Passing one recipient, `bo@example.com>\r\nRCPT TO:<hidden@example.com`, transmits two separate `RCPT TO` commands. A scripted TLS server accepted both recipients and DATA, and `send` returned `Ok(())`, silently delivering to an extra envelope recipient. Reject invalid envelope mailbox syntax, including CR/LF, for the sender and all recipients before transmitting the transaction; add regression coverage for both inputs. Reproduced on Windows and Linux: `smtp_envelope_cannot_inject_an_additional_recipient`, `.work/c12.1-r1-probe.log` and `.work/c12.1-r1-linux-probe.log`.
|
||||
|
||||
2. `crates/ely-mail-engine/Cargo.toml:10` — [P1] The selected async-imap and async-pop dependencies emit credentials and complete fetched messages through the shared `log` facade at trace level. Neither the dependency configuration nor the engine suppresses or redacts those records. With trace enabled, successful TLS login and fetch recorded the literal IMAP password, POP3 `PASS` password, and both message bodies. The project's logger enables these targets with `ELY_LOG=trace`, violating agents.md's prohibition on credentials and content in logs. Remove or redact sensitive protocol tracing, or reliably exclude those records from logging, and test actual dependency logs rather than only the engine's own messages. Reproduced on both platforms: `trace_logs_exclude_password_token_and_message`, the two probe logs above.
|
||||
|
||||
3. `crates/ely-mail-engine/src/smtp.rs:62` — [P2] SMTP XOAUTH2 does not complete an authentication error challenge correctly. After the initial token, a server replying `334 <base64 JSON error>` receives the token again from mail-send's generic authentication loop. The required response is an empty line, after which the server supplies its final `535` refusal ([Gmail protocol](https://developers.google.com/workspace/gmail/imap/xoauth2-protocol#error_response_3)). The scripted server expecting that exchange instead observed the repeated token; `connect` returned a connection error and lost the final refusal. Implement the stateful XOAUTH2 error exchange for SMTP and preserve the final server reply. Existing SMTP tests cover password refusal and token success only. Reproduced on both platforms: `smtp_refused_oauth_answers_the_error_challenge_empty`, the two probe logs above.
|
||||
|
||||
4. `crates/ely-mail-engine/src/pop.rs:106` — [P2] POP3 XOAUTH2 stops handling challenges immediately after sending the token. If the server then returns a base64 error challenge, async-pop receives a challenge where it expects final success and returns `Protocol("Did not received the expected auith response")`; the engine never sends the empty response and never reads the server's final `-ERR` explanation. This loses the required credential refusal and server wording for the documented [XOAUTH2 error exchange](https://developers.google.com/workspace/gmail/imap/xoauth2-protocol#error_response). Complete the challenge/final-response exchange, preserving both successful authentication and the final rejection; add a token-refusal test. Reproduced on both platforms: `pop_refused_oauth_answers_the_error_challenge_empty`, the two probe logs above.
|
||||
|
||||
5. `crates/ely-mail-engine/src/pop.rs:32` — [P2] POP3 login can report success after swallowing a connection failure. Both async-pop authentication paths call `update_capabilities`, which discards every CAPA error. A TLS server that answers USER/PASS successfully and then closes after receiving the post-login CAPA causes `Pop::connect` to return `Ok(Pop)` and emit the successful-login log despite the failed operation and unusable connection. Surface transport and malformed-response errors from capability discovery; distinguish an explicitly handled unsupported CAPA reply from other failures. Cover the same behavior for password and OAuth authentication. Reproduced on both platforms: `pop_connection_loss_during_capabilities_is_an_error`, the two probe logs above.
|
||||
|
||||
6. `crates/ely-mail-engine/src/imap.rs:101` — [P2] The IMAP greeting is discarded without checking its response type or status. When a TLS server sends `* BYE [UNAVAILABLE] Maintenance in progress` and closes, the client treats the greeting as successful and attempts authentication. The returned error is an OS connection failure (Windows 10053 / Linux broken pipe), with the already-received maintenance explanation lost. This breaks C12.1's requirement to retain server wording on failure. Interpret the greeting, return BYE's reason immediately, and avoid authentication after a refusing greeting; add a greeting-refusal regression. Reproduced on both platforms: `imap_greeting_refusal_keeps_the_server_words`, the two probe logs above.
|
||||
@@ -0,0 +1,9 @@
|
||||
FAIL
|
||||
|
||||
1. `crates/ely-mail-engine/src/imap.rs:60` — [P2] IMAP command refusals become successful empty results. async-imap's LIST and FETCH streams discard the tagged completion without checking its status. A server replying to LIST with `NO [UNAVAILABLE] Mailbox listing temporarily unavailable` makes `mailboxes()` return `Ok([])`; replying to UID FETCH with `NO [UNAVAILABLE] Message store temporarily unavailable` makes `fetch()` return `Ok(None)`, falsely reporting a missing UID. Both lose the server's explanation and swallow an operation failure. Ensure the tagged completion is checked for NO/BAD before returning collected results, and cover refusals for both operations. Reproduced on Windows and Linux: `imap_list_refusal_is_an_error`, `imap_fetch_refusal_is_an_error`; `.work/c12.1-r2-probe.log`, `.work/c12.1-r2-linux-probe.log`.
|
||||
|
||||
2. `crates/ely-mail-engine/src/imap.rs:44` — [P2] BYE explanations are still discarded during authentication. The round 1 greeting scenario is fixed, but after a normal greeting, a server answering LOGIN with `* BYE [UNAVAILABLE] Too many simultaneous connections` and closing produces only `cannot connect: peer closed connection without sending TLS close_notify`. async-imap ignores the untagged BYE while waiting for a tagged completion. This still violates C12.1's requirement to preserve server wording on failure. Propagate BYE and its explanation through authentication and command response handling, rather than handling it only as the initial greeting; add regression coverage after authentication starts. Reproduced on both platforms: `imap_login_bye_keeps_server_words`, the two probe logs above.
|
||||
|
||||
3. `crates/ely-mail-engine/src/smtp.rs:131` — [P2] Envelope validation rejects valid quoted mailbox addresses. For example, sending to `"bo smith"@example.com` returns `Error::Invalid` before any transaction, so that recipient cannot receive mail through this engine. Spaces inside a quoted local part are permitted by [RFC 5321 §4.1.2](https://www.rfc-editor.org/rfc/rfc5321.html#section-4.1.2). Validate SMTP mailbox grammar with quoting awareness while retaining command-injection protection, and test valid quoted senders and recipients alongside the injection cases. Reproduced on both platforms: `smtp_accepts_a_quoted_local_part`, the two probe logs above.
|
||||
|
||||
4. `crates/ely-mail-engine/src/smtp.rs:82` — [P2] SMTP DATA omits dot stuffing on the first line. A valid message beginning with the optional header `.X-Trace: yes` is transmitted with that single initial period, whereas subsequent dot-prefixed lines are escaped. A conforming receiver removes the period and changes the header name: [RFC 5321 §4.5.2](https://www.rfc-editor.org/rfc/rfc5321.html#section-4.5.2) requires escaping each dot-prefixed line, and [RFC 5322 §3.6.8](https://www.rfc-editor.org/rfc/rfc5322.html#section-3.6.8) permits this header name. The selected mail-send writer only escapes dots following CR/LF. Correct the transparency handling at the first byte as well, and test the exact DATA bytes of a message starting with a period. Reproduced on both platforms: `smtp_stuffs_a_dot_in_the_first_data_line`, the two probe logs above.
|
||||
@@ -0,0 +1,5 @@
|
||||
FAIL
|
||||
|
||||
1. `crates/ely-mail-engine/src/imap.rs:68` — [P2] Quoted LIST mailbox names retain their wire escapes. imap-proto's quoted-string parser returns the escaped interior, so a server listing the folder `a"b` as `"a\"b"` makes `mailboxes()` return a name containing an extra backslash. Passing that returned name to `fetch()` escapes it again in EXAMINE and addresses a different folder, preventing retrieval from the listed folder. Backslashes are similarly doubled. Decode quoted-string escapes at the response boundary, preserving literal mailbox contents unchanged, and cover LIST-to-fetch round trips for both representations ([RFC 3501 string syntax](https://www.rfc-editor.org/rfc/rfc3501.html#section-9)). Reproduced on Windows and Linux: `imap_list_decodes_quoted_mailbox_names` and `imap_fetch_from_a_listed_quoted_mailbox_uses_its_name`; literal-name control passes. Evidence: `.work/c12.1-r3-windows-probe.log`, `.work/c12.1-r3-linux-probe.log`.
|
||||
|
||||
2. `crates/ely-mail-engine/src/smtp.rs:85` — [P2] SMTPUTF8 is checked only for envelope addresses, ignoring internationalized message headers. With ASCII sender and recipients but `Subject: 您好`, the engine omits SMTPUTF8 from MAIL even when advertised. When the server does not advertise it, the engine still transmits the UTF-8 header and can return `Ok(())`. This violates [RFC 6531 §3.2 and §3.4](https://www.rfc-editor.org/rfc/rfc6531.html#section-3.2) and can make otherwise supported internationalized messages fail submission or subsequent relay. Include the message's SMTPUTF8 requirement in the send contract and capability check, reject unsupported messages before MAIL, and add the parameter when required; test ASCII envelopes with UTF-8 headers against both capability responses. Reproduced on Windows and Linux: `smtp_utf8_header_requests_smtputf8_with_ascii_envelope` and `smtp_utf8_header_refused_without_smtputf8`; the two probe logs above.
|
||||
Reference in new issue
Block a user