This repository has been archived on 2023-09-20. You can view files and clone it, but cannot push or open issues or pull requests.
rust-opensmtpd/opensmtpd/examples/dummy.rs
Rodolphe Breard 789455668c Use procedural macros to define events
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.
2019-01-06 15:41:30 +01:00

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();
}