opensmtpd-filter-dkimout/src/main.rs

47 lines
986 B
Rust
Raw Normal View History

2023-03-19 19:06:29 +01:00
mod entry;
2023-03-19 17:13:49 +01:00
mod handshake;
2023-03-19 20:32:11 +01:00
mod message;
2023-03-19 19:29:02 +01:00
mod stdin_reader;
2023-03-19 17:13:49 +01:00
2023-03-19 19:06:29 +01:00
use entry::Entry;
2023-03-19 20:32:11 +01:00
use message::Message;
use std::collections::HashMap;
2023-03-19 19:29:02 +01:00
use stdin_reader::StdinReader;
2023-03-19 19:06:29 +01:00
const DEFAULT_BUFF_SIZE: usize = 1024;
2023-03-19 14:59:32 +01:00
fn main() {
2023-03-19 19:29:02 +01:00
let mut reader = StdinReader::new();
2023-03-19 20:32:11 +01:00
let mut messages: HashMap<String, Message> = HashMap::new();
2023-03-19 19:29:02 +01:00
handshake::read_config(&mut reader);
2023-03-19 17:13:49 +01:00
handshake::register_filter();
2023-03-19 19:06:29 +01:00
loop {
2023-03-19 19:29:02 +01:00
match Entry::from_bytes(&reader.read_line()) {
2023-03-19 19:06:29 +01:00
Ok(entry) => {
2023-03-19 20:32:11 +01:00
let msg_id = entry.get_msg_id();
match messages.get_mut(&msg_id) {
Some(msg) => {
if !entry.is_end_of_message() {
msg.append_line(entry.get_data());
} else {
msg.sign_and_return();
messages.remove(&msg_id);
}
}
None => {
2023-03-19 21:42:36 +01:00
let msg = Message::from_entry(&entry);
2023-03-19 20:32:11 +01:00
if !entry.is_end_of_message() {
messages.insert(msg_id, msg);
} else {
msg.sign_and_return();
}
}
2023-03-19 19:06:29 +01:00
}
}
Err(err) => {
eprintln!("{err}");
}
}
}
}