[core] Tests: the mandatory suites, red against the API stubs (55 tests)
This commit is contained in:
+58
@@ -0,0 +1,58 @@
|
||||
//! `epistula-core`: everything Epistula Domi does with mail content, kept pure so it can be read and tested.
|
||||
//!
|
||||
//! No I/O, no clock, no randomness, no network: Message-IDs and dates are parameters. Every byte of an
|
||||
//! incoming message is hostile input. Nothing here panics on it.
|
||||
|
||||
pub mod compose;
|
||||
pub mod filename;
|
||||
pub mod mime;
|
||||
pub mod rules;
|
||||
pub mod sanitize;
|
||||
pub mod search;
|
||||
pub mod thread;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// One mailbox: an optional display name and an address.
|
||||
#[derive(Clone, PartialEq, Eq, Hash, Serialize, Deserialize, Default)]
|
||||
pub struct Address {
|
||||
pub name: Option<String>,
|
||||
pub email: String,
|
||||
}
|
||||
|
||||
impl Address {
|
||||
pub fn new(name: Option<&str>, email: &str) -> Address {
|
||||
Address {
|
||||
name: name.map(str::trim).filter(|n| !n.is_empty()).map(str::to_owned),
|
||||
email: email.trim().to_owned(),
|
||||
}
|
||||
}
|
||||
|
||||
/// `Name <email>` or `email`: what rules and search match against.
|
||||
pub fn display(&self) -> String {
|
||||
match &self.name {
|
||||
Some(name) => format!("{name} <{}>", self.email),
|
||||
None => self.email.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
/// The same mailbox, ignoring the display name and the case of the address.
|
||||
pub fn same_mailbox(&self, other: &Address) -> bool {
|
||||
self.email.trim().eq_ignore_ascii_case(other.email.trim())
|
||||
}
|
||||
}
|
||||
|
||||
/// Addresses are personal data: `Debug` never prints them (they could end up in a log).
|
||||
impl std::fmt::Debug for Address {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.write_str("Address([redacted])")
|
||||
}
|
||||
}
|
||||
|
||||
pub use compose::{Draft, OutAttachment, ReplyMode, compose, forward, message_id, reply};
|
||||
pub use filename::safe_filename;
|
||||
pub use mime::{Attachment, ParseError, Parsed, parse};
|
||||
pub use rules::{Condition, Field, Rule, RuleMessage, first_match, to_sieve};
|
||||
pub use sanitize::{SanitizeOptions, Sanitized, sanitize, text_to_html};
|
||||
pub use search::{Query, parse_query};
|
||||
pub use thread::{ThreadInput, normalize_subject, thread};
|
||||
Reference in New Issue
Block a user