diff --git a/Cargo.lock b/Cargo.lock index 10a78bd..15bdbeb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -70,7 +70,7 @@ checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" [[package]] name = "eml-codec" -version = "0.1.0" +version = "0.1.2" dependencies = [ "base64", "chrono", diff --git a/Cargo.toml b/Cargo.toml index 72effc0..fa23bf4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/mime/mod.rs b/src/mime/mod.rs index 5d049c4..2dd0c21 100644 --- a/src/mime/mod.rs +++ b/src/mime/mod.rs @@ -63,6 +63,7 @@ pub struct NaiveMIME<'a> { pub description: Option>, pub header_ext: Vec>, pub header_bad: Vec<&'a [u8]>, + pub raw: &'a [u8], } impl<'a> FromIterator> 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(self) -> AnyMIME<'a> { self.ctype.as_ref().map(|c| c.to_type()).unwrap_or(T::default_type()).to_mime(self).into() } diff --git a/src/part/composite.rs b/src/part/composite.rs index 12c3dd1..dc2ac68 100644 --- a/src/part/composite.rs +++ b/src/part/composite.rs @@ -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::().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::() + .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::().into(); + let in_mime = naive_mime.with_raw(raw_headers).to_interpreted::().into(); // parse this mimetype let (input, part) = part::anypart(in_mime)(input)?;