identification tests
This commit is contained in:
parent
b998aec37d
commit
4d86afaacf
2 changed files with 18 additions and 20 deletions
|
@ -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<MessageId<'a>>;
|
||||
|
||||
/*
|
||||
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"[..],
|
||||
}
|
||||
)),
|
||||
);
|
||||
|
|
|
@ -2,3 +2,4 @@ pub mod mailbox;
|
|||
pub mod address;
|
||||
pub mod datetime;
|
||||
pub mod trace;
|
||||
pub mod identification;
|
||||
|
|
Loading…
Reference in a new issue