Antispam sieve script draft

This commit is contained in:
mdecimus
2023-09-12 19:37:14 +02:00
parent 8bceb49fb7
commit ab65fa877b
17 changed files with 2018 additions and 182 deletions

View File

@@ -21,6 +21,7 @@
* for more details.
*/
use core::panic;
use std::{sync::Arc, time::Duration};
use ahash::AHashMap;
@@ -343,6 +344,31 @@ impl SMTP {
}
}
// Assert global variables
#[cfg(feature = "test_mode")]
if let Some(expected_variables) = params.expected_variables {
for var_name in instance.global_variable_names() {
if !expected_variables.contains_key(var_name) {
panic!(
"Unexpected variable {var_name:?} with value {:?}\nExpected {:?}\nFound: {:?}",
instance.global_variable(var_name).unwrap(),
expected_variables.keys().collect::<Vec<_>>(),
instance.global_variable_names().collect::<Vec<_>>()
);
}
}
for (name, expected) in &expected_variables {
if let Some(value) = instance.global_variable(name.as_str()) {
assert_eq!(value, expected, "Variable {name:?} has unexpected value");
} else {
panic!("Missing variable {name:?} with value {expected:?}\nExpected {:?}\nFound: {:?}",
expected_variables.keys().collect::<Vec<_>>(),
instance.global_variable_names().collect::<Vec<_>>());
}
}
}
// Keep id
// 0 = use original message
// MAX = implicit keep