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/rm_x-originating-ip.rs

28 lines
678 B
Rust
Raw Normal View History

2020-12-21 15:28:19 +01:00
use opensmtpd::{return_data_line, run_filter, Filter, FilterEntry};
use opensmtpd_derive::register;
pub const HEADER_NAME: &str = "x-originating-ip:";
pub const HEADER_LEN: usize = 17;
struct RmXOriginatingIp {}
impl Filter for RmXOriginatingIp {
2021-02-28 13:56:40 +01:00
#[register]
fn on_filter_data_line(&mut self, entry: &FilterEntry, data_line: &[u8]) {
if data_line.len() >= HEADER_LEN {
let head_start = data_line[..HEADER_LEN].to_vec();
if let Ok(s) = String::from_utf8(head_start) {
if s.to_lowercase() == HEADER_NAME {
return;
}
}
}
return_data_line(entry, data_line);
}
2020-12-21 15:28:19 +01:00
}
fn main() {
2021-02-28 13:56:40 +01:00
let mut my_filter = RmXOriginatingIp {};
run_filter(&mut my_filter);
2020-12-21 15:28:19 +01:00
}