forked from Fachschaft/nixConfig
Redirect for all incoming recipients as a copy and discard original incoming mail
This way it is not saved in the catch-all account.
This commit is contained in:
parent
281642aa38
commit
51416950e6
1 changed files with 21 additions and 4 deletions
|
@ -134,24 +134,41 @@ where
|
||||||
/// Addresses are sorted according to the order on `OrdEmailAddress`.
|
/// Addresses are sorted according to the order on `OrdEmailAddress`.
|
||||||
pub fn generate_sieve_script(redirects: AliasMap) -> String {
|
pub fn generate_sieve_script(redirects: AliasMap) -> String {
|
||||||
let mut script: String =
|
let mut script: String =
|
||||||
"require [\"variables\", \"copy\", \"vnd.stalwart.expressions\", \"envelope\"];\n\n"
|
"require [\"variables\", \"copy\", \"vnd.stalwart.expressions\", \"envelope\"];
|
||||||
.to_string();
|
|
||||||
|
let \"i\" \"0\";
|
||||||
|
while \"i < count(envelope.to)\" {
|
||||||
|
let \"redirected\" \"false\";
|
||||||
|
"
|
||||||
|
.to_string();
|
||||||
for (redirect, mut destinations) in redirects {
|
for (redirect, mut destinations) in redirects {
|
||||||
script += format!(
|
script += format!(
|
||||||
// inspired by https://github.com/stalwartlabs/mail-server/issues/916#issuecomment-2474844389
|
// 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,
|
redirect.0,
|
||||||
{
|
{
|
||||||
let mut subscript: String = String::new();
|
let mut subscript: String = String::new();
|
||||||
destinations.sort();
|
destinations.sort();
|
||||||
for destination in destinations.iter() {
|
for destination in destinations.iter() {
|
||||||
subscript += format!(" redirect :copy \"{}\";\n", destination.0).as_str();
|
subscript += format!(" redirect :copy \"{}\";", destination.0).as_str();
|
||||||
}
|
}
|
||||||
subscript
|
subscript
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.as_str();
|
.as_str();
|
||||||
}
|
}
|
||||||
|
script += " if eval \"!redirected\" {
|
||||||
|
let \"destination\" \"envelope.to[i]\";
|
||||||
|
redirect :copy \"${destination}\";
|
||||||
|
}
|
||||||
|
";
|
||||||
|
script += " let \"i\" \"i+1\";\n";
|
||||||
|
script += "}
|
||||||
|
discard;";
|
||||||
script
|
script
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue