to_mime works

This commit is contained in:
Quentin 2023-07-22 14:23:37 +02:00
parent 39d6847da7
commit a8ae9c3714
Signed by: quentin
GPG key ID: E9602264D639FF68
2 changed files with 11 additions and 11 deletions

View file

@ -8,10 +8,10 @@ use nom::{
use crate::text::whitespace::obs_crlf; use crate::text::whitespace::obs_crlf;
use crate::text::misc_token::{Unstructured, unstructured}; use crate::text::misc_token::{Unstructured, unstructured};
use crate::rfc5322::identification::{MessageID, msg_id}; use crate::rfc5322::identification::{MessageID, msg_id};
use crate::header::{field_name}; use crate::header::{field_name, CompFieldList};
use crate::mime::r#type::{NaiveType, naive_type}; use crate::mime::r#type::{NaiveType, naive_type};
use crate::mime::mechanism::{Mechanism, mechanism}; use crate::mime::mechanism::{Mechanism, mechanism};
//use crate::mime::mime::MIME; use crate::mime::mime::MIME;
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
pub enum Content<'a> { pub enum Content<'a> {
@ -20,9 +20,9 @@ pub enum Content<'a> {
ID(MessageID<'a>), ID(MessageID<'a>),
Description(Unstructured<'a>), Description(Unstructured<'a>),
} }
/*impl<'a> CompFieldList<Content<'a>> { impl<'a> CompFieldList<'a, Content<'a>> {
pub fn to_mime(&self) -> MIME { self.into() } pub fn to_mime(self) -> MIME<'a> { self.known().into_iter().collect::<MIME>() }
}*/ }
pub fn content(input: &[u8]) -> IResult<&[u8], Content> { pub fn content(input: &[u8]) -> IResult<&[u8], Content> {
terminated(alt(( terminated(alt((

View file

@ -6,14 +6,14 @@ use crate::mime::field::Content;
#[derive(Debug, PartialEq, Default)] #[derive(Debug, PartialEq, Default)]
pub struct MIME<'a> { pub struct MIME<'a> {
pub content_type: Option<&'a NaiveType<'a>>, pub content_type: Option<NaiveType<'a>>,
pub content_transfer_encoding: Option<&'a Mechanism<'a>>, pub content_transfer_encoding: Option<Mechanism<'a>>,
pub content_id: Option<&'a MessageID<'a>>, pub content_id: Option<MessageID<'a>>,
pub content_description: Option<&'a Unstructured<'a>>, pub content_description: Option<Unstructured<'a>>,
} }
impl<'a> FromIterator<&'a Content<'a>> for MIME<'a> { impl<'a> FromIterator<Content<'a>> for MIME<'a> {
fn from_iter<I: IntoIterator<Item = &'a Content<'a>>>(source: I) -> Self { fn from_iter<I: IntoIterator<Item = Content<'a>>>(source: I) -> Self {
source.into_iter().fold( source.into_iter().fold(
MIME::default(), MIME::default(),
|mut section, field| { |mut section, field| {