Trait Handler

Source
pub trait Handler {
    // Provided methods
    fn helo(&mut self, _ip: IpAddr, _domain: &str) -> Response { ... }
    fn mail(&mut self, _ip: IpAddr, _domain: &str, _from: &str) -> Response { ... }
    fn rcpt(&mut self, _to: &str) -> Response { ... }
    fn data_start(
        &mut self,
        _domain: &str,
        _from: &str,
        _is8bit: bool,
        _to: &[String],
    ) -> Response { ... }
    fn data(&mut self, _buf: &[u8]) -> Result<(), Error> { ... }
    fn data_end(&mut self) -> Response { ... }
    fn auth_plain(
        &mut self,
        _authorization_id: &str,
        _authentication_id: &str,
        _password: &str,
    ) -> Response { ... }
    fn auth_login(&mut self, _username: &str, _password: &str) -> Response { ... }
}
Expand description

A Handler makes decisions about incoming mail commands.

A Handler implementation must be provided by code using the mailin library.

All methods have a default implementation that does nothing. A separate handler instance should be created for each connection.

§Examples


impl Handler for MyHandler {
    fn helo(&mut self, ip: IpAddr, domain: &str) -> Response {
       if domain == "this.is.spam.com" {
           OK
       } else {
           BAD_HELLO
       }
    }

    fn rcpt(&mut self, to: &str) -> Response {
       if to == "alienscience" {
           OK
       } else {
           NO_MAILBOX
       }
    }
}

Provided Methods§

Source

fn helo(&mut self, _ip: IpAddr, _domain: &str) -> Response

Called when a client sends a ehlo or helo message

Source

fn mail(&mut self, _ip: IpAddr, _domain: &str, _from: &str) -> Response

Called when a mail message is started

Source

fn rcpt(&mut self, _to: &str) -> Response

Called when a mail recipient is set

Source

fn data_start( &mut self, _domain: &str, _from: &str, _is8bit: bool, _to: &[String], ) -> Response

Called when a data command is received

Source

fn data(&mut self, _buf: &[u8]) -> Result<(), Error>

Called when a data buffer is received

Source

fn data_end(&mut self) -> Response

Called at the end of receiving data

Source

fn auth_plain( &mut self, _authorization_id: &str, _authentication_id: &str, _password: &str, ) -> Response

Called when a plain authentication request is received

Source

fn auth_login(&mut self, _username: &str, _password: &str) -> Response

Called when a login authentication request is received

Implementors§