From 7320b5f3c7cbb0d393b04e36df014932acbd2bd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaume=20Delcl=C3=B2s=20Coll?= Date: Wed, 19 Nov 2025 15:58:34 +0100 Subject: [PATCH 1/2] expose binary version of attachment body --- src/core/header.rs | 1 + src/lib.rs | 1 + src/parsers/message.rs | 5 +++++ 3 files changed, 7 insertions(+) diff --git a/src/core/header.rs b/src/core/header.rs index 54e9c49..86bee3c 100644 --- a/src/core/header.rs +++ b/src/core/header.rs @@ -764,6 +764,7 @@ impl<'x> MessagePart<'x> { PartType::Message(v) => PartType::Message(v.into_owned()), PartType::Multipart(v) => PartType::Multipart(v), }, + raw_body: self.raw_body.into_owned().into(), encoding: self.encoding, offset_header: self.offset_header, offset_body: self.offset_body, diff --git a/src/lib.rs b/src/lib.rs index ea84deb..4c19664 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -61,6 +61,7 @@ pub struct MessagePart<'x> { #[cfg_attr(feature = "serde", serde(default))] //#[cfg_attr(feature = "rkyv", rkyv(omit_bounds))] pub body: PartType<'x>, + pub raw_body: Cow<'x, [u8]>, #[cfg_attr(feature = "serde", serde(skip))] pub encoding: Encoding, pub offset_header: u32, diff --git a/src/parsers/message.rs b/src/parsers/message.rs index 4ff25f9..9aa1035 100644 --- a/src/parsers/message.rs +++ b/src/parsers/message.rs @@ -182,6 +182,7 @@ impl MessageParser { is_encoding_problem: false, encoding: Encoding::None, body: PartType::default(), + raw_body: vec![].into(), }); state_stack.push((state, None)); state = new_state; @@ -229,6 +230,7 @@ impl MessageParser { offset_body: state.offset_body as u32, offset_end: 0, body: PartType::default(), // Temp value, will be replaced later. + raw_body: vec![].into(), }); state_stack.push((state, message.into())); message = Message::new(); @@ -262,6 +264,7 @@ impl MessageParser { } else { state.offset_end = offset_end; } + let raw_body = bytes.clone(); let body_part = if mime_type != MimeType::Message { let is_inline = is_inline @@ -382,6 +385,7 @@ impl MessageParser { encoding, is_encoding_problem, body: body_part, + raw_body: raw_body, offset_header: state.offset_header as u32, offset_body: state.offset_body as u32, offset_end: state.offset_end as u32, @@ -523,6 +527,7 @@ impl MessageParser { encoding: Encoding::None, is_encoding_problem: true, body: PartType::Text("".into()), + raw_body: vec![].into(), offset_header: 0, offset_body: message.raw_message.len() as u32, offset_end: message.raw_message.len() as u32, From 838b5745904eda78dee2492714dde8812c474324 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaume=20Delcl=C3=B2s=20Coll?= Date: Wed, 19 Nov 2025 17:50:32 +0100 Subject: [PATCH 2/2] getter method --- src/core/header.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/core/header.rs b/src/core/header.rs index 86bee3c..64e67fb 100644 --- a/src/core/header.rs +++ b/src/core/header.rs @@ -751,6 +751,11 @@ impl<'x> MessagePart<'x> { self.offset_end } + /// Get the raw body bytes of this part + pub fn raw_body(&self) -> &[u8] { + self.raw_body.as_ref() + } + /// Returns an owned version of the this part pub fn into_owned(self) -> MessagePart<'static> { MessagePart {