aboutsummaryrefslogtreecommitdiff
path: root/src/imap/mime_view.rs
diff options
context:
space:
mode:
authorQuentin Dufour <quentin@deuxfleurs.fr>2024-01-06 22:53:41 +0100
committerQuentin Dufour <quentin@deuxfleurs.fr>2024-01-06 22:53:41 +0100
commit5622a71cd163e4b18a3eabe8a28a5aedb23ee25d (patch)
tree43f3b4c560da80890844353da62e6629acb761cc /src/imap/mime_view.rs
parent73fc5e77df9db756af64135aaa08bb0242b13371 (diff)
downloadaerogramme-5622a71cd163e4b18a3eabe8a28a5aedb23ee25d.tar.gz
aerogramme-5622a71cd163e4b18a3eabe8a28a5aedb23ee25d.zip
Search MIME headers
Diffstat (limited to 'src/imap/mime_view.rs')
-rw-r--r--src/imap/mime_view.rs29
1 files changed, 24 insertions, 5 deletions
diff --git a/src/imap/mime_view.rs b/src/imap/mime_view.rs
index 5175c76..cf6c751 100644
--- a/src/imap/mime_view.rs
+++ b/src/imap/mime_view.rs
@@ -164,8 +164,23 @@ impl<'a> SubsettedSection<'a> {
/// Used for current MIME inspection
///
/// See NodeMime for recursive logic
-struct SelectedMime<'a>(&'a AnyPart<'a>);
+pub struct SelectedMime<'a>(pub &'a AnyPart<'a>);
impl<'a> SelectedMime<'a> {
+ pub fn header_value(&'a self, to_match_ext: &[u8]) -> Option<&'a [u8]> {
+ let to_match = to_match_ext.to_ascii_lowercase();
+
+ self.eml_mime()
+ .kv
+ .iter()
+ .filter_map(|field| match field {
+ header::Field::Good(header::Kv2(k, v)) => Some((k, v)),
+ _ => None,
+ })
+ .find(|(k, _)| k.to_ascii_lowercase() == to_match)
+ .map(|(_, v)| v)
+ .copied()
+ }
+
/// The subsetted fetch section basically tells us the
/// extraction logic to apply on our selected MIME.
/// This function acts as a router for these logic.
@@ -200,6 +215,13 @@ impl<'a> SelectedMime<'a> {
Ok(ExtractedFull(bytes.to_vec().into()))
}
+ fn eml_mime(&self) -> &eml_codec::mime::NaiveMIME<'_> {
+ match &self.0 {
+ AnyPart::Msg(msg) => msg.child.mime(),
+ other => other.mime(),
+ }
+ }
+
/// The [...] HEADER.FIELDS, and HEADER.FIELDS.NOT part
/// specifiers refer to the [RFC-2822] header of the message or of
/// an encapsulated [MIME-IMT] MESSAGE/RFC822 message.
@@ -231,10 +253,7 @@ impl<'a> SelectedMime<'a> {
.collect::<HashSet<_>>();
// Extract MIME headers
- let mime = match &self.0 {
- AnyPart::Msg(msg) => msg.child.mime(),
- other => other.mime(),
- };
+ let mime = self.eml_mime();
// Filter our MIME headers based on the field index
// 1. Keep only the correctly formatted headers