implement sender
This commit is contained in:
parent
d46c5895f5
commit
61a9772e6b
2 changed files with 42 additions and 10 deletions
|
@ -4,7 +4,6 @@ use nom::{
|
||||||
bytes::complete::take_while1,
|
bytes::complete::take_while1,
|
||||||
bytes::complete::tag,
|
bytes::complete::tag,
|
||||||
character::complete::space0,
|
character::complete::space0,
|
||||||
character::complete::crlf,
|
|
||||||
combinator::opt,
|
combinator::opt,
|
||||||
multi::fold_many0,
|
multi::fold_many0,
|
||||||
multi::many0,
|
multi::many0,
|
||||||
|
@ -15,6 +14,7 @@ use crate::whitespace::{fws, perm_crlf};
|
||||||
use crate::words::vchar_seq;
|
use crate::words::vchar_seq;
|
||||||
use crate::misc_token::unstructured;
|
use crate::misc_token::unstructured;
|
||||||
use crate::model::{PermissiveHeaderSection, HeaderDate, MailboxRef};
|
use crate::model::{PermissiveHeaderSection, HeaderDate, MailboxRef};
|
||||||
|
use crate::mailbox::mailbox;
|
||||||
use crate::address::{mailbox_list};
|
use crate::address::{mailbox_list};
|
||||||
|
|
||||||
/// HEADERS
|
/// HEADERS
|
||||||
|
@ -28,23 +28,31 @@ pub fn header_section(input: &str) -> IResult<&str, PermissiveHeaderSection> {
|
||||||
PermissiveHeaderSection::default,
|
PermissiveHeaderSection::default,
|
||||||
|mut section, head| {
|
|mut section, head| {
|
||||||
match head {
|
match head {
|
||||||
|
// 3.6.1. The Origination Date Field
|
||||||
HeaderField::Date(d) => {
|
HeaderField::Date(d) => {
|
||||||
//@FIXME only one date is allowed, what are we doing if multiple dates are
|
//@FIXME only one date is allowed, what are we doing if multiple dates are
|
||||||
//encountered? Currently, we override...
|
//encountered? Currently, we override...
|
||||||
// | orig-date | 1 | 1 | |
|
// | orig-date | 1 | 1 | |
|
||||||
section.date = d;
|
section.date = d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 3.6.2. Originator Fields
|
||||||
|
HeaderField::From(v) => {
|
||||||
|
//@FIXME override the from field if declared multiple times.
|
||||||
|
// | from | 1 | 1 | See sender and 3.6.2 |
|
||||||
|
section.from = v;
|
||||||
|
}
|
||||||
|
HeaderField::Sender(mbx) => {
|
||||||
|
// | sender | 0* | 1 | MUST occur with multi-address from - see 3.6.2 |
|
||||||
|
section.sender = Some(mbx);
|
||||||
|
}
|
||||||
|
|
||||||
HeaderField::Subject(title) => {
|
HeaderField::Subject(title) => {
|
||||||
section.subject = Some(title);
|
section.subject = Some(title);
|
||||||
}
|
}
|
||||||
HeaderField::Optional(name, body) => {
|
HeaderField::Optional(name, body) => {
|
||||||
section.optional.insert(name, body);
|
section.optional.insert(name, body);
|
||||||
}
|
}
|
||||||
HeaderField::From(v) => {
|
|
||||||
//@FIXME override the from field if declared multiple times.
|
|
||||||
// | from | 1 | 1 | See sender and 3.6.2 |
|
|
||||||
section.from = v;
|
|
||||||
}
|
|
||||||
_ => unimplemented!(),
|
_ => unimplemented!(),
|
||||||
};
|
};
|
||||||
section
|
section
|
||||||
|
@ -62,7 +70,7 @@ enum HeaderField<'a> {
|
||||||
|
|
||||||
// 3.6.2. Originator Fields
|
// 3.6.2. Originator Fields
|
||||||
From(Vec<MailboxRef>),
|
From(Vec<MailboxRef>),
|
||||||
Sender,
|
Sender(MailboxRef),
|
||||||
ReplyTo,
|
ReplyTo,
|
||||||
|
|
||||||
// 3.6.3. Destination Address Fields
|
// 3.6.3. Destination Address Fields
|
||||||
|
@ -120,7 +128,10 @@ fn header_field(input: &str) -> IResult<&str, HeaderField> {
|
||||||
let (input, body) = mailbox_list(input)?;
|
let (input, body) = mailbox_list(input)?;
|
||||||
(input, HeaderField::From(body))
|
(input, HeaderField::From(body))
|
||||||
},
|
},
|
||||||
"Sender" => unimplemented!(),
|
"Sender" => {
|
||||||
|
let (input, body) = mailbox(input)?;
|
||||||
|
(input, HeaderField::Sender(body))
|
||||||
|
},
|
||||||
"Subject" => {
|
"Subject" => {
|
||||||
let (input, body) = unstructured(input)?;
|
let (input, body) = unstructured(input)?;
|
||||||
(input, HeaderField::Subject(body))
|
(input, HeaderField::Subject(body))
|
||||||
|
@ -132,7 +143,7 @@ fn header_field(input: &str) -> IResult<&str, HeaderField> {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Drop EOL
|
// Drop EOL
|
||||||
let (input, _) = crlf(input)?;
|
let (input, _) = perm_crlf(input)?;
|
||||||
return Ok((input, hfield));
|
return Ok((input, hfield));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,6 +187,19 @@ mod tests {
|
||||||
}]))),
|
}]))),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
#[test]
|
||||||
|
fn test_sender() {
|
||||||
|
assert_eq!(
|
||||||
|
header_field("Sender: Michael Jones <mjones@machine.example>\r\n"),
|
||||||
|
Ok(("", HeaderField::Sender(MailboxRef {
|
||||||
|
name: Some("Michael Jones".into()),
|
||||||
|
addrspec: AddrSpec {
|
||||||
|
local_part: "mjones".into(),
|
||||||
|
domain: "machine.example".into(),
|
||||||
|
},
|
||||||
|
}))),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
10
src/parse.rs
10
src/parse.rs
|
@ -1,6 +1,14 @@
|
||||||
use imf_codec::headers;
|
use imf_codec::headers;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let header = "Date: Fri, 21 Nov 1997 09:55:06 -0600\r\nSubject: Hello\r\n World\r\nFrom: <quentin@deuxfleurs.fr>\r\n\r\nHello world";
|
let header = r#"Date: Fri, 21 Nov 1997 09:55:06 -0600
|
||||||
|
Subject: Hello
|
||||||
|
World
|
||||||
|
From: <quentin@example.com>
|
||||||
|
Sender: imf@example.com
|
||||||
|
|
||||||
|
Hello world
|
||||||
|
"#;
|
||||||
|
|
||||||
println!("{:?}", headers::header_section(header));
|
println!("{:?}", headers::header_section(header));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue