diff --git a/README.md b/README.md index 10e8ff3..d38d109 100644 --- a/README.md +++ b/README.md @@ -101,11 +101,16 @@ Todo: | 🔴 |2047 | ↳ MIME (Multipurpose Internet Mail Extensions) Part Three: Message Header Extensions for Non-ASCII Text | | 🔴 |2048 | ↳ Multipurpose Internet Mail Extensions (MIME) Part Four: Registration Procedures | | 🔴 |2049 | ↳ Multipurpose Internet Mail Extensions (MIME) Part Five: Conformance Criteria and Examples | -| 🔴 |2183 | Communicating Presentation Information in Internet Messages: The Content-Disposition Header Field | -| 🔴 |3462 | The Multipart/Report Content Type for the Reporting of Mail System Administrative Messages | -| 🔴 |3798 | Message Disposition Notification | -| 🟩 |6532 | Internationalized Email Headers | -| 🔴 |9228 | Delivered-To Email Header Field | +| | | **Headers extensions** | +| 🔴 |2183 | ↳ Communicating Presentation Information in Internet Messages: The Content-Disposition Header Field | +| 🟩 |6532 | ↳ Internationalized Email Headers | +| 🔴 |9228 | ↳ Delivered-To Email Header Field | +| | | **MIME extensions** | +| 🔴 |1847 | ↳ Security Multiparts for MIME: Multipart/Signed and Multipart/Encrypted | +| 🔴 |2387 | ↳ The MIME Multipart/Related Content-type | +| 🔴 |3462 | ↳ The Multipart/Report Content Type for the Reporting of Mail System Administrative Messages | +| 🔴 |3798 | ↳ Message Disposition Notification | +| 🔴 |6838 | ↳ Media Type Specifications and Registration Procedures | IANA references : - (tbd) MIME subtypes diff --git a/src/error.rs b/src/error.rs index 34b5405..35fdedc 100644 --- a/src/error.rs +++ b/src/error.rs @@ -17,4 +17,5 @@ pub enum IMFError<'a> { ReceivedLog(nom::Err>), Version(nom::Err>), ContentType(nom::Err>), + Mechanism(nom::Err>), } diff --git a/src/fragments/mime.rs b/src/fragments/mime.rs index b454b75..0004e4b 100644 --- a/src/fragments/mime.rs +++ b/src/fragments/mime.rs @@ -238,7 +238,9 @@ impl<'a> TryFrom<&'a lazy::Mechanism<'a>> for Mechanism<'a> { type Error = IMFError<'a>; fn try_from(mc: &'a lazy::Mechanism<'a>) -> Result { - Ok(Mechanism::Other("")) + mechanism(mc.0) + .map(|(_, v)| v) + .map_err(|e| IMFError::Mechanism(e)) } } @@ -385,6 +387,22 @@ pub fn content_type(input: &str) -> IResult<&str, Type> { Ok((rest, parsed)) } +pub fn mechanism(input: &str) -> IResult<&str, Mechanism> { + use Mechanism::*; + + let (input, mecha) = token(input)?; + let parsed = match mecha.to_lowercase().as_ref() { + "7bit" => _7Bit, + "8bit" => _8Bit, + "binary" => Binary, + "quoted-printable" => QuotedPrintable, + "base64" => Base64, + _ => Other(mecha), + }; + + Ok((input, parsed)) +} + #[cfg(test)] mod tests { use super::*; @@ -491,6 +509,33 @@ mod tests { parameter("charset=us-ascii (Plain text)"), Ok(("", Parameter::Charset(EmailCharset::US_ASCII))) ); + } + #[test] + fn test_mechanism() { + assert_eq!( + Mechanism::try_from(&lazy::Mechanism("7bit")), + Ok(Mechanism::_7Bit), + ); + + assert_eq!( + Mechanism::try_from(&lazy::Mechanism("(youhou) 8bit")), + Ok(Mechanism::_8Bit), + ); + + assert_eq!( + Mechanism::try_from(&lazy::Mechanism("(blip) bInArY (blip blip)")), + Ok(Mechanism::Binary), + ); + + assert_eq!( + Mechanism::try_from(&lazy::Mechanism(" base64 ")), + Ok(Mechanism::Base64), + ); + + assert_eq!( + Mechanism::try_from(&lazy::Mechanism(" Quoted-Printable ")), + Ok(Mechanism::QuotedPrintable), + ); } }