[core] V0.1: parse, compose, reply/forward, safe names, threading, rules + Sieve, sanitiser, search (55 tests green)

This commit is contained in:
2026-11-08 14:11:27 +01:00
parent c59480a0c0
commit e98e626c76
14 changed files with 1276 additions and 75 deletions
+14 -11
View File
@@ -3,8 +3,8 @@
use epistula_core::rules::RuleError;
use epistula_core::search::FTS_COLUMNS;
use epistula_core::{
Address, Condition, Field, Rule, RuleMessage, ThreadInput, first_match, normalize_subject, parse_query,
thread, to_sieve,
Address, Condition, Field, Rule, RuleMessage, ThreadInput, first_match, normalize_subject, parse_query, thread,
to_sieve,
};
use proptest::prelude::*;
@@ -54,10 +54,8 @@ fn references_join_across_a_missing_message() {
#[test]
fn a_reply_that_arrives_before_its_parent_still_joins() {
let t = thread(&[
msg(7, Some("b@x"), &["a@x"], &["a@x"], "Re: Plan", 200),
msg(9, Some("a@x"), &[], &[], "Plan", 100),
]);
let t =
thread(&[msg(7, Some("b@x"), &["a@x"], &["a@x"], "Re: Plan", 200), msg(9, Some("a@x"), &[], &[], "Plan", 100)]);
assert_eq!(t, vec![9, 9], "thread id = earliest message by date");
}
@@ -131,10 +129,8 @@ fn rule(name: &str, conditions: &[(Field, &str)], folder: &str) -> Rule {
#[test]
fn first_match_wins() {
let rules = vec![
rule("bank", &[(Field::From, "@bank.cz")], "Bank"),
rule("all-from-cz", &[(Field::From, ".cz")], "Czech"),
];
let rules =
vec![rule("bank", &[(Field::From, "@bank.cz")], "Bank"), rule("all-from-cz", &[(Field::From, ".cz")], "Czech")];
let from = [addr(None, "info@bank.cz")];
let m = RuleMessage { from: &from, to: &[], cc: &[], subject: "Výpis" };
assert_eq!(first_match(&rules, &m).unwrap().folder, "Bank");
@@ -261,7 +257,14 @@ fn search_finds_diacritics_insensitively() {
FTS_COLUMNS.join(", ")
))
.unwrap();
for (query, hits) in [("vylet", 1), ("from:anna", 1), ("from:anna@example.com", 1), ("subject:sobot", 1), ("to:anna", 0), ("mapa", 1)] {
for (query, hits) in [
("vylet", 1),
("from:anna", 1),
("from:anna@example.com", 1),
("subject:sobot", 1),
("to:anna", 0),
("mapa", 1),
] {
let expr = parse_query(query).fts_match().unwrap();
let n: i64 = db.query_row("SELECT count(*) FROM s WHERE s MATCH ?1", [&expr], |r| r.get(0)).unwrap();
assert_eq!(n, hits, "{query} -> {expr}");