[core] Tests: the mandatory suites, red against the API stubs (55 tests)
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
//! Incoming rules: conditions on From / To / Subject ("contains", case-insensitive, all must hold), one action
|
||||
//! (move to a folder), first match wins. The model is Sieve's `header :contains` + `fileinto`, so V2 can compile
|
||||
//! the same rules to a server-side script (`to_sieve`).
|
||||
|
||||
use crate::Address;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum Field {
|
||||
From,
|
||||
/// To and Cc.
|
||||
To,
|
||||
Subject,
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct Condition {
|
||||
pub field: Field,
|
||||
pub contains: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct Rule {
|
||||
pub name: String,
|
||||
pub conditions: Vec<Condition>,
|
||||
pub folder: String,
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for Rule {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_struct("Rule").field("conditions", &self.conditions.len()).finish_non_exhaustive()
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for Condition {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_struct("Condition").field("field", &self.field).finish_non_exhaustive()
|
||||
}
|
||||
}
|
||||
|
||||
/// Why a rule cannot be saved.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum RuleError {
|
||||
NoConditions,
|
||||
EmptyText,
|
||||
NoFolder,
|
||||
}
|
||||
|
||||
impl Rule {
|
||||
/// A rule with no condition, an empty text or no folder would match everything or nothing.
|
||||
pub fn validate(&self) -> Result<(), RuleError> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
/// The rule "Rule from this mail": sender address -> folder.
|
||||
pub fn from_sender(sender: &Address, folder: &str) -> Rule {
|
||||
let _ = (sender, folder);
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
/// What a rule looks at.
|
||||
pub struct RuleMessage<'a> {
|
||||
pub from: &'a [Address],
|
||||
pub to: &'a [Address],
|
||||
pub cc: &'a [Address],
|
||||
pub subject: &'a str,
|
||||
}
|
||||
|
||||
/// The first valid rule whose conditions all hold, or `None` (the message stays where it is).
|
||||
pub fn first_match<'r>(rules: &'r [Rule], message: &RuleMessage<'_>) -> Option<&'r Rule> {
|
||||
let _ = (rules, message);
|
||||
todo!()
|
||||
}
|
||||
|
||||
/// The same rules as a Sieve script (RFC 5228 + fileinto + RFC 5051 unicode-casemap).
|
||||
pub fn to_sieve(rules: &[Rule]) -> String {
|
||||
let _ = rules;
|
||||
todo!()
|
||||
}
|
||||
Reference in New Issue
Block a user