eml-codec/src/model.rs

34 lines
704 B
Rust
Raw Normal View History

2023-06-08 19:43:32 +00:00
use std::collections::HashMap;
2023-06-12 09:54:15 +00:00
use chrono::{DateTime,FixedOffset,ParseError};
#[derive(Debug, Default)]
pub enum HeaderDate {
Parsed(DateTime<FixedOffset>),
Unknown(String, ParseError),
#[default]
None,
}
2023-06-08 19:43:32 +00:00
#[derive(Debug, Default)]
pub struct HeaderSection<'a> {
pub subject: Option<String>,
pub from: Vec<String>,
2023-06-12 09:54:15 +00:00
pub date: HeaderDate,
2023-06-08 19:43:32 +00:00
pub optional: HashMap<&'a str, String>,
}
2023-06-12 09:54:15 +00:00
enum InvalidEmailErr {
NoUsableDate,
}
impl<'a> HeaderSection<'a> {
fn is_valid(&self) -> Result<(), InvalidEmailErr> {
match self.date {
HeaderDate::Parsed(_) => (),
_ => return Err(InvalidEmailErr::NoUsableDate),
};
Ok(())
}
}