1
0
Fork
You've already forked indymilterbroken
0
Asynchronous milter library for Rust
This repository has been archived on 2024年06月13日. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
Rust 97.9%
C 1.5%
Lua 0.6%
2024年02月06日 08:25:08 +01:00
examples New Listener trait and API 2024年02月06日 08:25:08 +01:00
src New Listener trait and API 2024年02月06日 08:25:08 +01:00
tests Formatting 2023年12月22日 19:36:29 +01:00
.gitignore Add libmilter test, improve internal errors 2021年12月27日 17:07:31 +01:00
.gitlab-ci.yml Initial commit 2021年10月17日 21:01:39 +02:00
Cargo.lock indymilter 0.3.0-alpha.1 2024年01月12日 16:31:03 +01:00
Cargo.toml indymilter 0.3.0-alpha.1 2024年01月12日 16:31:03 +01:00
CHANGELOG.md New Listener trait and API 2024年02月06日 08:25:08 +01:00
LICENSE Initial commit 2021年10月17日 21:01:39 +02:00
README.md New Listener trait and API 2024年02月06日 08:25:08 +01:00

indymilter

independent async milter library for Rust

  • pure, safe Rust library for writing milters
  • asynchronous implementation based on Tokio
  • no dependency on libmilter C library
  • fully compatible with existing milter-aware MTAs

The indymilter library provides facilities for creating milters in pure asynchronous Rust. A milter is a mail filtering application that can be integrated with MTAs (mail servers) such as Postfix.

The main advantage of indymilter over similar libraries is its wholehearted adoption of the asynchronous paradigm, which enables virtually unlimited concurrency. An arbitrary number of MTA connections can be handled concurrently by a small number of threads. Internally, the library is based on Tokio.

This library is an implementation of the milter side of the sendmail milter protocol. As such, it assumes the place of the libmilter C library distributed with sendmail. It has no dependency on that library but is a stand-alone, pure, safe (no unsafe) Rust product.

As libmilter is the standard implementation of the venerable milter protocol, indymilter mimics its behaviour accurately. In order to guarantee perfect compatibility with existing MTAs, indymilter aims for bug-for-bug compatibility rather than a fancy ‘modern’ reimagining of the protocol. Questions about the indymilter source code can be answered by looking at the libmilter source.

Usage

To use indymilter, add it as a dependency in Cargo.toml. Further usage information can be found in the following places:

For an overview of the protocol design and detailed API functionality, see the original sendmail milter API documentation. This documentation can be found in the sendmail package of your distro (for example, on Debian and Ubuntu at /usr/share/doc/sendmail-doc/libmilter/html/index.html), or directly in the sendmail source tarball at ftp://ftp.sendmail.org/pub/sendmail.

The above is important: While indymilter provides an API similar to libmilter, it does not duplicate documentation for the entire API. For details you will need to check the sendmail docs.

Example

Here is a simple but complete milter program that logs client IP addresses:

useindymilter::{Callbacks,Context,SocketInfo,Status};usetokio::{net::TcpListener,signal};#[tokio::main]asyncfn main(){letlistener=TcpListener::bind("127.0.0.1:3000").await.expect("cannot open milter socket");letcallbacks=Callbacks::new().on_connect(|context,_,socket_info|{Box::pin(handle_connect(context,socket_info))});letconfig=Default::default();indymilter::run(listener,callbacks,config,signal::ctrl_c()).await.expect("milter execution failed");}asyncfn handle_connect(_: &mutContext<()>,socket_info: SocketInfo,)-> Status{ifletSocketInfo::Inet(addr)=socket_info{println!("connect from {}",addr.ip());}Status::Continue}

The above milter will try to open a TCP socket at port 3000, and will then process incoming MTA connections until it is shut down with Control-C.

Licence

Copyright © 2021–2024 David Bürgin

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.