added alias-to-sieve to this repository #69

Merged
nerf merged 23 commits from nerf/nixConfig:sieve-script into main 2025-03-27 09:32:50 +00:00
Showing only changes of commit 51416950e6 - Show all commits

View file

@ -134,24 +134,41 @@ where
/// Addresses are sorted according to the order on `OrdEmailAddress`.
pub fn generate_sieve_script(redirects: AliasMap) -> String {
let mut script: String =
"require [\"variables\", \"copy\", \"vnd.stalwart.expressions\", \"envelope\"];\n\n"
.to_string();
"require [\"variables\", \"copy\", \"vnd.stalwart.expressions\", \"envelope\"];
let \"i\" \"0\";
while \"i < count(envelope.to)\" {
let \"redirected\" \"false\";
"
.to_string();
for (redirect, mut destinations) in redirects {
script += format!(
// inspired by https://github.com/stalwartlabs/mail-server/issues/916#issuecomment-2474844389
"if eval \"contains_ignore_case(envelope.to, '{}')\" {{\n{}}}\n",
" if eval \"eq_ignore_case(envelope.to[i], '{}')\" {{
{}
let \"redirected\" \"true\";
}}
",
redirect.0,
{
let mut subscript: String = String::new();
destinations.sort();
for destination in destinations.iter() {
subscript += format!(" redirect :copy \"{}\";\n", destination.0).as_str();
subscript += format!(" redirect :copy \"{}\";", destination.0).as_str();
}
subscript
}
)
.as_str();
}
script += " if eval \"!redirected\" {
let \"destination\" \"envelope.to[i]\";
redirect :copy \"${destination}\";
}
";
script += " let \"i\" \"i+1\";\n";
script += "}
discard;";
script
}