mirror of
https://github.com/chatmail/relay.git
synced 2026-09-13 02:43:15 +00:00
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.
This commit is contained in:
@@ -198,7 +198,7 @@ impl DkimVerifier {
|
|||||||
/// Verifies the DKIM signature of a raw email message and its alignment with the provided
|
/// Verifies the DKIM signature of a raw email message and its alignment with the provided
|
||||||
/// domain.
|
/// domain.
|
||||||
pub async fn verify(&self, raw_mail: &[u8], from_domain: &str) -> Result<(), String> {
|
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
|
let (header, body) = mail_data
|
||||||
.split_once("\r\n\r\n")
|
.split_once("\r\n\r\n")
|
||||||
.ok_or("554 Malformed data")?;
|
.ok_or("554 Malformed data")?;
|
||||||
|
|||||||
Reference in New Issue
Block a user