use crate::{HeaderName, HeaderValue, MessageParser};
impl MessageParser {
pub fn new() -> Self {
Self {
header_map: Default::default(),
def_hdr_parse_fnc: |s| s.parse_raw(),
}
}
pub fn with_mime_headers(self) -> Self {
self.header_content_type(HeaderName::ContentType)
.header_content_type(HeaderName::ContentDisposition)
.header_id(HeaderName::ContentId)
.header_text(HeaderName::ContentDescription)
.header_text(HeaderName::ContentLocation)
.header_text(HeaderName::ContentTransferEncoding)
}
pub fn with_date_headers(self) -> Self {
self.header_date(HeaderName::Date)
.header_date(HeaderName::ResentDate)
}
pub fn with_address_headers(self) -> Self {
self.header_address(HeaderName::From)
.header_address(HeaderName::Sender)
.header_address(HeaderName::ReplyTo)
.header_address(HeaderName::To)
.header_address(HeaderName::Cc)
.header_address(HeaderName::Bcc)
.header_address(HeaderName::ResentFrom)
.header_address(HeaderName::ResentSender)
.header_address(HeaderName::ResentTo)
.header_address(HeaderName::ResentCc)
.header_address(HeaderName::ResentBcc)
}
pub fn with_message_ids(self) -> Self {
self.header_id(HeaderName::MessageId)
.header_id(HeaderName::InReplyTo)
.header_id(HeaderName::References)
.header_id(HeaderName::ResentMessageId)
}
pub fn with_minimal_headers(self) -> Self {
self.with_mime_headers()
.header_date(HeaderName::Date)
.header_text(HeaderName::Subject)
.header_address(HeaderName::From)
.header_address(HeaderName::ReplyTo)
.header_address(HeaderName::To)
.header_address(HeaderName::Cc)
.header_address(HeaderName::Bcc)
}
pub fn without_header(mut self, header: impl Into<HeaderName<'static>>) -> Self {
self.header_map.remove(&header.into());
self
}
pub fn header_text(mut self, header: impl Into<HeaderName<'static>>) -> Self {
self.header_map
.insert(header.into(), |s| s.parse_unstructured());
self
}
pub fn header_date(mut self, header: impl Into<HeaderName<'static>>) -> Self {
self.header_map.insert(header.into(), |s| s.parse_date());
self
}
pub fn header_address(mut self, header: impl Into<HeaderName<'static>>) -> Self {
self.header_map.insert(header.into(), |s| s.parse_address());
self
}
pub fn header_id(mut self, header: impl Into<HeaderName<'static>>) -> Self {
self.header_map.insert(header.into(), |s| s.parse_id());
self
}
pub fn header_content_type(mut self, header: impl Into<HeaderName<'static>>) -> Self {
self.header_map
.insert(header.into(), |s| s.parse_content_type());
self
}
pub fn header_comma_separated(mut self, header: impl Into<HeaderName<'static>>) -> Self {
self.header_map
.insert(header.into(), |s| s.parse_comma_separared());
self
}
pub fn header_received(mut self, header: impl Into<HeaderName<'static>>) -> Self {
self.header_map
.insert(header.into(), |s| s.parse_received());
self
}
pub fn header_raw(mut self, header: impl Into<HeaderName<'static>>) -> Self {
self.header_map.insert(header.into(), |s| s.parse_raw());
self
}
pub fn ignore_header(mut self, header: impl Into<HeaderName<'static>>) -> Self {
self.header_map.insert(header.into(), |s| {
s.parse_and_ignore();
HeaderValue::Empty
});
self
}
pub fn default_header_text(mut self) -> Self {
self.def_hdr_parse_fnc = |s| s.parse_unstructured();
self
}
pub fn default_header_raw(mut self) -> Self {
self.def_hdr_parse_fnc = |s| s.parse_raw();
self
}
pub fn default_header_ignore(mut self) -> Self {
self.def_hdr_parse_fnc = |s| {
s.parse_and_ignore();
HeaderValue::Empty
};
self
}
}
impl Default for MessageParser {
fn default() -> Self {
Self::new()
}
}