789455668c
The construction of an EventHandler object should not be directly done by the client. Instead, it is easier to use procedural macro to automatize the process, hence exposing a nice and simple interface. Such use of procedural macros requires to crate an additional crate.
22 lines
537 B
Rust
22 lines
537 B
Rust
use env_logger::{Builder, Env};
|
|
use log::{debug, info};
|
|
use opensmtpd::{event, handlers, Entry, EventHandler, SmtpIn};
|
|
|
|
#[event(Any)]
|
|
fn on_event(entry: &Entry) -> bool {
|
|
debug!("Event received: {:?}", entry);
|
|
true
|
|
}
|
|
|
|
#[event(LinkConnect)]
|
|
fn on_connect(entry: &Entry) -> bool {
|
|
info!("New client on session {:x}.", entry.session_id);
|
|
true
|
|
}
|
|
|
|
fn main() {
|
|
Builder::from_env(Env::default().default_filter_or("debug")).init();
|
|
SmtpIn::new()
|
|
.event_handlers(handlers!(on_event, on_connect))
|
|
.run();
|
|
}
|