diff --git a/src/core/header.rs b/src/core/header.rs index 54e9c49..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 { @@ -764,6 +769,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,