From e76cd78e4f0f487b61b14dab97c1fccb71278d10 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Mon, 24 Jul 2023 11:17:47 +0200 Subject: [PATCH] add an example --- README.md | 11 +++++++---- examples/simple.rs | 18 ++++++++++++++++++ src/header.rs | 14 -------------- 3 files changed, 25 insertions(+), 18 deletions(-) create mode 100644 examples/simple.rs diff --git a/README.md b/README.md index 775e7f7..001b433 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,7 @@ ## Example ```rust -let input = br#" -Date: 7 Mar 2023 08:00:00 +0200 +let input = br#"Date: 7 Mar 2023 08:00:00 +0200 From: deuxfleurs@example.com To: someone_else@example.com Subject: An RFC 822 formatted message @@ -15,10 +14,14 @@ MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii This is the plain text body of the message. Note the blank line -between the header information and the body of the message.#; +between the header information and the body of the message."#; let email = eml_codec::email(input).unwrap(); -println!("{} just sent you an email with subject \"{}\", email.1. +println!( + "{} just sent you an email with subject \"{}\"", + email.1.from[0].to_string(), + email.1.subject.unwrap().to_string(), +); ``` ## About the name diff --git a/examples/simple.rs b/examples/simple.rs new file mode 100644 index 0000000..9886d8f --- /dev/null +++ b/examples/simple.rs @@ -0,0 +1,18 @@ +pub fn main() { + let input = br#"Date: 7 Mar 2023 08:00:00 +0200 +From: deuxfleurs@example.com +To: someone_else@example.com +Subject: An RFC 822 formatted message +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii + +This is the plain text body of the message. Note the blank line +between the header information and the body of the message."#; + + let email = eml_codec::email(input).unwrap(); + println!( + "{} just sent you an email with subject \"{}\"", + email.1.from[0].to_string(), + email.1.subject.unwrap().to_string(), + ); +} diff --git a/src/header.rs b/src/header.rs index bc82efd..b5fe4cd 100644 --- a/src/header.rs +++ b/src/header.rs @@ -49,20 +49,6 @@ pub fn header<'a, T>( } } -/* -pub fn header_in_boundaries<'a, T>(bound: &'a [u8], fx: impl Fn(&'a [u8]) -> IResult<&[u8], T> + Copy) - -> impl Fn(&'a [u8]) -> IResult<&[u8], CompFieldList> -{ - move |input| map(terminated(many0(preceded( - not(boundary(bound)), - alt(( - map(fx, CompField::Known), - map(opt_field, |(k,v)| CompField::Unknown(k,v)), - map(foldable_line, CompField::Bad), - )))), obs_crlf), CompFieldList)(input) -} -*/ - pub fn field_name<'a>(name: &'static [u8]) -> impl Fn(&'a [u8]) -> IResult<&'a [u8], &'a [u8]> { move |input| terminated(tag_no_case(name), tuple((space0, tag(b":"), space0)))(input) }