Project reorganization

This commit is contained in:
mdecimus
2023-09-04 15:23:45 +02:00
parent 5a7b50059f
commit 8e5381f60b
310 changed files with 6521 additions and 1534 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
[package]
name = "mail-parser"
description = "Fast and robust e-mail parsing library for Rust"
version = "0.8.2"
version = "0.9.0"
edition = "2018"
authors = [ "Stalwart Labs <hello@stalw.art>"]
license = "Apache-2.0 OR MIT"
-121
View File
@@ -1,121 +0,0 @@
/*
* Copyright Stalwart Labs Ltd. See the COPYING
* file at the top-level directory of this distribution.
*
* Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
* https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
* <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
* option. This file may not be copied, modified, or distributed
* except according to those terms.
*/
#![feature(test)]
extern crate test;
use std::{fs, path::PathBuf};
use test::Bencher;
fn bench_all_samples(b: &mut Bencher, name: &str, fnc: fn(&[u8], &str)) {
const SEPARATOR: &[u8] = "\n---- EXPECTED STRUCTURE ----\n".as_bytes();
println!("Benchmarking {}...\n", name);
let mut test_data = Vec::new();
for test_suite in ["rfc", "legacy", "thirdparty", "malformed"] {
let mut test_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
test_dir.push("tests");
test_dir.push(test_suite);
let mut bench_count = 0;
for file_name in fs::read_dir(&test_dir).unwrap() {
let file_name = file_name.as_ref().unwrap().path();
if file_name.extension().map_or(false, |e| e == "txt") {
let input = fs::read(&file_name).unwrap();
let mut pos = 0;
for sep_pos in 0..input.len() {
if input[sep_pos..sep_pos + SEPARATOR.len()].eq(SEPARATOR) {
pos = sep_pos;
break;
}
}
assert!(
pos > 0,
"Failed to find separator in test file '{}'.",
file_name.display()
);
test_data.push(Vec::from(&input[0..pos]));
bench_count += 1;
}
}
assert!(
bench_count > 0,
"Did not find any benchmarks to run in folder {}.",
test_dir.display()
);
}
b.iter(|| {
for test_msg in &test_data {
fnc(test_msg, String::from_utf8_lossy(&test_msg).as_ref());
}
});
}
#[bench]
fn bench_stalwart(b: &mut Bencher) {
bench_all_samples(b, "stalwart_mail_parser", |bytes, _str| {
mail_parser::Message::parse(bytes);
});
}
// These libraries do not support all RFCs and might be faster
// on the benchmarks as they do not parse all header fields,
// do not decode encoded parts or fail while trying to parse the messages.
// Also no text body conversion between HTML/plain-text is done by these.
//
// To benchmark against these libraries, add to Cargo.toml dev-dependencies:
//
// email = "0.0.21"
// email-format = "0.8"
// email-parser = { version = "0.5.0", features=["headers", "mime"] }
// mailparse = "0.13"
/*
#[bench]
fn bench_email_parser(b: &mut Bencher) {
bench_all_samples(b, "email_parser", |bytes, _str| {
email_parser::prelude::parse_message(bytes).unwrap();
});
}
#[bench]
fn bench_mailparse(b: &mut Bencher) {
bench_all_samples(b, "mailparse", |bytes, _str| {
mailparse::parse_mail(bytes).unwrap();
});
}
#[bench]
fn benchmark_email(b: &mut Bencher) {
bench_all_samples(b, "email", |_bytes, str| {
email::rfc5322::Rfc5322Parser::new(str).consume_message();
});
}
#[bench]
fn bench_email_format(b: &mut Bencher) {
use email_format::rfc5322::Parsable;
bench_all_samples(b, "email_format", |bytes, _str| {
email_format::Email::parse(bytes).unwrap();
});
}
*/
+8 -5
View File
@@ -15,11 +15,14 @@ use mail_parser::mailbox::maildir::FolderIterator;
fn main() {
// Iterates a Maildir++ structure printing the results to stdout.
let mut test_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
test_dir.push("tests");
test_dir.push("maildir");
for folder in FolderIterator::new(test_dir, ".".into()).unwrap() {
for folder in FolderIterator::new(
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("resources")
.join("maildir"),
".".into(),
)
.unwrap()
{
let folder = folder.unwrap();
println!("------\nMailbox: {:?}", folder.name().unwrap_or("INBOX"));
+678
View File
@@ -0,0 +1,678 @@
[
{
"header": "John Doe <jdoe@machine.example>\n",
"expected": {
"Address": {
"name": "John Doe",
"address": "jdoe@machine.example"
}
}
},
{
"header": " Mary Smith <mary@example.net>\n",
"expected": {
"Address": {
"name": "Mary Smith",
"address": "mary@example.net"
}
}
},
{
"header": "\"Joe Q. Public\" <john.q.public@example.com>\n",
"expected": {
"Address": {
"name": "Joe Q. Public",
"address": "john.q.public@example.com"
}
}
},
{
"header": "Mary Smith <mary@x.test>, jdoe@example.org, Who? <one@y.test>\n",
"expected": {
"AddressList": [
{
"name": "Mary Smith",
"address": "mary@x.test"
},
{
"name": null,
"address": "jdoe@example.org"
},
{
"name": "Who?",
"address": "one@y.test"
}
]
}
},
{
"header": "<boss@nil.test>, \"Giant; \\\"Big\\\" Box\" <sysservices@example.net>\n",
"expected": {
"AddressList": [
{
"name": null,
"address": "boss@nil.test"
},
{
"name": "Giant; \"Big\" Box",
"address": "sysservices@example.net"
}
]
}
},
{
"header": "A Group:Ed Jones <c@a.test>,joe@where.test,John <jdoe@one.test>;\n",
"expected": {
"Group": {
"name": "A Group",
"addresses": [
{
"name": "Ed Jones",
"address": "c@a.test"
},
{
"name": null,
"address": "joe@where.test"
},
{
"name": "John",
"address": "jdoe@one.test"
}
]
}
}
},
{
"header": "Undisclosed recipients:;\n",
"expected": {
"Group": {
"name": "Undisclosed recipients",
"addresses": []
}
}
},
{
"header": "\"Mary Smith: Personal Account\" <smith@home.example >\n",
"expected": {
"Address": {
"name": "Mary Smith: Personal Account",
"address": "smith@home.example"
}
}
},
{
"header": "Pete(A nice \\) chap) <pete(his account)@silly.test(his host)>\n",
"expected": {
"Address": {
"name": "Pete (A nice ) chap his account his host)",
"address": "pete@silly.test"
}
}
},
{
"header": "Pete(A nice \n \\\n ) chap) <pete(his\n account)@silly\n .test(his host)>\n",
"expected": {
"Address": {
"name": "Pete (A nice ) chap his account his host)",
"address": "pete@silly.test"
}
}
},
{
"header": "A Group(Some people)\n :Chris Jones <c@(Chris's host.)public.example>,\n joe@example.org,\n John <jdoe@one.test> (my dear friend); (the end of the group)\n",
"expected": {
"GroupList": [
{
"name": "A Group (Some people)",
"addresses": [
{
"name": "Chris Jones (Chris's host.)",
"address": "c@public.example"
},
{
"name": null,
"address": "joe@example.org"
},
{
"name": "John (my dear friend)",
"address": "jdoe@one.test"
}
]
},
{
"name": null,
"addresses": [
{
"name": "the end of the group",
"address": null
}
]
}
]
}
},
{
"header": "(Empty list)(start)Hidden recipients :(nobody(that I know)) ;\n",
"expected": {
"Group": {
"name": "Hidden recipients (Empty list start)",
"addresses": [
{
"name": "nobody(that I know)",
"address": null
}
]
}
}
},
{
"header": "Joe Q. Public <john.q.public@example.com>\n",
"expected": {
"Address": {
"name": "Joe Q. Public",
"address": "john.q.public@example.com"
}
}
},
{
"header": "Mary Smith <@node.test:mary@example.net>, , jdoe@test . example\n",
"expected": {
"AddressList": [
{
"name": "Mary Smith",
"address": "@node.test:mary@example.net"
},
{
"name": null,
"address": "jdoe@test . example"
}
]
}
},
{
"header": "John Doe <jdoe@machine(comment). example>\n",
"expected": {
"Address": {
"name": "John Doe (comment)",
"address": "jdoe@machine. example"
}
}
},
{
"header": "Mary Smith\n \n\t<mary@example.net>\n",
"expected": {
"Address": {
"name": "Mary Smith",
"address": "mary@example.net"
}
}
},
{
"header": "=?US-ASCII*EN?Q?Keith_Moore?= <moore@cs.utk.edu>\n",
"expected": {
"Address": {
"name": "Keith Moore",
"address": "moore@cs.utk.edu"
}
}
},
{
"header": "John =?US-ASCII*EN?Q?Doe?= <moore@cs.utk.edu>\n",
"expected": {
"Address": {
"name": "John Doe",
"address": "moore@cs.utk.edu"
}
}
},
{
"header": "=?ISO-8859-1?Q?Keld_J=F8rn_Simonsen?= <keld@dkuug.dk>\n",
"expected": {
"Address": {
"name": "Keld Jørn Simonsen",
"address": "keld@dkuug.dk"
}
}
},
{
"header": "=?ISO-8859-1?Q?Andr=E9?= Pirard <PIRARD@vm1.ulg.ac.be>\n",
"expected": {
"Address": {
"name": "André Pirard",
"address": "PIRARD@vm1.ulg.ac.be"
}
}
},
{
"header": "=?ISO-8859-1?Q?Olle_J=E4rnefors?= <ojarnef@admin.kth.se>\n",
"expected": {
"Address": {
"name": "Olle Järnefors",
"address": "ojarnef@admin.kth.se"
}
}
},
{
"header": "ietf-822@dimacs.rutgers.edu, ojarnef@admin.kth.se\n",
"expected": {
"AddressList": [
{
"name": null,
"address": "ietf-822@dimacs.rutgers.edu"
},
{
"name": null,
"address": "ojarnef@admin.kth.se"
}
]
}
},
{
"header": "Nathaniel Borenstein <nsb@thumper.bellcore.com>\n (=?iso-8859-8?b?7eXs+SDv4SDp7Oj08A==?=)\n",
"expected": {
"Address": {
"name": "Nathaniel Borenstein (םולש ןב ילטפנ)",
"address": "nsb@thumper.bellcore.com"
}
}
},
{
"header": "Greg Vaudreuil <gvaudre@NRI.Reston.VA.US>, Ned Freed\n <ned@innosoft.com>, Keith Moore <moore@cs.utk.edu>\n",
"expected": {
"AddressList": [
{
"name": "Greg Vaudreuil",
"address": "gvaudre@NRI.Reston.VA.US"
},
{
"name": "Ned Freed",
"address": "ned@innosoft.com"
},
{
"name": "Keith Moore",
"address": "moore@cs.utk.edu"
}
]
}
},
{
"header": "=?ISO-8859-1?Q?a?= <test@test.com>\n",
"expected": {
"Address": {
"name": "a",
"address": "test@test.com"
}
}
},
{
"header": "\"=?ISO-8859-1?Q?a?= b\" <test@test.com>\n",
"expected": {
"Address": {
"name": "a b",
"address": "test@test.com"
}
}
},
{
"header": "=?ISO-8859-1?Q?a?= =?ISO-8859-1?Q?b?= <test@test.com>\n",
"expected": {
"Address": {
"name": "ab",
"address": "test@test.com"
}
}
},
{
"header": "=?ISO-8859-1?Q?a?=\n =?ISO-8859-1?Q?b?= <test@test.com>\n",
"expected": {
"Address": {
"name": "ab",
"address": "test@test.com"
}
}
},
{
"header": "=?ISO-8859-1?Q?a?= \"=?ISO-8859-2?Q?_b?=\" <test@test.com>\n",
"expected": {
"Address": {
"name": "a b",
"address": "test@test.com"
}
}
},
{
"header": " <test@test.com>\n",
"expected": {
"Address": {
"name": null,
"address": "test@test.com"
}
}
},
{
"header": "test@test.com\ninvalid@address.com\n",
"expected": {
"Address": {
"name": null,
"address": "test@test.com"
}
}
},
{
"header": "\"=?ISO-8859-1?Q =?ISO-8859-1?Q?a?= \\\" =?ISO-8859-1?Q?b?=\" <last@address.com>\n\nbody@content.com",
"expected": {
"Address": {
"name": "=?ISO-8859-1?Q a \" b",
"address": "last@address.com"
}
}
},
{
"header": "=? <name@domain.com>\n",
"expected": {
"Address": {
"name": "=?",
"address": "name@domain.com"
}
}
},
{
"header": "\" James Smythe\" <james@example.com>, Friends:\n jane@example.com, =?UTF-8?Q?John_Sm=C3=AEth?=\n <john@example.com>;\n",
"expected": {
"GroupList": [
{
"name": null,
"addresses": [
{
"name": " James Smythe",
"address": "james@example.com"
}
]
},
{
"name": "Friends",
"addresses": [
{
"name": null,
"address": "jane@example.com"
},
{
"name": "John Smîth",
"address": "john@example.com"
}
]
}
]
}
},
{
"header": "List 1: addr1@test.com, addr2@test.com; List 2: addr3@test.com, addr4@test.com; addr5@test.com, addr6@test.com\n",
"expected": {
"GroupList": [
{
"name": "List 1",
"addresses": [
{
"name": null,
"address": "addr1@test.com"
},
{
"name": null,
"address": "addr2@test.com"
}
]
},
{
"name": "List 2",
"addresses": [
{
"name": null,
"address": "addr3@test.com"
},
{
"name": null,
"address": "addr4@test.com"
}
]
},
{
"name": null,
"addresses": [
{
"name": null,
"address": "addr5@test.com"
},
{
"name": null,
"address": "addr6@test.com"
}
]
}
]
}
},
{
"header": "\"List 1\": addr1@test.com, addr2@test.com; \"List 2\": addr3@test.com, addr4@test.com; addr5@test.com, addr6@test.com\n",
"expected": {
"GroupList": [
{
"name": "List 1",
"addresses": [
{
"name": null,
"address": "addr1@test.com"
},
{
"name": null,
"address": "addr2@test.com"
}
]
},
{
"name": "List 2",
"addresses": [
{
"name": null,
"address": "addr3@test.com"
},
{
"name": null,
"address": "addr4@test.com"
}
]
},
{
"name": null,
"addresses": [
{
"name": null,
"address": "addr5@test.com"
},
{
"name": null,
"address": "addr6@test.com"
}
]
}
]
}
},
{
"header": "\"=?utf-8?b?VGjDrXMgw61zIHbDoWzDrWQgw5pURjg=?=\": addr1@test.com, addr2@test.com; =?utf-8?b?VGjDrXMgw61zIHbDoWzDrWQgw5pURjg=?=: addr3@test.com, addr4@test.com; addr5@test.com, addr6@test.com\n",
"expected": {
"GroupList": [
{
"name": "Thís ís válíd ÚTF8",
"addresses": [
{
"name": null,
"address": "addr1@test.com"
},
{
"name": null,
"address": "addr2@test.com"
}
]
},
{
"name": "Thís ís válíd ÚTF8",
"addresses": [
{
"name": null,
"address": "addr3@test.com"
},
{
"name": null,
"address": "addr4@test.com"
}
]
},
{
"name": null,
"addresses": [
{
"name": null,
"address": "addr5@test.com"
},
{
"name": null,
"address": "addr6@test.com"
}
]
}
]
}
},
{
"header": "<http://www.host.com/list/archive/> (Web Archive)\n",
"expected": {
"Address": {
"name": "Web Archive",
"address": "http://www.host.com/list/archive/"
}
}
},
{
"header": "<mailto:archive@host.com?subject=index%20list>\n",
"expected": {
"Address": {
"name": null,
"address": "mailto:archive@host.com?subject=index%20list"
}
}
},
{
"header": "<mailto:moderator@host.com> (Postings are Moderated)\n",
"expected": {
"Address": {
"name": "Postings are Moderated",
"address": "mailto:moderator@host.com"
}
}
},
{
"header": "(Use this command to join the list)\n <mailto:list-manager@host.com?body=subscribe%20list>\n",
"expected": {
"Address": {
"name": "Use this command to join the list",
"address": "mailto:list-manager@host.com?body=subscribe%20list"
}
}
},
{
"header": "<http://www.host.com/list.cgi?cmd=sub&lst=list>,\n <mailto:list-manager@host.com?body=subscribe%20list>\n",
"expected": {
"AddressList": [
{
"name": null,
"address": "http://www.host.com/list.cgi?cmd=sub&lst=list"
},
{
"name": null,
"address": "mailto:list-manager@host.com?body=subscribe%20list"
}
]
}
},
{
"header": "NO (posting not allowed on this list)\n",
"expected": {
"Address": {
"name": "posting not allowed on this list",
"address": "NO"
}
}
},
{
"header": "<ftp://ftp.host.com/list.txt> (FTP),\n <mailto:list@host.com?subject=help>\n",
"expected": {
"AddressList": [
{
"name": "FTP",
"address": "ftp://ftp.host.com/list.txt"
},
{
"name": null,
"address": "mailto:list@host.com?subject=help"
}
]
}
},
{
"header": "<http://www.host.com/list/>, <mailto:list-info@host.com>\n",
"expected": {
"AddressList": [
{
"name": null,
"address": "http://www.host.com/list/"
},
{
"name": null,
"address": "mailto:list-info@host.com"
}
]
}
},
{
"header": "(Use this command to get off the list)\n <mailto:list-manager@host.com?body=unsubscribe%20list>\n",
"expected": {
"Address": {
"name": "Use this command to get off the list",
"address": "mailto:list-manager@host.com?body=unsubscribe%20list"
}
}
},
{
"header": "<http://www.host.com/list.cgi?cmd=unsub&lst=list>,\n <mailto:list-request@host.com?subject=unsubscribe>\n",
"expected": {
"AddressList": [
{
"name": null,
"address": "http://www.host.com/list.cgi?cmd=unsub&lst=list"
},
{
"name": null,
"address": "mailto:list-request@host.com?subject=unsubscribe"
}
]
}
},
{
"header": "<mailto:listmom@host.com> (Contact Person for Help)\n",
"expected": {
"Address": {
"name": "Contact Person for Help",
"address": "mailto:listmom@host.com"
}
}
},
{
"header": "\"\\\\\\\\\\\\\\\\S. NIG\\\\\\\\\\\\\\\\\" <first.last@host.com>",
"expected": {
"Address": {
"name": "\\\\\\\\S. NIG\\\\\\\\",
"address": "first.last@host.com"
}
}
}
]

Some files were not shown because too many files have changed in this diff Show More