Parse the end of the header section

This commit is contained in:
Quentin 2023-06-08 21:58:24 +02:00
parent 10c5968676
commit a7824e9657
Signed by: quentin
GPG key ID: E9602264D639FF68
2 changed files with 7 additions and 4 deletions

View file

@ -10,7 +10,7 @@ use nom::{
sequence::tuple,
};
use crate::abnf::{fws, vchar_seq};
use crate::abnf::{fws, vchar_seq, perm_crlf};
use crate::model::HeaderSection;
/// HEADERS
@ -19,7 +19,7 @@ use crate::model::HeaderSection;
///
/// See: https://www.rfc-editor.org/rfc/rfc5322.html#section-2.2
pub fn header_section(input: &str) -> IResult<&str, HeaderSection> {
fold_many0(
let (input, headers) = fold_many0(
header_field,
HeaderSection::default,
|mut section, head| {
@ -34,7 +34,10 @@ pub fn header_section(input: &str) -> IResult<&str, HeaderSection> {
};
section
}
)(input)
)(input)?;
let (input, _) = perm_crlf(input)?;
Ok((input, headers))
}
enum HeaderField<'a> {

View file

@ -1,6 +1,6 @@
use imf_codec::headers;
fn main() {
let header = "Subject: Hello\r\n World\r\nFrom: <quentin@deuxfleurs.fr>\r\n\r\n";
let header = "Subject: Hello\r\n World\r\nFrom: <quentin@deuxfleurs.fr>\r\n\r\nHello world";
println!("{:?}", headers::header_section(header));
}