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,
|
branch::alt,
|
||||||
bytes::complete::{tag, take_while},
|
bytes::complete::{tag, take_while},
|
||||||
combinator::opt,
|
combinator::opt,
|
||||||
multi::many1,
|
|
||||||
sequence::{delimited, pair, tuple},
|
sequence::{delimited, pair, tuple},
|
||||||
IResult,
|
IResult,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::error::IMFError;
|
use crate::rfc5322::mailbox::is_dtext;
|
||||||
use crate::fragments::lazy;
|
use crate::text::whitespace::cfws;
|
||||||
use crate::fragments::mailbox::is_dtext;
|
use crate::text::words::dot_atom_text;
|
||||||
use crate::fragments::model::{MessageId, MessageIdList};
|
|
||||||
use crate::fragments::whitespace::cfws;
|
|
||||||
use crate::fragments::words::dot_atom_text;
|
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub struct MessageId<'a> {
|
pub struct MessageId<'a> {
|
||||||
pub left: &'a str,
|
pub left: &'a [u8],
|
||||||
pub right: &'a str,
|
pub right: &'a [u8],
|
||||||
}
|
}
|
||||||
pub type MessageIdList<'a> = Vec<MessageId<'a>>;
|
pub type MessageIdList<'a> = Vec<MessageId<'a>>;
|
||||||
|
|
||||||
|
/*
|
||||||
impl<'a> TryFrom<&'a lazy::Identifier<'a>> for MessageId<'a> {
|
impl<'a> TryFrom<&'a lazy::Identifier<'a>> for MessageId<'a> {
|
||||||
type Error = IMFError<'a>;
|
type Error = IMFError<'a>;
|
||||||
|
|
||||||
|
@ -40,14 +37,14 @@ impl<'a> TryFrom<&'a lazy::IdentifierList<'a>> for MessageIdList<'a> {
|
||||||
.map(|(_, i)| i)
|
.map(|(_, i)| i)
|
||||||
.map_err(|e| IMFError::MessageIDList(e))
|
.map_err(|e| IMFError::MessageIDList(e))
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
/// Message identifier
|
/// Message identifier
|
||||||
///
|
///
|
||||||
/// ```abnf
|
/// ```abnf
|
||||||
/// msg-id = [CFWS] "<" id-left "@" id-right ">" [CFWS]
|
/// 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(
|
let (input, (left, _, right)) = delimited(
|
||||||
pair(opt(cfws), tag("<")),
|
pair(opt(cfws), tag("<")),
|
||||||
tuple((id_left, tag("@"), id_right)),
|
tuple((id_left, tag("@"), id_right)),
|
||||||
|
@ -56,17 +53,17 @@ pub fn msg_id(input: &str) -> IResult<&str, MessageId> {
|
||||||
Ok((input, MessageId { left, right }))
|
Ok((input, MessageId { left, right }))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Missing obsolete
|
// @FIXME Missing obsolete
|
||||||
fn id_left(input: &str) -> IResult<&str, &str> {
|
fn id_left(input: &[u8]) -> IResult<&[u8], &[u8]> {
|
||||||
dot_atom_text(input)
|
dot_atom_text(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Missing obsolete
|
// @FIXME Missing obsolete
|
||||||
fn id_right(input: &str) -> IResult<&str, &str> {
|
fn id_right(input: &[u8]) -> IResult<&[u8], &[u8]> {
|
||||||
alt((dot_atom_text, no_fold_litteral))(input)
|
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)
|
delimited(tag("["), take_while(is_dtext), tag("]"))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,12 +74,12 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_msg_id() {
|
fn test_msg_id() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
msg_id("<5678.21-Nov-1997@example.com>"),
|
msg_id(b"<5678.21-Nov-1997@example.com>"),
|
||||||
Ok((
|
Ok((
|
||||||
"",
|
&b""[..],
|
||||||
MessageId {
|
MessageId {
|
||||||
left: "5678.21-Nov-1997",
|
left: &b"5678.21-Nov-1997"[..],
|
||||||
right: "example.com"
|
right: &b"example.com"[..],
|
||||||
}
|
}
|
||||||
)),
|
)),
|
||||||
);
|
);
|
||||||
|
|
|
@ -2,3 +2,4 @@ pub mod mailbox;
|
||||||
pub mod address;
|
pub mod address;
|
||||||
pub mod datetime;
|
pub mod datetime;
|
||||||
pub mod trace;
|
pub mod trace;
|
||||||
|
pub mod identification;
|
||||||
|
|
Loading…
Reference in a new issue