[−][src]Struct milter::Milter
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
milter library, which relies heavily on global state.)
Examples
The following shows the simplest possible, no-op milter.
use milter::Milter; Milter::new("unix:/run/noopmilter.sock").run().expect("could not run milter");
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("could not run milter");
Methods
impl Milter
[src]
pub fn new(socket: &str) -> Self
[src]
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
Panics
Panics if socket
contains a zero byte.
Examples
let mut milter = Milter::new("inet:3000@localhost");
pub fn name(&mut self, name: &str) -> &mut Self
[src]
pub fn on_negotiate(&mut self, callback: NegotiateCallback) -> &mut Self
[src]
Sets the callback to use for this milter’s negotiate
stage.
Use the on_negotiate
attribute macro to generate the callback
function.
pub fn on_connect(&mut self, callback: ConnectCallback) -> &mut Self
[src]
Sets the callback to use for this milter’s connect
stage.
Use the on_connect
attribute macro to generate the callback
function.
pub fn on_helo(&mut self, callback: HeloCallback) -> &mut Self
[src]
Sets the callback to use for this milter’s helo
stage.
Use the on_helo
attribute macro to generate the callback function.
pub fn on_mail(&mut self, callback: MailCallback) -> &mut Self
[src]
Sets the callback to use for this milter’s mail
stage.
Use the on_mail
attribute macro to generate the callback function.
pub fn on_rcpt(&mut self, callback: RcptCallback) -> &mut Self
[src]
Sets the callback to use for this milter’s rcpt
stage.
Use the on_rcpt
attribute macro to generate the callback function.
pub fn on_data(&mut self, callback: DataCallback) -> &mut Self
[src]
Sets the callback to use for this milter’s data
stage.
Use the on_data
attribute macro to generate the callback function.
pub fn on_header(&mut self, callback: HeaderCallback) -> &mut Self
[src]
Sets the callback to use for this milter’s header
stage.
Use the on_header
attribute macro to generate the callback function.
pub fn on_eoh(&mut self, callback: EohCallback) -> &mut Self
[src]
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.
pub fn on_body(&mut self, callback: BodyCallback) -> &mut Self
[src]
Sets the callback to use for this milter’s body
stage.
Use the on_body
attribute macro to generate the callback function.
pub fn on_eom(&mut self, callback: EomCallback) -> &mut Self
[src]
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.
pub fn on_abort(&mut self, callback: AbortCallback) -> &mut Self
[src]
Sets the callback to use for this milter’s abort
stage.
Use the on_abort
attribute macro to generate the callback function.
pub fn on_close(&mut self, callback: CloseCallback) -> &mut Self
[src]
Sets the callback to use for this milter’s close
stage.
Use the on_close
attribute macro to generate the callback function.
pub fn on_unknown(&mut self, callback: UnknownCallback) -> &mut Self
[src]
Sets the callback to use for this milter’s unknown
stage.
Use the on_unknown
attribute macro to generate the callback
function.
pub fn actions(&mut self, actions: Actions) -> &mut Self
[src]
Enables the given actions for this milter.
Actions represented as methods on ActionContext
need to be enabled
with this method before they can be used.
pub fn timeout(&mut self, duration: Duration) -> &mut Self
[src]
Configures the time until the connection to the MTA times out.
pub fn socket_backlog(&mut self, len: u32) -> &mut Self
[src]
Configures the socket backlog, that is the maximum number of incoming connections to queue up.
pub fn run(&mut self) -> Result<()>
[src]
Starts this milter. This is a blocking call, it only returns when the milter is shut down.
If the start is successful, this freezes this milter’s configuration.
Repeated calls to run
are allowed, but will not see changes to the
configuration options (the underlying registration procedure for this
milter is done only once).
Not more than one milter must be (configured and) run at a time!
Errors
Only when calling run
, this milter’s configuration is applied. This
can fail for a variety of reasons encoded in the error result type.
Trait Implementations
Auto Trait Implementations
impl Send for Milter
impl Sync for Milter
impl Unpin for Milter
impl UnwindSafe for Milter
impl RefUnwindSafe for Milter
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,