From 8b69586c1f372fe8492cf628cad28af0c2a958db Mon Sep 17 00:00:00 2001 From: Zaz Brown Date: Sun, 4 May 2025 14:04:36 +0000 Subject: [PATCH] add Message::all_parts, leaf_parts, other_parts --- src/core/message.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/core/message.rs b/src/core/message.rs index 7d8e94ec..68ee80c4 100644 --- a/src/core/message.rs +++ b/src/core/message.rs @@ -458,6 +458,29 @@ impl<'x> Message<'x> { AttachmentIterator::new(self) } +/// Returns all parts of the email. +pub fn all_parts(&self) -> impl Iterator> + '_ { + (0..).map(move |id| self.part(id)) + .take_while(|part| part.is_some()) + .filter_map(move |part| part) +} + +/// Returns all parts of the email that are not Multipart. +pub fn leaf_parts(&self) -> impl Iterator> + '_ { + self.all_parts().filter(|part| !part.is_multipart()) +} + +/// Returns all parts of the email that are not Multipart, attachments, or HTML +/// or text body parts. +pub fn other_parts(&self) -> impl Iterator> + '_ { + let this = self; + self.leaf_parts().filter(move |part| { + !this.attachments().any(|attachment| part == &attachment) && + !this.html_bodies().any(|html_body_part| part == &html_body_part) && + !this.text_bodies().any(|text_body_part| part == &text_body_part) + }) +} + /// Returns an owned version of the message pub fn into_owned(self) -> Message<'static> { Message {