diff --git a/src/message/mimebody.rs b/src/message/mimebody.rs index a78f7b0..c511269 100644 --- a/src/message/mimebody.rs +++ b/src/message/mimebody.rs @@ -17,6 +17,15 @@ pub(super) enum Part { Multi(MultiPart), } +impl Part { + pub(super) fn body_raw(&self) -> Vec { + match self { + Part::Single(part) => part.body_raw(), + Part::Multi(part) => part.body_raw(), + } + } +} + impl EmailFormat for Part { fn format(&self, out: &mut Vec) { match self { @@ -132,6 +141,13 @@ impl SinglePart { self.format(&mut out); out } + + pub(super) fn body_raw(&self) -> Vec { + let mut out = Vec::new(); + out.extend_from_slice(&self.body); + out.extend_from_slice(b"\r\n"); + out + } } impl EmailFormat for SinglePart { @@ -373,6 +389,24 @@ impl MultiPart { self.format(&mut out); out } + + pub(super) fn body_raw(&self) -> Vec { + let mut out = Vec::new(); + + let boundary = self.boundary(); + + for part in &self.parts { + out.extend_from_slice(b"--"); + out.extend_from_slice(boundary.as_bytes()); + out.extend_from_slice(b"\r\n"); + part.format(&mut out); + } + + out.extend_from_slice(b"--"); + out.extend_from_slice(boundary.as_bytes()); + out.extend_from_slice(b"--\r\n"); + out + } } impl EmailFormat for MultiPart { diff --git a/src/message/mod.rs b/src/message/mod.rs index 6ba9912..414f4ca 100644 --- a/src/message/mod.rs +++ b/src/message/mod.rs @@ -525,7 +525,7 @@ impl Message { pub(crate) fn body_raw(&self) -> Vec { let mut out = Vec::new(); match &self.body { - MessageBody::Mime(p) => p.format(&mut out), + MessageBody::Mime(p) => out = p.body_raw(), MessageBody::Raw(r) => out.extend_from_slice(r), }; out.extend_from_slice(b"\r\n");