From 2529b0145e4c1d7f6cd6090abcfd2521689d9848 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Wed, 30 Aug 2023 19:48:23 +0200 Subject: [PATCH] fixed tests! --- src/imf/mod.rs | 8 ++++++++ src/part/composite.rs | 27 +++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/imf/mod.rs b/src/imf/mod.rs index bd7e24a..32eb925 100644 --- a/src/imf/mod.rs +++ b/src/imf/mod.rs @@ -55,6 +55,14 @@ pub struct Imf<'a> { // MIME pub mime_version: Option, + + // Raw fields + pub kv: Vec>, +} +impl<'a> Imf<'a> { + pub fn with_kv(mut self, v: Vec>) -> Self { + self.kv = v; self + } } //@FIXME min and max limits are not enforced, diff --git a/src/part/composite.rs b/src/part/composite.rs index b2bb754..f1bae97 100644 --- a/src/part/composite.rs +++ b/src/part/composite.rs @@ -164,8 +164,11 @@ pub fn message<'a>( // aggregate header fields let (naive_mime, imf) = part::field::split_and_build(&headers); + // Bind headers to the IMF object + let imf = imf.with_kv(headers); + // interpret headers to choose a mime type - let in_mime = naive_mime.with_kv(headers).with_raw(raw_headers).to_interpreted::().into(); + let in_mime = naive_mime.with_raw(raw_headers).to_interpreted::().into(); //--------------- // parse a part following this mime specification @@ -487,6 +490,19 @@ OoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoO
right: &b"www.grrrndzero.org"[..], }), mime_version: Some(imf::mime::Version { major: 1, minor: 0}), + kv: vec![ + header::Field::Good(header::Kv2(&b"Date"[..], &b"Sat, 8 Jul 2023 07:14:29 +0200"[..])), + header::Field::Good(header::Kv2(&b"From"[..], &b"Grrrnd Zero "[..])), + header::Field::Good(header::Kv2(&b"To"[..], &b"John Doe "[..])), + header::Field::Good(header::Kv2(&b"CC"[..], &b"=?ISO-8859-1?Q?Andr=E9?= Pirard "[..])), + header::Field::Good(header::Kv2(&b"Subject"[..], &b"=?ISO-8859-1?B?SWYgeW91IGNhbiByZWFkIHRoaXMgeW8=?=\n =?ISO-8859-2?B?dSB1bmRlcnN0YW5kIHRoZSBleGFtcGxlLg==?="[..])), + header::Field::Good(header::Kv2(&b"X-Unknown"[..], &b"something something"[..])), + header::Field::Bad(&b"Bad entry\n on multiple lines\n"[..]), + header::Field::Good(header::Kv2(&b"Message-ID"[..], &b""[..])), + header::Field::Good(header::Kv2(&b"MIME-Version"[..], &b"1.0"[..])), + header::Field::Good(header::Kv2(&b"Content-Type"[..], &b"multipart/alternative;\n boundary=\"b1_e376dc71bafc953c0b0fdeb9983a9956\""[..])), + header::Field::Good(header::Kv2(&b"Content-Transfer-Encoding"[..], &b"7bit"[..])), + ], ..imf::Imf::default() }, child: Box::new(AnyPart::Mult(Multipart { @@ -531,6 +547,10 @@ OoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoO
] }), transfer_encoding: mime::mechanism::Mechanism::QuotedPrintable, + kv: vec![ + header::Field::Good(header::Kv2(&b"Content-Type"[..], &b"text/plain; charset=utf-8"[..])), + header::Field::Good(header::Kv2(&b"Content-Transfer-Encoding"[..], &b"quoted-printable"[..])), + ], raw: &b"Content-Type: text/plain; charset=utf-8\nContent-Transfer-Encoding: quoted-printable\n\n"[..], ..mime::NaiveMIME::default() } @@ -554,7 +574,10 @@ OoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoO
value: MIMEWord::Atom(&b"us-ascii"[..]), } ] - }), + }), + kv: vec![ + header::Field::Good(header::Kv2(&b"Content-Type"[..], &b"text/html; charset=us-ascii"[..])), + ], raw: &b"Content-Type: text/html; charset=us-ascii\n\n"[..], ..mime::NaiveMIME::default() },