13 个版本
| 0.6.4 | 2024 年 2 月 10 日 |
|---|---|
| 0.6.3 | 2023 年 5 月 20 日 |
| 0.6.2 | 2023 年 4 月 13 日 |
| 0.6.1 | 2022 年 6 月 6 日 |
| 0.1.2 | 2018 年 12 月 28 日 |
#108 in 邮件
980 每月下载量
用于 5 个 Crates(3 个直接使用)
66KB
1.5K SLoC
Mailin
这是一个用于在 Rust 中编写 SMTP 服务器的库。该库处理解析、SMTP 状态机和构建响应。
使用 Mailin 库的程序负责所有 IO,包括打开套接字和存储消息。Mailin 通过调用实现 Handler 特质的对象上的方法,使 SMTP 会话的生命周期可用。
lib.rs:
用于构建 smtp 服务器的库。
该库提供解析器和 SMTP 状态机。库的用户提供 I/O 代码和用于控制 SMTP 会话的 Handler 实现代码。
使用该库的代码将接收到的行发送到 Session.process_line() 方法。用户还提供了一个 Handler 实现来决定是否接受或拒绝电子邮件消息。在咨询 Handler 之后,Session.process_line() 函数将返回一个可以发送回电子邮件客户端的响应。
伪代码
// Create a handler which will control the SMTP session
let hander = create_handler();
// Create a SMTP session when a new client connects
let session = SessionBuilder::new("mailserver_name").build(client_ip, handler);
// Read a line from the client
let line = read_line(tcp_connection);
// Send the line to the session
let res = session.process(line);
// Act on the response
match res.action {
Action::Reply => {
write_response(tcp_connection, &res)?;
}
Action::Close => {
write_response(tcp_connection, &res)?;
close(tcp_connection);
}
Action::NoReply => (), // No response needed
}
依赖项
~1.5MB
~26K SLoC