add a raw field to mime

This commit is contained in:
Quentin 2023-08-16 16:15:57 +02:00
parent 32ca628358
commit 8aa23ac5f2
Signed by: quentin
GPG Key ID: E9602264D639FF68
4 changed files with 17 additions and 4 deletions

2
Cargo.lock generated
View File

@ -70,7 +70,7 @@ checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa"
[[package]]
name = "eml-codec"
version = "0.1.0"
version = "0.1.2"
dependencies = [
"base64",
"chrono",

View File

@ -1,6 +1,6 @@
[package]
name = "eml-codec"
version = "0.1.1"
version = "0.1.2"
edition = "2021"
license = "GPL-3.0-or-later"
repository = "https://git.deuxfleurs.fr/Deuxfleurs/eml-codec"

View File

@ -63,6 +63,7 @@ pub struct NaiveMIME<'a> {
pub description: Option<Unstructured<'a>>,
pub header_ext: Vec<header::Kv<'a>>,
pub header_bad: Vec<&'a [u8]>,
pub raw: &'a [u8],
}
impl<'a> FromIterator<Content<'a>> for NaiveMIME<'a> {
@ -89,6 +90,9 @@ impl<'a> NaiveMIME<'a> {
pub fn with_bad(mut self, bad: Vec<&'a [u8]>) -> Self {
self.header_bad = bad; self
}
pub fn with_raw(mut self, raw: &'a [u8]) -> Self {
self.raw = raw; self
}
pub fn to_interpreted<T: WithDefaultType>(self) -> AnyMIME<'a> {
self.ctype.as_ref().map(|c| c.to_type()).unwrap_or(T::default_type()).to_mime(self).into()
}

View File

@ -74,7 +74,16 @@ pub fn multipart<'a>(
// parse mime headers, otherwise pick default mime
let (input, naive_mime) = match header(mime::field::content)(input) {
Ok((input, (known, unknown, bad))) => (input, known.into_iter().collect::<mime::NaiveMIME>().with_opt(unknown).with_bad(bad)),
Ok((input_eom, (known, unknown, bad))) => {
let raw_hdrs = pointers::parsed(input, input_eom);
let mime = known
.into_iter()
.collect::<mime::NaiveMIME>()
.with_opt(unknown)
.with_bad(bad)
.with_raw(raw_hdrs);
(input_eom, mime)
},
Err(_) => (input, mime::NaiveMIME::default()),
};
@ -132,7 +141,7 @@ pub fn message<'a>(
let imf = imf.with_opt(unknown).with_bad(bad);
// interpret headers to choose a mime type
let in_mime = naive_mime.to_interpreted::<mime::WithGenericDefault>().into();
let in_mime = naive_mime.with_raw(raw_headers).to_interpreted::<mime::WithGenericDefault>().into();
// parse this mimetype
let (input, part) = part::anypart(in_mime)(input)?;