Struct milter::Milter [−][src]
pub struct Milter { /* fields omitted */ }
Expand description
A configurable milter runner.
Milter
is used to configure and run a milter implementation. It is
instantiated with Milter::new
and a mandatory listening socket. The
milter can then be configured with a name, a selection of callbacks that
provide the functionality of the milter, and the actions that the milter
wants to take. Finally, a call to run
starts the milter.
A limitation to be aware of is that while Milter
appears to expose a
tidily encapsulated fluent builder API, Milter
must essentially be used
like a singleton. No more than one milter can be configured and run in a
single process. (This limitation is due to the design of the underlying
libmilter library, which is based on a paradigm of global state.)
Examples
The following shows the simplest possible, no-op milter.
use milter::Milter;
Milter::new("unix:/run/noopmilter.sock").run().expect("milter execution failed");
More typically, a milter is configured with a name, some callbacks, and the desired actions before being started:
Milter::new("inet:3333@localhost")
.name("MyMilter")
.on_eom(eom_callback)
.actions(Actions::ADD_HEADER)
.run()
.expect("milter execution failed");
Implementations
Creates a new milter that will listen on the given socket.
The socket
specification needs to be in one of the following formats:
inet:port@host
– an IPv4 socketinet6:port@host
– an IPv6 socket
whereport
is a numeric port, andhost
can be either a hostname or an IP address{unix|local}:path
– a UNIX domain socket at an absolute file systempath
UNIX domain socket files are created using the user and umask of the milter process.
While Milter
is responsible for creation and deletion of UNIX domain
sockets, it is possible that a socket file survives an abnormal
termination. See Milter::remove_socket
for an option that may help
address this.
Panics
Panics if socket
contains a zero byte.
Examples
let mut milter = Milter::new("inet:3000@localhost");
Sets the callback to use for this milter’s negotiate
stage.
Use the on_negotiate
attribute macro to generate the callback
function.
Sets the callback to use for this milter’s connect
stage.
Use the on_connect
attribute macro to generate the callback
function.
Sets the callback to use for this milter’s helo
stage.
Use the on_helo
attribute macro to generate the callback function.
Sets the callback to use for this milter’s mail
stage.
Use the on_mail
attribute macro to generate the callback function.
Sets the callback to use for this milter’s rcpt
stage.
Use the on_rcpt
attribute macro to generate the callback function.
Sets the callback to use for this milter’s data
stage.
Use the on_data
attribute macro to generate the callback function.
Sets the callback to use for this milter’s header
stage.
Use the on_header
attribute macro to generate the callback function.
Sets the callback to use for this milter’s eoh
(end-of-header) stage.
Use the on_eoh
attribute macro to generate the callback function.
Sets the callback to use for this milter’s body
stage.
Use the on_body
attribute macro to generate the callback function.
Sets the callback to use for this milter’s eom
(end-of-message) stage.
Use the on_eom
attribute macro to generate the callback function.
Sets the callback to use for this milter’s abort
stage.
Use the on_abort
attribute macro to generate the callback function.
Sets the callback to use for this milter’s close
stage.
Use the on_close
attribute macro to generate the callback function.
Sets the callback to use for this milter’s unknown
stage.
Use the on_unknown
attribute macro to generate the callback
function.
Enables the given actions for this milter.
Actions represented as methods on ContextApi
need to be enabled with
this method (or during negotiation) before they can be used.
Configures the time until the connection to the MTA times out.
Panics
Panics if the duration is outside the acceptable range.
Configures the socket backlog, that is, the maximum number of incoming connections to queue up.
Panics
Panics if the given length is outside the acceptable range.
Configures whether to force removal of any existing UNIX domain socket
at the location given in Milter::new
during startup.
While a Milter
normally manages creation and deletion of socket files
itself, a socket file may survive an abnormal termination; enabling this
option may help clear out leftover files when (re-)starting.
Registers this milter’s configuration with the libmilter library and
starts the milter. This is a blocking call, run
only returns when the
milter is shut down.
Important: Not more than one milter may be configured and run at a time.
Errors
Only when calling run
is this milter’s configuration applied. This can
fail for a variety of reasons encoded in the error result.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Milter
impl UnwindSafe for Milter
Blanket Implementations
Mutably borrows from an owned value. Read more