This commit is contained in:
Quentin 2023-06-19 17:25:16 +02:00
parent 34b146edaf
commit 25bc3bb55c
Signed by: quentin
GPG key ID: E9602264D639FF68
23 changed files with 62 additions and 107 deletions

View file

@ -1,51 +0,0 @@
#[derive(Debug, PartialEq)]
pub struct Raw<'a>(&'a [u8]);
pub struct Segment<'a> {
pub header: &'a [u8],
pub body: &'a [u8],
}
/*
pub struct DecodeHeader<'a> {
pub header: Cow<'a, &str>;
pub encoding: &'static Encoding;
pub is_malformed: bool;
pub body: &'a [u8];
}
pub struct ExtractHeaderLines<'a> {
pub header: Vec<Cow<'a, &str>>;
pub body: &'a [u8];
}
pub struct ParseFieldNames<'a> {
pub header: Vec<FieldName>;
pub body: &'a [u8];
pub bad_lines: Vec<Cow<'a, &str>;
}
pub struct ParseFieldBody<'a> {
pub header: Vec<FieldBody>;
pub body: &'a [u8];
pub bad_lines: Vec<Cow<'a, &str>;
pub bad_fields: Vec<FieldName>;
}
pub struct BuildHeaderSection<'a> {
pub header: Section<'a>;
pub body: &'a [u8];
}*/
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_create_parser() {
assert_eq!(
Raw(b"From: a@a.com\r\n\r\n"),
Raw(&[0x46, 0x72, 0x6F, 0x6D, 0x3A, 0x20, 0x61, 0x40, 0x61, 0x2E, 0x63, 0x6F, 0x6D, 0x0D, 0x0A, 0x0D, 0x0A]),
);
}
}

View file

