milter-callback 0.1.3

Attribute macros for milter callback generation
milter-callback-0.1.3 doesn't have any documentation.

Procedural macros to generate C callback functions for use in milter implementation.

The attribute macros in this crate facilitate the creation of FFI callback functions that are required for the configuration of a Milter. The attribute macros are used to annotate ordinary Rust functions as milter callbacks. A C function is then generated that delegates to the Rust callback, safely, and taking care of conversion between Rust/C types.

Callback functions serve the purpose of event handlers (hence the nomenclature on_*) for the various ‘events’ that happen during an SMTP conversation. For each of the stages in the milter protocol there is a corresponding attribute macro.


This crate is a dependency of the milter crate, which re-exports all macros under its namespace. Thus you should not need to use this crate directly.

Note that with Rust 2018 there are two ways of importing procedural macros. Nowadays, macros can be imported like other symbols:

use milter::{on_connect, on_close, Milter, Status};

That does require you to list all macros in the use statement, though. The older syntax with extern crate lets you import all macros without listing them explicitly:

#[macro_use] extern crate milter;

use milter::{Milter, Status};

Both notations are acceptable.

Callback results

The result type of a callback function may be wrapped in a milter::Result where desired. This is a convenience: as most Context methods return milter::Results these can then be unwrapped with the ? operator.

For example, the end-of-message handler may return plain Status:

# #[macro_use] extern crate milter_callback;
# use milter::{ActionContext, Status};
fn handle_eom(context: ActionContext<()>) -> Status {

Or it may return milter::Result<Status>. The example shows the use of the ? operator enabled by choosing this return type.

# #[macro_use] extern crate milter_callback;
# use milter::{ActionContext, Status};
fn handle_eom(context: ActionContext<()>) -> milter::Result<Status> {
if let Some(version) = context.macro_value("v")? {
println!("{}", version);


This feature is supported on all the callback functions.

Failure modes

An Err result returned from a callback leads to a temporary failure (Status::Tempfail) response being returned to the MTA. The milter then continues to handle requests normally.

Panicking, on the other hand, leads to immediate shutdown of the milter. All stages switch to returning a failure response and no longer execute the handler functions (however, currently executing callback handlers are allowed to finish). The milter library worker processes are terminated and the currently blocked invocation of Milter::run returns. Cleanup logic in the close or other stages is not executed.

The principle behind the panicking behaviour is, as elsewhere, exit as quickly as possible, within the constraints posed by the milter library and the FFI interface.

The above failure modes are provided as a convenience. Use explicit error handling if they don’t satisfy your requirements.