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/report_counter.rs

27 lines
578 B
Rust
Raw Normal View History

use log;
use opensmtpd::entry::Entry;
use opensmtpd::{register_contexts, report, simple_filter};
#[derive(Clone, Default)]
struct MyCounter {
nb: usize,
}
register_contexts!(MyCounter, MyCounter);
#[report(v1, smtp_in, match(all))]
fn on_report(entry: &Entry, total: &mut MyCounter, session: &mut MyCounter) {
total.nb += 1;
session.nb += 1;
log::info!(
"Event received for session {}: {} (total: {})",
entry.get_session_id(),
session.nb,
total.nb
);
}
fn main() {
simple_filter!(MyCounter, MyCounter, [on_report]);
}