From 0e3cfe536f111c1094d530aed0581390e3fbc878 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Sat, 10 Feb 2024 12:11:01 +0100 Subject: Escape LMTP data --- src/lmtp.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/lmtp.rs b/src/lmtp.rs index f88ed8f..28c4d51 100644 --- a/src/lmtp.rs +++ b/src/lmtp.rs @@ -16,7 +16,7 @@ use tokio::select; use tokio::sync::watch; use tokio_util::compat::*; -use smtp_message::{Email, EscapedDataReader, Reply, ReplyCode}; +use smtp_message::{Email, EscapedDataReader, DataUnescaper, Reply, ReplyCode}; use smtp_server::{reply, Config, ConnectionMetadata, Decision, MailMetadata}; use crate::config::*; @@ -181,6 +181,12 @@ impl Config for LmtpServer { return err_response_stream(meta, format!("io error: {}", e)); } reader.complete(); + let raw_size = text.len(); + + // Unescape email, shrink it also to remove last dot + let unesc_res = DataUnescaper::new(true).unescape(&mut text); + text.truncate(unesc_res.written); + tracing::debug!(prev_sz=raw_size, new_sz=text.len(), "unescaped"); let encrypted_message = match EncryptedMessage::new(text) { Ok(x) => Arc::new(x), -- cgit v1.2.3