Polish the code

- Reject user ids containing ANSI control characters when creating a new
  signing key.
- Prevent adding certificates twice when querying online sources if they
  contain multiple encryption keys.
- Dedup introducers if there are multiple authenticating paths.
- When listing locals, skip the signing key.
- Check if a mail can be encrypted at all due to available certificates.
  If not tell the MTA that the processing is done.
- Make `Introducer` comparable (`PartialEq`, `Eq` and `Hash`).
- minor polishing
This commit is contained in:
Malte Meiboom
2026-07-24 13:41:07 +02:00
parent 0b1969e75b
commit 8de999411d
15 changed files with 233 additions and 51 deletions
+14 -12
View File
@@ -19,19 +19,20 @@ use crate::types::errors::HuskError;
use crate::types::recipient::Recipient;
/// Parse the user id fields from a string.
pub fn to_userid(rcpt: &CString) -> Option<UserID> {
match rcpt.to_str() {
Ok(s) => Some(UserID::from(s)),
_ => None
}
pub fn to_userid(rcpt: &CString) -> Result<UserID> {
let rcpt = rcpt.to_str()?;
Ok(UserID::from(rcpt))
}
/// Get the email from the string representation of a user id.
pub fn to_email(rcpt: &CString) -> Option<String> {
if let Some(u) = to_userid(rcpt) {
if let Ok(Some(e)) = u.email() { Some(e.to_string()) }
else { None }
} else { None }
pub fn to_email(rcpt: &CString) -> Result<String> {
let u = to_userid(rcpt)?;
if let Some(e) = u.email()? {
Ok(e.to_string())
} else {
Err(HuskError::CannotConvertToEmail(u.to_string()).into())
}
}
/// Checks if the parameter has a valid email format.
@@ -78,7 +79,7 @@ pub async fn smtp_inject(from: String, to: &Vec<Recipient<'_>>, header: CHeader,
// convert addresses
let from_email = CString::new(from.clone())?;
let from_email = to_email(&from_email).unwrap(); // XXX
let from_email = to_email(&from_email)?;
let from_email: Address = from_email.try_into()?;
let mut rcpts: Vec<Address> = Vec::new();
@@ -87,7 +88,8 @@ pub async fn smtp_inject(from: String, to: &Vec<Recipient<'_>>, header: CHeader,
rcpts.push(rcpt.try_into()?);
}
let my_id = ClientId::Domain(defaults::HELO_REINJECT_ID.to_owned()); // TODO: add secret token?
// XXX: add secret token?
let my_id = ClientId::Domain(defaults::HELO_REINJECT_ID.to_owned());
joinset.spawn(async move {
// XXX