mime header fields

This commit is contained in:
Quentin 2023-07-04 15:50:45 +02:00
parent 766eef71c7
commit 9b5ceafa5d
Signed by: quentin
GPG key ID: E9602264D639FF68
3 changed files with 57 additions and 6 deletions

View file

@ -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

View file

@ -17,4 +17,5 @@ pub enum IMFError<'a> {
ReceivedLog(nom::Err<nom::error::Error<&'a str>>),
Version(nom::Err<nom::error::Error<&'a str>>),
ContentType(nom::Err<nom::error::Error<&'a str>>),
Mechanism(nom::Err<nom::error::Error<&'a str>>),
}

View file

@ -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<Self, Self::Error> {
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),
);
}
}