@ -7,10 +7,10 @@ use nom::{
sequence::tuple,
};
use crate::model::{GroupRef, AddressRef, MailboxRef};
use crate::mailbox::{addr_spec, mailbox};
use crate::misc_token::phrase;
use crate::whitespace::{cfws};
use crate::fragments::model::{GroupRef, AddressRef, MailboxRef};
use crate::fragments::mailbox::{addr_spec, mailbox};
use crate::fragments::misc_token::phrase;
use crate::fragments::whitespace::{cfws};
/// Address (section 3.4 of RFC5322)
///
@ -77,7 +77,7 @@ pub fn address_list_cfws(input: &str) -> IResult<&str, Vec<AddressRef>> {
#[cfg(test)]
mod tests {
use super::*;
use crate::model::AddrSpec;
use crate::fragments::model::AddrSpec;
#[test]
fn test_mailbox_list() {

View file

@ -10,8 +10,8 @@ use nom::{
combinator::{map, opt, value},
sequence::{preceded, terminated, tuple, delimited },
};
use crate::misc_token;
use crate::whitespace::{fws, cfws};
use crate::fragments::misc_token;
use crate::fragments::whitespace::{fws, cfws};
const MIN: i32 = 60;
const HOUR: i32 = 60 * MIN;

View file

@ -14,14 +14,14 @@ use nom::{
use chardetng::EncodingDetector;
use encoding_rs::Encoding;
use crate::whitespace::{fws, perm_crlf};
use crate::words::vchar_seq;
use crate::misc_token::{phrase, unstructured};
use crate::model::{HeaderSection, MailboxRef, AddressRef, Field, FieldBody};
use crate::mailbox::mailbox;
use crate::address::{mailbox_list, address_list, address_list_cfws};
use crate::identification::msg_id;
use crate::{datetime, trace, model};
use crate::fragments::whitespace::{fws, perm_crlf};
use crate::fragments::words::vchar_seq;
use crate::fragments::misc_token::{phrase, unstructured};
use crate::fragments::model::{HeaderSection, MailboxRef, AddressRef, Field, FieldBody};
use crate::fragments::mailbox::mailbox;
use crate::fragments::address::{mailbox_list, address_list, address_list_cfws};
use crate::fragments::identification::msg_id;
use crate::fragments::{datetime, trace, model};
/// HEADERS
@ -329,7 +329,7 @@ fn rescue_field(input: &str) -> IResult<&str, Field> {
#[cfg(test)]
mod tests {
use super::*;
use crate::model::{GroupRef, AddrSpec};
use crate::fragments::model::{GroupRef, AddrSpec};
// 3.6.1. The Origination Date Field
/* #[test]

View file

@ -7,10 +7,10 @@ use nom::{
sequence::{delimited, pair, tuple},
};
use crate::whitespace::cfws;
use crate::words::dot_atom_text;
use crate::mailbox::is_dtext;
use crate::model::MessageId;
use crate::fragments::whitespace::cfws;
use crate::fragments::words::dot_atom_text;
use crate::fragments::mailbox::is_dtext;
use crate::fragments::model::MessageId;
/// Message identifier
///

View file

@ -10,11 +10,11 @@ use nom::{
sequence::{delimited,pair,preceded,terminated,tuple},
};
use crate::model::{MailboxRef, AddrSpec};
use crate::misc_token::{phrase, word};
use crate::whitespace::{cfws, fws, is_obs_no_ws_ctl};
use crate::words::{atom, dot_atom};
use crate::quoted::quoted_string;
use crate::fragments::model::{MailboxRef, AddrSpec};
use crate::fragments::misc_token::{phrase, word};
use crate::fragments::whitespace::{cfws, fws, is_obs_no_ws_ctl};
use crate::fragments::words::{atom, dot_atom};
use crate::fragments::quoted::quoted_string;
/// Mailbox
///

View file

@ -9,9 +9,9 @@ use nom::{
sequence::{pair, tuple},
};
use crate::quoted::quoted_string;
use crate::whitespace::{fws, is_obs_no_ws_ctl};
use crate::words::{atom, is_vchar};
use crate::fragments::quoted::quoted_string;
use crate::fragments::whitespace::{fws, is_obs_no_ws_ctl};
use crate::fragments::words::{atom, is_vchar};
/// Word
///

18
src/fragments/mod.rs Normal file
View file

@ -0,0 +1,18 @@
// Model
pub mod model;
// Generic
mod whitespace;
mod words;
mod quoted;
mod misc_token;
// Header specific
mod mailbox;
mod address;
mod identification;
mod trace;
mod datetime;
// Header blocks
pub mod header;

View file

@ -8,8 +8,8 @@ use nom::{
sequence::{pair, preceded},
};
use crate::words::is_vchar;
use crate::whitespace::{fws, cfws, is_obs_no_ws_ctl};
use crate::fragments::words::is_vchar;
use crate::fragments::whitespace::{fws, cfws, is_obs_no_ws_ctl};
/// Quoted pair
///

View file

@ -8,7 +8,7 @@ use nom::{
multi::many0,
sequence::{delimited, pair, tuple},
};
use crate::{datetime, mailbox, model, misc_token, whitespace};
use crate::fragments::{datetime, mailbox, model, misc_token, whitespace};
pub fn received_body(input: &str) -> IResult<&str, &str> {
map(

View file

@ -7,7 +7,7 @@ use nom::{
multi::{many0, many1},
sequence::{pair, tuple},
};
use crate::quoted::quoted_pair;
use crate::fragments::quoted::quoted_pair;
// --- whitespaces and comments

View file

@ -5,7 +5,7 @@ use nom::{
multi::many0,
sequence::{delimited, pair},
};
use crate::whitespace::cfws;
use crate::fragments::whitespace::cfws;
/// VCHAR definition

View file

@ -1,21 +1,2 @@
// Model
pub mod model;
// Generic
mod whitespace;
mod words;
mod quoted;
mod misc_token;
// Header specific
mod mailbox;
mod address;
mod identification;
mod trace;
mod datetime;
// Header blocks
pub mod header;
// root
pub mod email;
pub mod fragments;
pub mod multipass;

View file

View file

View file

0
src/multipass/mod.rs Normal file
View file

View file

View file

7
src/multipass/segment.rs Normal file
View file

@ -0,0 +1,7 @@
#[derive(Debug, PartialEq)]
pub struct Segment<'a> {
pub header: &'a [u8],
pub body: &'a [u8],
}

View file

@ -1,4 +1,4 @@
use imf_codec::header;
use imf_codec::fragments::header;
use std::io;
use std::io::Read;

View file

@ -2,7 +2,7 @@ use std::collections::HashSet;
use std::path::PathBuf;
use std::fs::File;
use std::io::Read;
use imf_codec::header;
use imf_codec::fragments::header;
use walkdir::WalkDir;