From 4d86afaacf2c9732cc28eafe0190569b811ccfa0 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Wed, 19 Jul 2023 18:30:43 +0200 Subject: [PATCH] identification tests --- src/rfc5322/identification.rs | 37 ++++++++++++++++------------------- src/rfc5322/mod.rs | 1 + 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/rfc5322/identification.rs b/src/rfc5322/identification.rs index 179505e..7a44720 100644 --- a/src/rfc5322/identification.rs +++ b/src/rfc5322/identification.rs @@ -2,26 +2,23 @@ use nom::{ branch::alt, bytes::complete::{tag, take_while}, combinator::opt, - multi::many1, sequence::{delimited, pair, tuple}, IResult, }; -use crate::error::IMFError; -use crate::fragments::lazy; -use crate::fragments::mailbox::is_dtext; -use crate::fragments::model::{MessageId, MessageIdList}; -use crate::fragments::whitespace::cfws; -use crate::fragments::words::dot_atom_text; +use crate::rfc5322::mailbox::is_dtext; +use crate::text::whitespace::cfws; +use crate::text::words::dot_atom_text; #[derive(Debug, PartialEq)] pub struct MessageId<'a> { - pub left: &'a str, - pub right: &'a str, + pub left: &'a [u8], + pub right: &'a [u8], } pub type MessageIdList<'a> = Vec>; +/* impl<'a> TryFrom<&'a lazy::Identifier<'a>> for MessageId<'a> { type Error = IMFError<'a>; @@ -40,14 +37,14 @@ impl<'a> TryFrom<&'a lazy::IdentifierList<'a>> for MessageIdList<'a> { .map(|(_, i)| i) .map_err(|e| IMFError::MessageIDList(e)) } -} +}*/ /// Message identifier /// /// ```abnf /// msg-id = [CFWS] "<" id-left "@" id-right ">" [CFWS] /// ``` -pub fn msg_id(input: &str) -> IResult<&str, MessageId> { +pub fn msg_id(input: &[u8]) -> IResult<&[u8], MessageId> { let (input, (left, _, right)) = delimited( pair(opt(cfws), tag("<")), tuple((id_left, tag("@"), id_right)), @@ -56,17 +53,17 @@ pub fn msg_id(input: &str) -> IResult<&str, MessageId> { Ok((input, MessageId { left, right })) } -// Missing obsolete -fn id_left(input: &str) -> IResult<&str, &str> { +// @FIXME Missing obsolete +fn id_left(input: &[u8]) -> IResult<&[u8], &[u8]> { dot_atom_text(input) } -// Missing obsolete -fn id_right(input: &str) -> IResult<&str, &str> { +// @FIXME Missing obsolete +fn id_right(input: &[u8]) -> IResult<&[u8], &[u8]> { alt((dot_atom_text, no_fold_litteral))(input) } -fn no_fold_litteral(input: &str) -> IResult<&str, &str> { +fn no_fold_litteral(input: &[u8]) -> IResult<&[u8], &[u8]> { delimited(tag("["), take_while(is_dtext), tag("]"))(input) } @@ -77,12 +74,12 @@ mod tests { #[test] fn test_msg_id() { assert_eq!( - msg_id("<5678.21-Nov-1997@example.com>"), + msg_id(b"<5678.21-Nov-1997@example.com>"), Ok(( - "", + &b""[..], MessageId { - left: "5678.21-Nov-1997", - right: "example.com" + left: &b"5678.21-Nov-1997"[..], + right: &b"example.com"[..], } )), ); diff --git a/src/rfc5322/mod.rs b/src/rfc5322/mod.rs index 7192509..e3dca7f 100644 --- a/src/rfc5322/mod.rs +++ b/src/rfc5322/mod.rs @@ -2,3 +2,4 @@ pub mod mailbox; pub mod address; pub mod datetime; pub mod trace; +pub mod identification;