implement from
This commit is contained in:
parent
fe6bd78f3c
commit
d46c5895f5
2 changed files with 29 additions and 12 deletions
|
@ -15,6 +15,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::address::{mailbox_list};
|
||||||
|
|
||||||
/// HEADERS
|
/// HEADERS
|
||||||
|
|
||||||
|
@ -30,6 +31,7 @@ pub fn header_section(input: &str) -> IResult<&str, PermissiveHeaderSection> {
|
||||||
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 | |
|
||||||
section.date = d;
|
section.date = d;
|
||||||
}
|
}
|
||||||
HeaderField::Subject(title) => {
|
HeaderField::Subject(title) => {
|
||||||
|
@ -38,6 +40,11 @@ pub fn header_section(input: &str) -> IResult<&str, PermissiveHeaderSection> {
|
||||||
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
|
||||||
|
@ -48,13 +55,13 @@ pub fn header_section(input: &str) -> IResult<&str, PermissiveHeaderSection> {
|
||||||
Ok((input, headers))
|
Ok((input, headers))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, PartialEq)]
|
||||||
enum HeaderField<'a> {
|
enum HeaderField<'a> {
|
||||||
// 3.6.1. The Origination Date Field
|
// 3.6.1. The Origination Date Field
|
||||||
Date(HeaderDate),
|
Date(HeaderDate),
|
||||||
|
|
||||||
// 3.6.2. Originator Fields
|
// 3.6.2. Originator Fields
|
||||||
From,
|
From(Vec<MailboxRef>),
|
||||||
Sender,
|
Sender,
|
||||||
ReplyTo,
|
ReplyTo,
|
||||||
|
|
||||||
|
@ -109,7 +116,10 @@ fn header_field(input: &str) -> IResult<&str, HeaderField> {
|
||||||
// Extract field body
|
// Extract field body
|
||||||
let (input, hfield) = match field_name {
|
let (input, hfield) = match field_name {
|
||||||
"Date" => datetime(input)?,
|
"Date" => datetime(input)?,
|
||||||
"From" => from(input)?,
|
"From" => {
|
||||||
|
let (input, body) = mailbox_list(input)?;
|
||||||
|
(input, HeaderField::From(body))
|
||||||
|
},
|
||||||
"Sender" => unimplemented!(),
|
"Sender" => unimplemented!(),
|
||||||
"Subject" => {
|
"Subject" => {
|
||||||
let (input, body) = unstructured(input)?;
|
let (input, body) = unstructured(input)?;
|
||||||
|
@ -137,17 +147,10 @@ fn datetime(input: &str) -> IResult<&str, HeaderField> {
|
||||||
Ok((input, HeaderField::Date(date)))
|
Ok((input, HeaderField::Date(date)))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from(input: &str) -> IResult<&str, HeaderField> {
|
|
||||||
//let (input, mbox_list) = many0(mailbox)(input)?;
|
|
||||||
//Ok((input, HeaderField::From(mbox_list)))
|
|
||||||
unimplemented!();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::model::AddrSpec;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_datetime() {
|
fn test_datetime() {
|
||||||
|
@ -159,6 +162,20 @@ mod tests {
|
||||||
_ => panic!("Date has not been parsed"),
|
_ => panic!("Date has not been parsed"),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_from() {
|
||||||
|
assert_eq!(
|
||||||
|
header_field("From: \"Joe Q. Public\" <john.q.public@example.com>\r\n"),
|
||||||
|
Ok(("", HeaderField::From(vec![MailboxRef {
|
||||||
|
name: Some("Joe Q. Public".into()),
|
||||||
|
addrspec: AddrSpec {
|
||||||
|
local_part: "john.q.public".into(),
|
||||||
|
domain: "example.com".into(),
|
||||||
|
}
|
||||||
|
}]))),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use chrono::{DateTime,FixedOffset,ParseError};
|
use chrono::{DateTime,FixedOffset,ParseError};
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, PartialEq, Default)]
|
||||||
pub enum HeaderDate {
|
pub enum HeaderDate {
|
||||||
Parsed(DateTime<FixedOffset>),
|
Parsed(DateTime<FixedOffset>),
|
||||||
Unknown(String, ParseError),
|
Unknown(String, ParseError),
|
||||||
|
|
Loading…
Reference in a new issue