[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
+8 -14
View File
@@ -2,8 +2,8 @@
use base64::Engine;
use epistula_core::mime::{MAX_MESSAGE_BYTES, ParseError, parse};
use epistula_core::sanitize::{InlineImage, SanitizeOptions, sanitize};
use epistula_core::safe_filename;
use epistula_core::sanitize::{InlineImage, SanitizeOptions, sanitize};
use proptest::prelude::*;
use std::collections::HashMap;
@@ -31,8 +31,8 @@ fn noise(len: usize, mut seed: u64) -> Vec<u8> {
}
const PNG_1X1: &[u8] = &[
0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0, 0, 0, 0x0D, 0x49, 0x48, 0x44, 0x52, 0, 0, 0, 1, 0, 0,
0, 1, 8, 6, 0, 0, 0, 0x1F, 0x15, 0xC4, 0x89,
0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0, 0, 0, 0x0D, 0x49, 0x48, 0x44, 0x52, 0, 0, 0, 1, 0, 0, 0, 1, 8,
6, 0, 0, 0, 0x1F, 0x15, 0xC4, 0x89,
];
fn nested_fixture() -> Vec<u8> {
@@ -120,10 +120,8 @@ fn inline_cid_image_becomes_a_data_uri_in_the_reader() {
inline.content_id.clone().unwrap(),
InlineImage { content_type: &inline.content_type, data: &inline.data },
);
let out = sanitize(
m.html.as_deref().unwrap(),
&SanitizeOptions { load_remote_images: false, inline_images: images },
);
let out =
sanitize(m.html.as_deref().unwrap(), &SanitizeOptions { load_remote_images: false, inline_images: images });
assert!(out.html.contains("data&#58;image/png;base64,"), "{}", out.html);
assert!(!out.html.contains("cid"), "{}", out.html);
assert_eq!(out.blocked_images, 0);
@@ -153,7 +151,8 @@ fn broken_charsets_do_not_panic_and_keep_text() {
let m = parse(unknown).unwrap();
assert!(m.text.unwrap().contains("ok"));
let invalid_utf8 = b"Subject: =?UTF-8?B?/w==?=\r\nContent-Type: text/plain; charset=utf-8\r\n\r\nbad \xFF\xFE bytes\r\n";
let invalid_utf8 =
b"Subject: =?UTF-8?B?/w==?=\r\nContent-Type: text/plain; charset=utf-8\r\n\r\nbad \xFF\xFE bytes\r\n";
let m = parse(invalid_utf8).unwrap();
assert!(m.text.unwrap().contains("bytes"));
@@ -215,12 +214,7 @@ fn two_hundred_kilobyte_header_block() {
#[test]
fn hostile_filenames_in_messages_are_made_safe() {
let names = [
"../../../etc/passwd",
"..\\..\\Windows\\win.ini",
"CON.txt",
"invoice\u{202E}fdp.exe",
];
let names = ["../../../etc/passwd", "..\\..\\Windows\\win.ini", "CON.txt", "invoice\u{202E}fdp.exe"];
let mut raw = String::from("Subject: files\r\nContent-Type: multipart/mixed; boundary=f\r\n\r\n");
for name in names {
raw.push_str(&format!(