From 94f1b299170554db741e2a45ec45bbae7aced063 Mon Sep 17 00:00:00 2001 From: l Date: Thu, 19 Feb 2026 18:06:08 +0000 Subject: [PATCH] refactor: do not copy the mail in memory for DKIM verification (#54) `String::from_utf8_lossy` always copies the data for the case when it needs to replace invalid UTF-8, but we don't want invalid UTF-8 anyway as replacing invalid UTF-8 characters will break DKIM signature. --- filtermail/src/dkim_verifier.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/filtermail/src/dkim_verifier.rs b/filtermail/src/dkim_verifier.rs index f61b9746..d7fd03a6 100644 --- a/filtermail/src/dkim_verifier.rs +++ b/filtermail/src/dkim_verifier.rs @@ -198,7 +198,7 @@ impl DkimVerifier { /// Verifies the DKIM signature of a raw email message and its alignment with the provided /// domain. pub async fn verify(&self, raw_mail: &[u8], from_domain: &str) -> Result<(), String> { - let mail_data = String::from_utf8_lossy(raw_mail); + let mail_data = str::from_utf8(raw_mail).or(Err("554 Non-UTF-8 message"))?; let (header, body) = mail_data .split_once("\r\n\r\n") .ok_or("554 Malformed data")?;