add an example

This commit is contained in:
Quentin 2023-07-24 11:17:47 +02:00
parent 4ad0aad8be
commit e76cd78e4f
Signed by: quentin
GPG key ID: E9602264D639FF68
3 changed files with 25 additions and 18 deletions

View file

@ -6,8 +6,7 @@
## Example ## Example
```rust ```rust
let input = br#" let input = br#"Date: 7 Mar 2023 08:00:00 +0200
Date: 7 Mar 2023 08:00:00 +0200
From: deuxfleurs@example.com From: deuxfleurs@example.com
To: someone_else@example.com To: someone_else@example.com
Subject: An RFC 822 formatted message Subject: An RFC 822 formatted message
@ -15,10 +14,14 @@ MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii Content-Type: text/plain; charset=us-ascii
This is the plain text body of the message. Note the blank line 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(); 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 ## About the name

18
examples/simple.rs Normal file
View file

@ -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(),
);
}

View file

@ -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<T>>
{
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]> { 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) move |input| terminated(tag_no_case(name), tuple((space0, tag(b":"), space0)))(input)
} }