add a raw field to mime #22

Merged
quentin merged 1 commit from better_access_to_bytes into main 2023-08-16 14:18:52 +00:00
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)?;