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 --- Cargo.lock | 2 +- src/lmtp.rs | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b197677..c37165a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -28,7 +28,7 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "aerogramme" -version = "0.2.0" +version = "0.2.1" dependencies = [ "anyhow", "argon2", 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