cargo clippy suggestions

This commit is contained in:
Gonne 2024-11-28 16:38:09 +01:00
parent 1ec2267ce1
commit ab9a6f0d32

View file

@ -50,7 +50,7 @@ fn main() {
println!("{}", generate_sieve_script(parse_alias_to_map(alias_files)));
}
/// Read a virtual alias file (http://www.postfix.org/virtual.5.html)
/// Read a virtual alias file <https://www.postfix.org/virtual.5.html>
/// and convert it to a map of destination addresses to a list of their final forwarding addresses.
fn parse_alias_to_map(alias_files: Vec<AliasFile>) -> AliasMap {
// File must exist in the current path
@ -74,7 +74,7 @@ fn parse_alias_to_map(alias_files: Vec<AliasFile>) -> AliasMap {
.split_at(line.find(char::is_whitespace).unwrap_or(0))
.1
.split(' ')
.filter(|address| address.trim().to_string().replace(',', "") != "")
.filter(|address| !address.trim().to_string().replace(',', "").is_empty())
.map(|addr| to_mailaddress(addr, &alias_file.default_domain))
.collect();
@ -116,16 +116,14 @@ fn parse_alias_to_map(alias_files: Vec<AliasFile>) -> AliasMap {
*redirect_map.get_mut(&destination).unwrap() = new_redirect;
}
}
if iterations == max_iterations {
panic!("Possibly infinite recursion detected in parse_alias_map. Did not terminate after {max_iterations} rounds.");
}
assert!(iterations != max_iterations, "Possibly infinite recursion detected in parse_alias_map. Did not terminate after {max_iterations} rounds.");
redirect_map
}
/// Generate a Sieve script (https://en.wikipedia.org/wiki/Sieve_(mail_filtering_language))
/// Generate a Sieve script <https://en.wikipedia.org/wiki/Sieve_(mail_filtering_language)>
/// from a map of destination addresses to a list of their forwarding addresses.
///
/// Addresses are sorted according to the order on OrdEmailAddress.
/// Addresses are sorted according to the order on `OrdEmailAddress`.
fn generate_sieve_script(redirects: AliasMap) -> String {
let mut script: String = "require [\"envelope\", \"copy\"];\n\n".to_string();
for (redirect, mut destinations) in redirects {
@ -147,7 +145,7 @@ fn generate_sieve_script(redirects: AliasMap) -> String {
script
}
/// Create an OrdEmailAddress from some alias entry.
/// Create an `OrdEmailAddress` from some alias entry.
/// Return parameter for complete mail addresses and append the default domain for local parts.
fn to_mailaddress(alias_entry: &str, default_domain: &FQDN) -> OrdEmailAddress {
let mut addr = alias_entry.trim().to_string();