wip fields
This commit is contained in:
parent
b7ad47b41e
commit
83a527b618
3 changed files with 51 additions and 84 deletions
|
@ -104,3 +104,5 @@ fn opt_field(input: &[u8]) -> IResult<&[u8], (&[u8], Unstructured)> {
|
|||
unstructured,
|
||||
)(input)
|
||||
}
|
||||
|
||||
// @TODO write a parse header function
|
||||
|
|
|
@ -1,112 +1,76 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use crate::fragments::eager::{Field, MIMEField};
|
||||
use crate::fragments::lazy;
|
||||
use crate::fragments::misc_token::{PhraseList, Unstructured};
|
||||
use crate::fragments::mime::{Version,Type,Mechanism};
|
||||
use crate::fragments::model::{AddressRef, MailboxRef, MessageId};
|
||||
use crate::fragments::trace::ReceivedLog;
|
||||
use crate::text::misc_token::{PhraseList, Unstructured};
|
||||
use crate::rfc5322::mime::Version;
|
||||
use crate::rfc5322::mailbox::{MailboxRef};
|
||||
use crate::rfc5322::address::{AddressRef};
|
||||
use crate::rfc5322::identification::{MessageID, MessageIDList};
|
||||
use crate::rfc5322::field::Field;
|
||||
use crate::rfc5322::trace::ReceivedLog;
|
||||
use chrono::{DateTime, FixedOffset};
|
||||
|
||||
#[derive(Debug, PartialEq, Default)]
|
||||
pub struct Message<'a> {
|
||||
// 3.6.1. The Origination Date Field
|
||||
pub date: Option<DateTime<FixedOffset>>,
|
||||
pub date: &'a Option<DateTime<FixedOffset>>,
|
||||
|
||||
// 3.6.2. Originator Fields
|
||||
pub from: Vec<MailboxRef<'a>>,
|
||||
pub sender: Option<MailboxRef<'a>>,
|
||||
pub reply_to: Vec<AddressRef<'a>>,
|
||||
pub from: Vec<&'a MailboxRef<'a>>,
|
||||
pub sender: Option<&'a MailboxRef<'a>>,
|
||||
pub reply_to: Vec<&'a AddressRef<'a>>,
|
||||
|
||||
// 3.6.3. Destination Address Fields
|
||||
pub to: Vec<AddressRef<'a>>,
|
||||
pub cc: Vec<AddressRef<'a>>,
|
||||
pub bcc: Vec<AddressRef<'a>>,
|
||||
pub to: Vec<&'a AddressRef<'a>>,
|
||||
pub cc: Vec<&'a AddressRef<'a>>,
|
||||
pub bcc: Vec<&'a AddressRef<'a>>,
|
||||
|
||||
// 3.6.4. Identification Fields
|
||||
pub msg_id: Option<MessageId<'a>>,
|
||||
pub in_reply_to: Vec<MessageId<'a>>,
|
||||
pub references: Vec<MessageId<'a>>,
|
||||
pub msg_id: Option<&'a MessageID<'a>>,
|
||||
pub in_reply_to: MessageIDList<'a>,
|
||||
pub references: MessageIDList<'a>,
|
||||
|
||||
// 3.6.5. Informational Fields
|
||||
pub subject: Option<Unstructured<'a>>,
|
||||
pub comments: Vec<Unstructured<'a>>,
|
||||
pub keywords: Vec<PhraseList<'a>>,
|
||||
pub subject: Option<&'a Unstructured<'a>>,
|
||||
pub comments: Vec<&'a Unstructured<'a>>,
|
||||
pub keywords: Vec<&'a PhraseList<'a>>,
|
||||
|
||||
// 3.6.6 Not implemented
|
||||
// 3.6.7 Trace Fields
|
||||
pub return_path: Vec<MailboxRef<'a>>,
|
||||
pub received: Vec<ReceivedLog<'a>>,
|
||||
pub return_path: Vec<&'a MailboxRef<'a>>,
|
||||
pub received: Vec<&'a ReceivedLog<'a>>,
|
||||
|
||||
// 3.6.8. Optional Fields
|
||||
pub optional: HashMap<&'a [u8], Unstructured<'a>>,
|
||||
|
||||
// Recovery
|
||||
pub unparsed: Vec<&'a [u8]>,
|
||||
// MIME
|
||||
pub mime_version: Option<&'a Version>,
|
||||
}
|
||||
|
||||
impl<'a> FromIterator<&'a [u8]> for Message<'a> {
|
||||
fn from_iter<I: IntoIterator<Item = &'a [u8]>>(iter: I) -> Self {
|
||||
iter.fold(
|
||||
//@FIXME min and max limits are not enforced,
|
||||
// it may result in missing data or silently overriden data.
|
||||
impl<'a> FromIterator<&'a Field<'a>> for Message<'a> {
|
||||
fn from_iter<I: IntoIterator<Item = &'a Field<'a>>>(iter: I) -> Self {
|
||||
iter.into_iter().fold(
|
||||
Message::default(),
|
||||
|mut msg, field| {
|
||||
match field_name(field) {
|
||||
Ok((name, value)) => xx,
|
||||
|
||||
}
|
||||
|
||||
|mut section, field| {
|
||||
match field {
|
||||
|
||||
}
|
||||
msg
|
||||
Field::Date(v) => section.date = v,
|
||||
Field::From(v) => section.from.extend(v),
|
||||
Field::Sender(v) => section.sender = Some(v),
|
||||
Field::ReplyTo(v) => section.reply_to.extend(v),
|
||||
Field::To(v) => section.to.extend(v),
|
||||
Field::Cc(v) => section.cc.extend(v),
|
||||
Field::Bcc(v) => section.bcc.extend(v),
|
||||
Field::MessageID(v) => section.msg_id = Some(v),
|
||||
Field::InReplyTo(v) => section.in_reply_to.extend(v),
|
||||
Field::References(v) => section.references.extend(v),
|
||||
Field::Subject(v) => section.subject = Some(v),
|
||||
Field::Comments(v) => section.comments.push(v),
|
||||
Field::Keywords(v) => section.keywords.push(v),
|
||||
Field::ReturnPath(v) => section.return_path.push(v),
|
||||
Field::Received(v) => section.received.push(v),
|
||||
Field::MIMEVersion(v) => section.mime_version = Some(v),
|
||||
};
|
||||
section
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//@FIXME min and max limits are not enforced,
|
||||
// it may result in missing data or silently overriden data.
|
||||
impl<'a> FromIterator<&'a Field<'a>> for Section<'a> {
|
||||
fn from_iter<I: IntoIterator<Item = &'a Field<'a>>>(iter: I) -> Self {
|
||||
let mut section = Section::default();
|
||||
for field in iter {
|
||||
match field {
|
||||
Field::Date(v) => section.date = Some(v),
|
||||
Field::From(v) => section.from.extend(v),
|
||||
Field::Sender(v) => section.sender = Some(v),
|
||||
Field::ReplyTo(v) => section.reply_to.extend(v),
|
||||
Field::To(v) => section.to.extend(v),
|
||||
Field::Cc(v) => section.cc.extend(v),
|
||||
Field::Bcc(v) => section.bcc.extend(v),
|
||||
Field::MessageID(v) => section.msg_id = Some(v),
|
||||
Field::InReplyTo(v) => section.in_reply_to.extend(v),
|
||||
Field::References(v) => section.references.extend(v),
|
||||
Field::Subject(v) => section.subject = Some(v),
|
||||
Field::Comments(v) => section.comments.push(v),
|
||||
Field::Keywords(v) => section.keywords.push(v),
|
||||
Field::ReturnPath(v) => section.return_path.push(v),
|
||||
Field::Received(v) => section.received.push(v),
|
||||
Field::Optional(k, v) => {
|
||||
section.optional.insert(k, v);
|
||||
}
|
||||
Field::Rescue(v) => section.unparsed.push(v),
|
||||
Field::MIMEVersion(v) => section.mime_version = Some(v),
|
||||
Field::MIME(v) => match v {
|
||||
MIMEField::ContentType(v) => section.mime.content_type = Some(v),
|
||||
MIMEField::ContentTransferEncoding(v) => section.mime.content_transfer_encoding = Some(v),
|
||||
MIMEField::ContentID(v) => section.mime.content_id = Some(v),
|
||||
MIMEField::ContentDescription(v) => section.mime.content_description = Some(v),
|
||||
MIMEField::Optional(k, v) => {
|
||||
section.mime.optional.insert(k, v);
|
||||
}
|
||||
MIMEField::Rescue(v) => section.mime.unparsed.push(v),
|
||||
|
||||
},
|
||||
}
|
||||
}
|
||||
section
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,3 +5,4 @@ pub mod trace;
|
|||
pub mod identification;
|
||||
pub mod mime;
|
||||
pub mod field;
|
||||
pub mod message;
|
||||
|
|
Loading…
Reference in a new issue