Loop through all recipients
This commit is contained in:
parent
c37b6ec865
commit
0e5cb1c3ee
1 changed files with 16 additions and 16 deletions
32
src/lib.rs
32
src/lib.rs
|
@ -133,27 +133,26 @@ 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 = "require [\"envelope\", \"copy\"];\n\n".to_string();
|
let mut script: String = "require [\"variables\", \"copy\", \"vnd.stalwart.expressions\"];\n\n".to_string();
|
||||||
for (redirect, mut destinations) in redirects {
|
for (redirect, mut destinations) in redirects {
|
||||||
script += format!("if envelope :is \"to\" \"{}\" {{\n{}}}\n", redirect.0, {
|
script += format!(
|
||||||
let mut subscript: String = String::new();
|
"if eval \"contains(recipients, '{}')\" {{\n{}}}\n",
|
||||||
destinations.sort();
|
redirect.0,
|
||||||
for destination in destinations.iter().rev().skip(1).rev() {
|
{
|
||||||
subscript += format!(" redirect :copy \"{}\";\n", destination.0).as_str();
|
let mut subscript: String = String::new();
|
||||||
|
destinations.sort();
|
||||||
|
for destination in destinations.iter() {
|
||||||
|
subscript += format!(" redirect :copy \"{}\";\n", destination.0).as_str();
|
||||||
|
}
|
||||||
|
subscript
|
||||||
}
|
}
|
||||||
subscript
|
)
|
||||||
+ format!(
|
|
||||||
" redirect \"{}\";\n",
|
|
||||||
destinations.iter().next_back().unwrap().0
|
|
||||||
)
|
|
||||||
.as_str()
|
|
||||||
})
|
|
||||||
.as_str();
|
.as_str();
|
||||||
}
|
}
|
||||||
|
script += "discard;";
|
||||||
script
|
script
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -173,11 +172,12 @@ mod tests {
|
||||||
let result = parse_alias_to_map(vec![AliasFile {
|
let result = parse_alias_to_map(vec![AliasFile {
|
||||||
content: read_lines("testdata/simple.aliases").unwrap(),
|
content: read_lines("testdata/simple.aliases").unwrap(),
|
||||||
default_domain: FQDN::from_str("example.com").unwrap(),
|
default_domain: FQDN::from_str("example.com").unwrap(),
|
||||||
}]).unwrap();
|
}])
|
||||||
|
.unwrap();
|
||||||
assert_eq!(result.len(), 4);
|
assert_eq!(result.len(), 4);
|
||||||
|
|
||||||
for redirects in result.iter() {
|
for redirects in result.iter() {
|
||||||
assert_eq!(redirects.1[0].0.to_string(), "me@example.org");
|
assert_eq!(redirects.1[0].0.to_string(), "me@example.org");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue