feat(NODE-1955): Add SMTP library & server#87
Merged
Conversation
frankdavid
reviewed
May 18, 2026
frankdavid
approved these changes
May 19, 2026
There was a problem hiding this comment.
Pull request overview
Introduces an SMTP library and a small testing SMTP server binary, refactors common networking code (listeners, TLS handshake, async byte-counter) out of the http module into a new network module, and adds Candid types for talking to canisters over an IC SMTP protocol.
Changes:
- Extract shared network primitives (
Listener,listen_tcp,listen_unix,tls_handshake,AsyncCounter,AsyncReadWrite) intosrc/network/. - Add
src/smtp/with an inbound SMTP session state machine (EHLO/HELO, MAIL FROM with SPF/iprev, RCPT TO with resolver policies, DATA/BDAT, STARTTLS), session manager, andServer. - Add IC SMTP Candid types under
src/smtp/ic/candid.rsand atools/smtp-servertest binary; pull inmail-auth,mail-parser,smtp-protoworkspace deps.
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| Cargo.toml | Adds mail-auth, mail-parser, smtp-proto to the workspace. |
| ic-bn-lib/Cargo.toml | Adds SMTP-related deps, tokio-test, tracing-subscriber, and the smtp-server binary target. |
| ic-bn-lib/src/lib.rs | Exposes network and smtp modules; allows collapsible_if. |
| ic-bn-lib/src/http/mod.rs | Moves AsyncReadWrite/AsyncCounter to network. |
| ic-bn-lib/src/http/server/mod.rs | Switches to shared Listener/tls_handshake from network. |
| ic-bn-lib/src/network/mod.rs | New module with tls_handshake, AsyncCounter, AsyncReadWrite. |
| ic-bn-lib/src/network/listener.rs | Generic TCP/Unix listener moved here. |
| ic-bn-lib/src/smtp/mod.rs | Core SMTP types (Message, traits, dummies, errors). |
| ic-bn-lib/src/smtp/address.rs | EmailAddress parsing/formatting. |
| ic-bn-lib/src/smtp/server.rs | TCP listener loop spawning sessions. |
| ic-bn-lib/src/smtp/inbound/mod.rs | Session config/state/data + tests. |
| ic-bn-lib/src/smtp/inbound/session.rs | Session state machine and IO loop. |
| ic-bn-lib/src/smtp/inbound/ehlo.rs | EHLO/HELO handling. |
| ic-bn-lib/src/smtp/inbound/mail_from.rs | MAIL FROM handling with optional iprev/SPF. |
| ic-bn-lib/src/smtp/inbound/rcpt_to.rs | RCPT TO handling with resolver policies. |
| ic-bn-lib/src/smtp/inbound/manager.rs | Session lifetime + STARTTLS upgrade. |
| ic-bn-lib/src/smtp/ic/mod.rs, candid.rs | IC SMTP Candid types. |
| ic-bn-lib/tools/smtp_server.rs | Test binary running the SMTP server. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| pub(crate) async fn message_too_big(&mut self) -> SessionResult<()> { | ||
| let msg = format!( | ||
| "Message too big for, we accept up to {} bytes.", |
| "Message too big for, we accept up to {} bytes.", | ||
| self.cfg.max_message_size | ||
| ); | ||
| return self.reply("552", "5.3.4", &msg).await; |
| if let Some(v) = output.explanation() { | ||
| write!(msg, ": {v}.").ok(); | ||
| } | ||
| write!(msg, "\r\n").ok(); |
| let rustls_server_cfg = ServerConfig::builder() | ||
| .with_no_client_auth() | ||
| .with_cert_resolver(Arc::new( | ||
| StubResolver::new(TEST_CERT_1.as_bytes(), TEST_KEY_2.as_bytes()).unwrap(), |
|
|
||
| use crate::{ | ||
| network::listener::listen_tcp, | ||
| smtp::inbound::{SessionConfig, SessionError, SessionResult, manager::SessionManager}, |
| @@ -0,0 +1,34 @@ | |||
| use std::{net::SocketAddr, str::FromStr, sync::Arc, time::Duration}; | |||
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.
networkmoduleMore work will follow to glue SMTP to the IC