Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/core/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions src/parsers/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down