use jiff::Zoned;
use mailparse::parse_headers;
pub const MAX_RECEIVED_COUNT: u8 = 30;
pub fn count_received(body: &[u8]) -> u8 {
let Ok((headers, _)) = parse_headers(body) else {
return 0;
};
headers
.iter()
.filter(|h| h.get_key_ref().eq_ignore_ascii_case("Received"))
.count()
.try_into()
.unwrap_or(u8::MAX)
}
pub fn add_received(body: &mut Vec<u8>, from: &str, by: &str) {
let now = Zoned::now().strftime("%a, %d %b %Y %H:%M:%S %z");
let header = format!("Received: from {from} by {by}; {now}\r\n");
body.splice(0..0, header.bytes());
}