diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..331aa70 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,1260 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "ammonia" +version = "4.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f45dfa685e1ec33b1bf1a3b93b8047cbdbef41b6040deebbe6bea7720a45574" +dependencies = [ + "cssparser", + "html5ever", + "maplit", + "url", +] + +[[package]] +name = "autocfg" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53" + +[[package]] +name = "base64" +version = "0.23.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac07cdecf99051d9a5238b80f35af32cdeba5b336e55d957b318b50137e18da5" + +[[package]] +name = "bit-set" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56d87354e4229f54a44f7bf2435906a4656dba36026ab6eaca629a2c436a691c" +dependencies = [ + "bit-vec", +] + +[[package]] +name = "bit-vec" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5727b15fa97d4f4fee0a3b7c3d550ed0269f54329207b86388de918604e31269" +dependencies = [ + "borsh", + "serde", +] + +[[package]] +name = "bitflags" +version = "2.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06" + +[[package]] +name = "borsh" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "553c5d846a6ba5150c65e3b1b8ec073bcf1abc20f9b7220de384a4443ea4e20a" +dependencies = [ + "borsh-derive", + "bytes", + "cfg_aliases", +] + +[[package]] +name = "borsh-derive" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12cdfe656708a01f89b451a7d36466e6fe6c414de0aa18fc54f864f6f9ca9f56" +dependencies = [ + "once_cell", + "proc-macro-crate", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "bumpalo" +version = "3.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649" + +[[package]] +name = "bytes" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04" + +[[package]] +name = "cc" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ff2a8126fff0f8c839080d619675a585e61720bb12d2baceae45769fd66f155" +dependencies = [ + "find-msvc-tools", + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600" + +[[package]] +name = "cfg_aliases" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f079e83a288787bcd14a6aea84cee5c87a67c5a3e660c30f557a3d24761b3527" + +[[package]] +name = "chacha20" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65c35e4b699c7e15ccbe7ee35c005e4fc0a278d22238a2857e6ce2dadeda1b06" +dependencies = [ + "cfg-if", + "cpufeatures", + "rand_core", +] + +[[package]] +name = "core_detect" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f8f80099a98041a3d1622845c271458a2d73e688351bf3cb999266764b81d48" + +[[package]] +name = "cpufeatures" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca28b0ae3115b884660db4118d803791fd6756b6e88f39c0f3f7859060d7566" +dependencies = [ + "libc", +] + +[[package]] +name = "cssparser" +version = "0.38.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11119743ad110e8c1bdccd930d7f5c30c99e5fc76a7b63ec9807e84eef0c5f59" +dependencies = [ + "dtoa-short", + "itoa", + "smallvec", +] + +[[package]] +name = "displaydoc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6232dd377dcc64799954cbd3a9bb882e9cdc1308ccd87b1c098f1fb2eaf82a8" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dtoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c3cf4824e2d5f025c7b531afcb2325364084a16806f6d47fbc1f5fbd9960590" + +[[package]] +name = "dtoa-short" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd1511a7b6a56299bd043a9c167a6d2bfb37bf84a6dfceaba651168adfb43c87" +dependencies = [ + "dtoa", +] + +[[package]] +name = "encodify" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e95d6e27686e1d6991a3077f4dbec9d33d18903466d234165ad86cd08c3ebc79" +dependencies = [ + "memchr", + "simdutf8", +] + +[[package]] +name = "epistula-core" +version = "0.1.0" +dependencies = [ + "ammonia", + "base64", + "mail-builder", + "mail-parser", + "proptest", + "rusqlite", + "serde", +] + +[[package]] +name = "equivalent" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00d174d5400e5e8fd687ad1049e2f578285fa914201b1af7e8b112a4546bd826" + +[[package]] +name = "errno" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "fallible-iterator" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649" + +[[package]] +name = "fallible-streaming-iterator" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a" + +[[package]] +name = "fastrand" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da7c62ceae207dd37ea5b845da6a0696c799f85e97da1ab5b7910be3c1c80223" + +[[package]] +name = "find-msvc-tools" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c66915cc5391097de7a2b0b972e8505aa33c0df401fd3a6811dbdb32881ba48" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foldhash" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb" + +[[package]] +name = "form_urlencoded" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futures-core" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e" + +[[package]] +name = "futures-task" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd417de3d1d015fc3bfd2b1ea46dfc7bab72ef86f1cc7cc9c78e728b34a6d1fd" + +[[package]] +name = "futures-util" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc" +dependencies = [ + "futures-core", + "futures-task", + "pin-project-lite", + "slab", +] + +[[package]] +name = "getrandom" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099" +dependencies = [ + "cfg-if", + "libc", + "r-efi", + "rand_core", +] + +[[package]] +name = "hashbrown" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" +dependencies = [ + "foldhash", +] + +[[package]] +name = "hashify" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04a037b1848eada162d6534c206770180e6bfc0eaa97292250c3e7179d8b1f73" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "hashlink" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a596f1b20ed2cc5ecac41a164aaebc7258057060f06c0cf7a2ba3991ee7990fb" +dependencies = [ + "hashbrown", +] + +[[package]] +name = "html5ever" +version = "0.40.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "456a1a377e608e555d22ddab27ac0114bc7a7b4199078108e34c2aeae6c9b130" +dependencies = [ + "log", + "markup5ever", + "memchr", +] + +[[package]] +name = "icu_collections" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe090a42a0d3140fed8c63263ed1fecc02422cb2f4bfe55cd8de2de1b8e105dd" +dependencies = [ + "displaydoc", + "potential_utf", + "utf8_iter", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locale_core" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25d29b57c17c6528d0dc4c2141cfa2d08200465acb537a3909c8b9b8a4a984c0" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_normalizer" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "404a3b8c486f205c87fe7f23ab6894d84a4ad76d6e4671ae1981ba7def87c599" +dependencies = [ + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20f0088bfb7441f7a37fa0c9e20cb1e9cba1cac6b9ce8cd2a6dc44294f8e8cbc" + +[[package]] +name = "icu_properties" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ea83d991c56158f7cf898bf86436c1dfe7c07ee82fe88951f2695c9f37a379f" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_locale_core", + "icu_properties_data", + "icu_provider", + "zerotrie", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b98f29af82d02b163fe50161388350e743bb3107cc8e8c2f7314cb505faddfcf" + +[[package]] +name = "icu_provider" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413099315636c588ee8f011190b329b971a09a8fae9d157e01dcae8379468514" +dependencies = [ + "displaydoc", + "icu_locale_core", + "writeable", + "yoke", + "zerofrom", + "zerotrie", + "zerovec", +] + +[[package]] +name = "idna" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb68373c0d6620ef8105e855e7745e18b0d00d3bdb07fb532e434244cdb9a714" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + +[[package]] +name = "indexmap" +version = "2.14.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc4e190f5d26ca7051642629da2c52fc03bde85a03197c99408dcd291734c855" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "itoa" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" + +[[package]] +name = "js-sys" +version = "0.3.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8dc09d2154098bbf4ef54eab6b117a3c24cbbffe94046b16ee6d6d4510584d3a" +dependencies = [ + "cfg-if", + "futures-util", + "wasm-bindgen", +] + +[[package]] +name = "libc" +version = "0.2.191" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a" + +[[package]] +name = "libsqlite3-sys" +version = "0.39.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14a5f01b87b92705d07b433c06f96cbc764637d81a0bffb5734ce17cf0f9a2b3" +dependencies = [ + "cc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "linux-raw-sys" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53" + +[[package]] +name = "litemap" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47d9d19d1d6efa0109d2f65ff4c85cddd50bd572e5a00127ab10987290bcefae" + +[[package]] +name = "lock_api" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" +dependencies = [ + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d15f86d12da44cd8d4ec3c73984537eb7f4cadcb9776a575a0a8a05ca11005c" + +[[package]] +name = "mail-builder" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aca3ad941e4c466402151719d6b4cea4bdfcb212b11e5970afa75e7d28c6502a" +dependencies = [ + "encodify", + "web-time", +] + +[[package]] +name = "mail-parser" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d4ea9311ef3ca6189aa85c5f984bd47b2f12079bcabae28917d900ab26c9ecc" +dependencies = [ + "encodify", + "hashify", + "memchr", + "simdutf8", +] + +[[package]] +name = "maplit" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" + +[[package]] +name = "markup5ever" +version = "0.40.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ab3dc68ac4a0f5719e560136778c1ee716e296030d75dbd4484e37e39e3a842" +dependencies = [ + "log", + "tendril", + "web_atoms", +] + +[[package]] +name = "memchr" +version = "2.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" + +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "once_cell" +version = "1.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" + +[[package]] +name = "parking_lot" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-link", +] + +[[package]] +name = "percent-encoding" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" + +[[package]] +name = "phf" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "010378780309880b08997fae13be7834dba947d36393bd372f2b1556deb2a2f6" +dependencies = [ + "phf_shared", + "serde", +] + +[[package]] +name = "phf_codegen" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41b585a510fb76fdebead6897982ef2a03a21d8e6cbcca904999742a4afc6ffe" +dependencies = [ + "phf_generator", + "phf_shared", +] + +[[package]] +name = "phf_generator" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aeb62e0959d5a1bebc965f4d15d9e2b7cea002b6b0f5ba8cde6cc26738467100" +dependencies = [ + "fastrand", + "phf_shared", +] + +[[package]] +name = "phf_shared" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6fd9027e2d9319be6349febd1db4e8d02aa544921200c9b777720ac34a3aa89" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" + +[[package]] +name = "pkg-config" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6b464fbc74e149a392436b17d523f769e057cb6877f6a5c4618bc6f11800548" + +[[package]] +name = "potential_utf" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d83eb9bc6d8e5cf568e7a1101d60ee05e81ed50ea106026f3d18deeb046d7661" +dependencies = [ + "zerovec", +] + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "proc-macro-crate" +version = "3.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e67ba7e9b2b56446f1d419b1d807906278ffa1a658a8a5d8a39dcb1f5a78614f" +dependencies = [ + "toml_edit", +] + +[[package]] +name = "proc-macro2" +version = "1.0.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "proptest" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8530004ccb15eae51c7e40009fbe317f341f804db54dc033eec1c50be28cfa0" +dependencies = [ + "bit-set", + "bit-vec", + "bitflags", + "chacha20", + "core_detect", + "num-traits", + "rand", + "rand_xorshift", + "regex-syntax", + "rusty-fork", + "tempfile", + "unarray", +] + +[[package]] +name = "quick-error" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" + +[[package]] +name = "quote" +version = "1.0.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "r-efi" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" + +[[package]] +name = "rand" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65c9fb96cbc91e3478eaae79a69fcd3f1ae4ad052e471fe6732fff548984b4af" +dependencies = [ + "getrandom", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69" + +[[package]] +name = "rand_xorshift" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60aa6af80be32871323012e02e6e65f8a7cc7890931ae421d217ad8fe0df2ccf" +dependencies = [ + "rand_core", +] + +[[package]] +name = "redox_syscall" +version = "0.5.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" +dependencies = [ + "bitflags", +] + +[[package]] +name = "regex-syntax" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4" + +[[package]] +name = "rsqlite-vfs" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "353b74f9810d5b085b6c42c9d86a5f0fdb795553235cdd48753b32e3809d18a7" +dependencies = [ + "thiserror", +] + +[[package]] +name = "rusqlite" +version = "0.41.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da9bba6f3506135e120a6586df05be18b48d18896600646a4bec8f993d91a594" +dependencies = [ + "bitflags", + "fallible-iterator", + "fallible-streaming-iterator", + "hashlink", + "libsqlite3-sys", + "smallvec", + "sqlite-wasm-rs", +] + +[[package]] +name = "rustix" +version = "1.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5e76742e5294153d4dde1207dbec5bdd81eef6fabdc0d2118babadabfd858aa" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys", +] + +[[package]] +name = "rustversion" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f" + +[[package]] +name = "rusty-fork" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc6bf79ff24e648f6da1f8d1f011e9cac26491b619e6b9280f2b47f1774e6ee2" +dependencies = [ + "fnv", + "quick-error", + "tempfile", + "wait-timeout", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "serde" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "shlex" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" + +[[package]] +name = "simdutf8" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3a9fe34e3e7a50316060351f37187a3f546bce95496156754b601a5fa71b76e" + +[[package]] +name = "siphasher" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33f4fe9184a62d842c9ef383018f3306d8ba224fd9d836f56d7288308847c256" + +[[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + +[[package]] +name = "smallvec" +version = "1.16.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "149309498a5f7334b12ddae0cad8aba81ce785fe91755068867e017cf98fee46" + +[[package]] +name = "sqlite-wasm-rs" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36bd8e29bf08189a005b2df1df99823aa0861cabe9044e5f31ed54ca292ee618" +dependencies = [ + "cc", + "rsqlite-vfs", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" + +[[package]] +name = "string_cache" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffa8a5dbe8b3f0bbe29d4c3225daafaeead63afdc1b65fc4c01a1384166038e6" +dependencies = [ + "new_debug_unreachable", + "parking_lot", + "phf_shared", + "precomputed-hash", +] + +[[package]] +name = "string_cache_codegen" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "928dcdf75e47626b3617a976ec205d9f057584c371c1f23b782129268d0e6edc" +dependencies = [ + "phf_generator", + "phf_shared", + "proc-macro2", + "quote", +] + +[[package]] +name = "syn" +version = "3.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d78c8dee4c7bf0e14673097256fed6142ce9d3b85a408189d07482442145823b" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "synstructure" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "901704edd0dfe137f1987838ee4f259e4e063c31371bdb423f7ae38ec6f77f02" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tempfile" +version = "3.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd" +dependencies = [ + "fastrand", + "getrandom", + "once_cell", + "rustix", + "windows-sys", +] + +[[package]] +name = "tendril" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fed54709c5b3a53d09bb1c113ea4f5ceafd1e772ddcb0030a82e1d56c087b08" +dependencies = [ + "new_debug_unreachable", +] + +[[package]] +name = "thiserror" +version = "2.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09e52cb86a36cede5cb101bf8908837b3e4c6e5e59fe7fd85c23fb56200d189e" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe5197923287db20a58125f0bc85c062f7f2c892de97b18c356f9efb14b28524" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tinystr" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abc840c238154d58f9e86b2792261edfde565a17696e1cda1a449de27979801a" +dependencies = [ + "displaydoc", + "zerovec", +] + +[[package]] +name = "toml_datetime" +version = "1.1.3+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "173f25c883cd2176a2d8212155638c0a60d484a9d84546d270866f40f56b6e49" +dependencies = [ + "serde_core", +] + +[[package]] +name = "toml_edit" +version = "0.25.19+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd43688c4858d7264ae1cf9a9f874a67c3feb74a883b1cd7bebd6a4ea8307218" +dependencies = [ + "indexmap", + "toml_datetime", + "toml_parser", + "winnow", +] + +[[package]] +name = "toml_parser" +version = "1.1.5+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baa693a8032d7e1cada7d0041e96126df243179ff061456783ac7f12bda4744c" +dependencies = [ + "winnow", +] + +[[package]] +name = "unarray" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94" + +[[package]] +name = "unicode-ident" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563" + +[[package]] +name = "url" +version = "2.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", + "serde", +] + +[[package]] +name = "utf8_iter" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af3bd9d3e571c26fcce9d033b87ea5ab061b8d2ffe9b7a5675d810d68f03edf0" +dependencies = [ + "utf_types", +] + +[[package]] +name = "utf_types" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a3b425286980a367278453f3b6d28cdcb134b574e5a35824a6ff5eebad50bb6" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "wait-timeout" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ac3b126d3914f9849036f826e054cbabdc8519970b8998ddaf3b5bd3c65f11" +dependencies = [ + "libc", +] + +[[package]] +name = "wasm-bindgen" +version = "0.2.130" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0181c14ddd6c7b8b0b0132a5f1ea2f32be0d893cd3ea97b6e3b28886b8a3d1c" +dependencies = [ + "cfg-if", + "rustversion", + "wasm-bindgen-macro", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.130" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e931a02a39abdbf66966fc35902b5ed58344750a70885bed4ebb3d8eaf28ed9" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.130" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ca4b54280e455bd831e33a6b8e734baf432fe63fbc35c42ac14ce67a043a53a" +dependencies = [ + "bumpalo", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.130" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b1f9c3798725016c6ee5f2f57869ec0831e8bbc0ab0310a86e787e97f41389e" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "web-time" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "web_atoms" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7572660c8890448ba236b7376f27e389c6a7e1c70195622faced601f855c0ada" +dependencies = [ + "phf", + "phf_codegen", + "string_cache", + "string_cache_codegen", +] + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] + +[[package]] +name = "winnow" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3b93199df0ab874cdf0c6a94f0a0dc3423fe41f1cafb62b8bd7b1deb277aef" +dependencies = [ + "memchr", +] + +[[package]] +name = "writeable" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ad82d2a33cdc9674dc7465672f271e096168fcdbe0f799d9e6db8c5892679dc" + +[[package]] +name = "yoke" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "417ef3fcf6c300b7dbd25c85531a746931c02ad536f3cf4786ed1e88223340b3" +dependencies = [ + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec8ebde2db3681e8c9980cc27822030e68752690ddfa9473e739aeb4dbde6d71" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zerofrom" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ec05a11813ea801ff6d75110ad09cd0824ddba17dfe17128ea0d5f68e6c5272" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f75b4683f6c7f45248d4d64056a24298c6281e0993356d7d1b4a1a962ef10d4a" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zerotrie" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ea269c3bd32f0a32c321907a2ae912ba6f4649bb0fc764a15627e99a7095a3f" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", +] + +[[package]] +name = "zerovec" +version = "0.11.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f58a2799cfe9a1670c7ea8edbd52ef8edb93cb37a7f83bf31ba9e35d9dae6a40" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.11.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3743ddbf47738d929cd1ae2e199d40d0162979dfe31aef8ae646d2bf00bf97a" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..a571f97 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "epistula-core" +version = "0.1.0" +edition = "2024" +rust-version = "1.85" +license = "MPL-2.0" +description = "Epistula Domi core: MIME parse and compose, threading, rules, HTML sanitising, search queries. Pure, no I/O." +repository = "https://gitea.marek-novak.cz/mnovak/EpistulaPublic" +publish = false + +[dependencies] +ammonia = "4.2.4" +base64 = "0.23.1" +mail-builder = { version = "2.0.1", default-features = false } +mail-parser = "1.0.1" +serde = { version = "1.0.229", features = ["derive"] } + +[dev-dependencies] +proptest = "1.12.0" +rusqlite = { version = "0.41.1", features = ["bundled"] } + +[profile.test] +opt-level = 1 + +[profile.dev.package."*"] +opt-level = 2 diff --git a/src/compose.rs b/src/compose.rs new file mode 100644 index 0000000..61dd9a1 --- /dev/null +++ b/src/compose.rs @@ -0,0 +1,70 @@ +//! Composing outgoing mail (mail-builder), and the drafts for reply, reply all and forward. + +use crate::{Address, Parsed}; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Default)] +pub struct Draft { + pub from: Address, + pub to: Vec
, + pub cc: Vec
, + pub bcc: Vec
, + pub subject: String, + /// Line endings are `\n`. + pub text: String, + pub html: Option, + pub attachments: Vec, + /// Without angle brackets. + pub in_reply_to: Option, + pub references: Vec, +} + +#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct OutAttachment { + pub filename: String, + pub content_type: String, + pub data: Vec, +} + +impl std::fmt::Debug for Draft { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("Draft") + .field("to", &self.to.len()) + .field("attachments", &self.attachments.len()) + .finish_non_exhaustive() + } +} + +impl std::fmt::Debug for OutAttachment { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("OutAttachment").field("bytes", &self.data.len()).finish_non_exhaustive() + } +} + +#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub enum ReplyMode { + Sender, + All, +} + +/// A Message-ID from 16 random bytes the caller supplies and the sender's domain, without brackets. +pub fn message_id(random: [u8; 16], domain: &str) -> String { + let _ = (random, domain); + todo!() +} + +/// The RFC 5322 bytes of `draft`, with the given Message-ID (no brackets) and Date (Unix seconds). +pub fn compose(draft: &Draft, message_id: &str, date: i64) -> Vec { + let _ = (draft, message_id, date); + todo!() +} + +pub fn reply(original: &Parsed, me: &Address, mode: ReplyMode) -> Draft { + let _ = (original, me, mode); + todo!() +} + +pub fn forward(original: &Parsed, me: &Address) -> Draft { + let _ = (original, me); + todo!() +} diff --git a/src/filename.rs b/src/filename.rs new file mode 100644 index 0000000..f360f45 --- /dev/null +++ b/src/filename.rs @@ -0,0 +1,10 @@ +//! Attachment names from mail are hostile: `../../evil.exe`, `CON.txt`, `invoice\u{202E}fdp.exe`. + +/// The longest name kept, in characters (the extension is kept when cutting). +pub const MAX_FILENAME_CHARS: usize = 120; + +/// A name that is safe to create in any directory on Windows, Android and iOS, and that shows what it is. +pub fn safe_filename(raw: &str) -> String { + let _ = raw; + todo!() +} diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..85822eb --- /dev/null +++ b/src/lib.rs @@ -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, + 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 ` 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}; diff --git a/src/mime.rs b/src/mime.rs new file mode 100644 index 0000000..0352c1d --- /dev/null +++ b/src/mime.rs @@ -0,0 +1,87 @@ +//! Parsing a raw RFC 5322 message (mail-parser) into what the app stores and shows. + +use crate::Address; +use serde::{Deserialize, Serialize}; + +/// Larger messages are refused before parsing (Proton's own limit is 25 MB of attachments). +pub const MAX_MESSAGE_BYTES: usize = 64 * 1024 * 1024; +/// A subject longer than this is cut (characters). +pub const MAX_SUBJECT_CHARS: usize = 998; +/// At most this many addresses per field are kept. +pub const MAX_ADDRESSES: usize = 500; +/// At most this many attachments are kept; the rest are counted in `dropped_attachments`. +pub const MAX_ATTACHMENTS: usize = 500; + +#[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Default)] +pub struct Parsed { + pub message_id: Option, + pub in_reply_to: Vec, + pub references: Vec, + pub subject: String, + pub from: Vec
, + pub to: Vec
, + pub cc: Vec
, + pub reply_to: Vec
, + /// Seconds since the Unix epoch, from the Date header. + pub date: Option, + /// The Date header as RFC 822 text, for "On , wrote:". + pub date_text: Option, + /// Line endings are `\n`. + pub text: Option, + pub html: Option, + pub attachments: Vec, + pub dropped_attachments: usize, +} + +#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct Attachment { + /// Already safe for a file system (`safe_filename`). + pub filename: String, + pub content_type: String, + /// Without the angle brackets. + pub content_id: Option, + pub inline: bool, + pub data: Vec, +} + +/// Bodies and attachments are personal data: `Debug` prints sizes only. +impl std::fmt::Debug for Parsed { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("Parsed") + .field("text_len", &self.text.as_ref().map(String::len)) + .field("html_len", &self.html.as_ref().map(String::len)) + .field("attachments", &self.attachments.len()) + .finish_non_exhaustive() + } +} + +impl std::fmt::Debug for Attachment { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("Attachment") + .field("bytes", &self.data.len()) + .field("inline", &self.inline) + .finish_non_exhaustive() + } +} + +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum ParseError { + TooLarge, + NotMail, +} + +impl std::fmt::Display for ParseError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + ParseError::TooLarge => write!(f, "message larger than {MAX_MESSAGE_BYTES} bytes"), + ParseError::NotMail => f.write_str("not a mail message"), + } + } +} + +impl std::error::Error for ParseError {} + +pub fn parse(raw: &[u8]) -> Result { + let _ = raw; + todo!() +} diff --git a/src/rules.rs b/src/rules.rs new file mode 100644 index 0000000..f92f8b3 --- /dev/null +++ b/src/rules.rs @@ -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, + 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!() +} diff --git a/src/sanitize.rs b/src/sanitize.rs new file mode 100644 index 0000000..146acd4 --- /dev/null +++ b/src/sanitize.rs @@ -0,0 +1,40 @@ +//! HTML from mail -> HTML the reader may show. Allow-list (ammonia): no scripts, no event handlers, no forms, +//! no `javascript:` or `data:text/html` URLs, no CSS that runs or loads anything, remote images replaced by a +//! placeholder unless the user chose "Load images" for this message. + +use std::collections::HashMap; + +/// What an inline `cid:` image resolves to. +pub struct InlineImage<'a> { + pub content_type: &'a str, + pub data: &'a [u8], +} + +#[derive(Default)] +pub struct SanitizeOptions<'a> { + /// Keep `https:` / `http:` images (the user pressed "Load images" for this message). + pub load_remote_images: bool, + /// Inline parts by Content-ID (no brackets): `cid:` sources become `data:` URIs. + pub inline_images: HashMap>, +} + +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct Sanitized { + pub html: String, + /// Remote images replaced by the placeholder: show "Load images" only when this is not zero. + pub blocked_images: usize, +} + +/// The placeholder for a blocked remote image (a small grey square, SVG in a data URI: no script runs in ``). +pub const BLOCKED_IMAGE_SRC: &str = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCI+PHJlY3Qgd2lkdGg9IjI0IiBoZWlnaHQ9IjI0IiBmaWxsPSIjNDQ0Ii8+PC9zdmc+"; + +pub fn sanitize(html: &str, options: &SanitizeOptions<'_>) -> Sanitized { + let _ = (html, options); + todo!() +} + +/// A plain-text body as safe HTML (escaped, line breaks kept, links made clickable). +pub fn text_to_html(text: &str) -> String { + let _ = text; + todo!() +} diff --git a/src/search.rs b/src/search.rs new file mode 100644 index 0000000..2cd748b --- /dev/null +++ b/src/search.rs @@ -0,0 +1,32 @@ +//! The search box: free text plus `from:`, `to:`, `subject:`, `has:attachment`, `is:starred`, with +//! "quoted phrases". The query becomes an SQLite FTS5 expression in which every user term is a quoted string, +//! so no input can inject FTS5 syntax. + +#[derive(Clone, Debug, PartialEq, Eq, Default)] +pub struct Query { + pub text: Vec, + pub from: Vec, + pub to: Vec, + pub subject: Vec, + pub has_attachment: bool, + pub is_starred: bool, +} + +/// FTS5 column names the app's search table must use. +pub const FTS_COLUMNS: [&str; 5] = ["subject", "sender", "recipients", "body", "attachments"]; + +pub fn parse_query(input: &str) -> Query { + let _ = input; + todo!() +} + +impl Query { + pub fn is_empty(&self) -> bool { + todo!() + } + + /// The FTS5 `MATCH` expression, or `None` when there is no text to match (only flags). + pub fn fts_match(&self) -> Option { + todo!() + } +} diff --git a/src/thread.rs b/src/thread.rs new file mode 100644 index 0000000..07ee5a8 --- /dev/null +++ b/src/thread.rs @@ -0,0 +1,25 @@ +//! Conversations: Message-ID / In-Reply-To / References, with a normalised-subject fallback. + +/// What threading needs from one message. `id` is the app's local id. +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct ThreadInput { + pub id: u64, + pub message_id: Option, + pub in_reply_to: Vec, + pub references: Vec, + pub subject: String, + pub date: i64, +} + +/// `Re: Fwd: [list] Hello world` -> `hello world`. +pub fn normalize_subject(subject: &str) -> String { + let _ = subject; + todo!() +} + +/// The thread id of each input, in input order. A thread's id is the `id` of its earliest message +/// (by date, then id), so the result does not depend on input order. +pub fn thread(messages: &[ThreadInput]) -> Vec { + let _ = messages; + todo!() +} diff --git a/tests/compose.proptest-regressions b/tests/compose.proptest-regressions new file mode 100644 index 0000000..0f99bea --- /dev/null +++ b/tests/compose.proptest-regressions @@ -0,0 +1,7 @@ +# Seeds for failure cases proptest has generated in the past. It is +# automatically read and these particular cases re-run before any +# novel cases are generated. +# +# It is recommended to check this file in to source control so that +# everyone who runs the test benefits from these saved cases. +cc e5afee1f2e4ce59f6e7d9827da4a73afcbf8e1fb9864bd31e13543f3e41bcf37 # shrinks to d = Draft { to: 1, attachments: 0, .. } diff --git a/tests/compose.rs b/tests/compose.rs new file mode 100644 index 0000000..10a1616 --- /dev/null +++ b/tests/compose.rs @@ -0,0 +1,194 @@ +//! Mandatory: compose round trip, and the headers and bodies of reply, reply all and forward. + +use epistula_core::{Address, Draft, OutAttachment, ReplyMode, compose, forward, message_id, parse, reply}; +use proptest::prelude::*; + +fn me() -> Address { + Address::new(Some("Mark Novák"), "mark@example.cz") +} + +fn original() -> epistula_core::Parsed { + let raw = "From: Anna \r\n\ + To: Mark Novák , Jiří \r\n\ + Cc: eva@example.cz, MARK@example.cz\r\n\ + Subject: Výlet v sobotu\r\n\ + Date: Sat, 08 Nov 2026 10:00:00 +0100\r\n\ + Message-ID: \r\n\ + References: \r\n\ + In-Reply-To: \r\n\ + Content-Type: multipart/mixed; boundary=b\r\n\r\n\ + --b\r\nContent-Type: multipart/alternative; boundary=a\r\n\r\n\ + --a\r\nContent-Type: text/plain; charset=utf-8\r\n\r\nPojedeme v 8.\r\nVezmi deštník.\r\n\ + --a\r\nContent-Type: text/html; charset=utf-8\r\n\r\n

Pojedeme v 8.

\r\n\ + --a--\r\n\ + --b\r\nContent-Type: application/pdf\r\nContent-Disposition: attachment; filename=mapa.pdf\r\n\r\nPDFDATA\r\n\ + --b--\r\n"; + parse(raw.as_bytes()).unwrap() +} + +#[test] +fn reply_sets_threading_headers_and_quotes() { + let orig = original(); + let d = reply(&orig, &me(), ReplyMode::Sender); + assert_eq!(d.subject, "Re: Výlet v sobotu"); + assert_eq!(d.to, vec![Address::new(Some("Anna"), "anna@example.com")]); + assert!(d.cc.is_empty()); + assert_eq!(d.in_reply_to.as_deref(), Some("orig-2@example.com")); + assert_eq!(d.references, vec!["root-0@example.com", "orig-1@example.com", "orig-2@example.com"]); + assert!(d.text.contains("Anna wrote:"), "{}", d.text); + assert!(d.text.contains("> Pojedeme v 8.\n> Vezmi deštník."), "{}", d.text); + let html = d.html.as_deref().unwrap(); + assert!(html.contains("8"), "{html}"); + assert!(d.attachments.is_empty(), "a reply does not carry attachments"); + assert_eq!(d.from, me()); +} + +#[test] +fn reply_does_not_stack_prefixes_and_prefers_reply_to() { + let raw = b"From: list@example.com\r\nReply-To: Anna \r\nSubject: RE: Re: plan\r\nMessage-ID: \r\n\r\nhi\r\n"; + let d = reply(&parse(raw).unwrap(), &me(), ReplyMode::Sender); + assert_eq!(d.subject, "Re: plan"); + assert_eq!(d.to[0].email, "anna@example.com"); + assert_eq!(d.references, vec!["x@y"]); +} + +#[test] +fn reply_all_keeps_everyone_but_me_once() { + let d = reply(&original(), &me(), ReplyMode::All); + let to: Vec<_> = d.to.iter().map(|a| a.email.as_str()).collect(); + let cc: Vec<_> = d.cc.iter().map(|a| a.email.as_str()).collect(); + assert_eq!(to, vec!["anna@example.com"]); + assert_eq!(cc, vec!["jiri@example.cz", "eva@example.cz"]); +} + +#[test] +fn reply_to_my_own_sent_mail_goes_to_the_original_recipients() { + let raw = b"From: Mark \r\nTo: anna@example.com\r\nSubject: s\r\nMessage-ID: \r\n\r\nhi\r\n"; + let d = reply(&parse(raw).unwrap(), &me(), ReplyMode::Sender); + assert_eq!(d.to[0].email, "anna@example.com"); +} + +#[test] +fn forward_keeps_attachments_and_the_original() { + let orig = original(); + let d = forward(&orig, &me()); + assert_eq!(d.subject, "Fwd: Výlet v sobotu"); + assert!(d.to.is_empty() && d.cc.is_empty()); + assert_eq!(d.attachments.len(), 1); + assert_eq!(d.attachments[0].filename, "mapa.pdf"); + assert_eq!(d.attachments[0].content_type, "application/pdf"); + assert_eq!(d.attachments[0].data, orig.attachments[0].data); + assert!(d.text.contains("Forwarded message"), "{}", d.text); + assert!(d.text.contains("Subject: Výlet v sobotu"), "{}", d.text); + assert!(d.text.contains("Pojedeme v 8."), "{}", d.text); + assert!(d.html.as_deref().unwrap().contains("8")); + // Forwarded attachments survive compose -> parse. + let back = parse(&compose(&d, "fwd-1@example.cz", 1_794_128_400)).unwrap(); + assert_eq!(back.attachments.len(), 1); + assert_eq!(back.attachments[0].data, orig.attachments[0].data); +} + +#[test] +fn composed_reply_carries_in_reply_to_and_references() { + let d = reply(&original(), &me(), ReplyMode::All); + let raw = compose(&d, "reply-1@example.cz", 1_794_128_400); + let back = parse(&raw).unwrap(); + assert_eq!(back.message_id.as_deref(), Some("reply-1@example.cz")); + assert_eq!(back.in_reply_to, vec!["orig-2@example.com"]); + assert_eq!(back.references, vec!["root-0@example.com", "orig-1@example.com", "orig-2@example.com"]); + assert_eq!(back.date, Some(1_794_128_400)); +} + +#[test] +fn bcc_is_never_written_into_the_message() { + let d = Draft { + from: me(), + to: vec![Address::new(None, "anna@example.com")], + bcc: vec![Address::new(Some("Secret"), "hidden@example.cz")], + subject: "s".into(), + text: "t".into(), + ..Default::default() + }; + let raw = String::from_utf8(compose(&d, "b@example.cz", 0)).unwrap(); + assert!(!raw.contains("hidden@example.cz"), "{raw}"); + assert!(!raw.to_ascii_lowercase().contains("bcc:"), "{raw}"); +} + +#[test] +fn compose_is_deterministic() { + let d = forward(&original(), &me()); + assert_eq!(compose(&d, "same@example.cz", 5), compose(&d, "same@example.cz", 5)); +} + +#[test] +fn message_id_shape() { + let id = message_id([0xAB; 16], "example.cz"); + assert_eq!(id, format!("{}@example.cz", "ab".repeat(16))); + assert_ne!(message_id([1; 16], "example.cz"), message_id([2; 16], "example.cz")); +} + +fn address() -> impl Strategy { + ( + proptest::option::of("[A-Za-zÁČĎÉĚÍŇÓŘŠŤÚŮÝŽáčďéěíňóřšťúůýž][A-Za-zčřšžý .'-]{0,20}[a-zý]"), + "[a-z][a-z0-9._-]{0,10}[a-z0-9]@[a-z]{2,10}\\.(cz|com|org)", + ) + .prop_map(|(name, email)| Address::new(name.as_deref(), &email)) +} + +fn body_text() -> impl Strategy { + proptest::collection::vec("[A-Za-z0-9ěščřžýáíéúůĚŠČŘŽ€ .,!?:;()+-]{0,70}", 0..8) + .prop_map(|lines| lines.iter().map(|l| l.trim_end()).collect::>().join("\n")) +} + +fn attachment() -> impl Strategy { + ( + "[A-Za-z0-9_-]{1,20}", + prop_oneof![Just(("pdf", "application/pdf")), Just(("png", "image/png")), Just(("bin", "application/octet-stream"))], + proptest::collection::vec(any::(), 0..3000), + ) + .prop_map(|(stem, (ext, ct), data)| OutAttachment { + filename: format!("{stem}.{ext}"), + content_type: ct.into(), + data, + }) +} + +fn draft() -> impl Strategy { + ( + address(), + proptest::collection::vec(address(), 1..4), + proptest::collection::vec(address(), 0..3), + "[A-Za-z0-9ěščřžýáíé€][A-Za-z0-9ěščřžýáíé€ ,.!?:-]{0,120}[A-Za-z0-9ěščřžýáíé€]", + body_text(), + any::(), + proptest::collection::vec(attachment(), 0..3), + ) + .prop_map(|(from, to, cc, subject, text, with_html, attachments)| { + let html = with_html.then(|| { + format!("

{}

", text.replace('&', "&").replace('<', "<").replace('\n', "
")) + }); + Draft { from, to, cc, subject, text, html, attachments, ..Default::default() } + }) +} + +proptest! { + #![proptest_config(ProptestConfig::with_cases(300))] + + #[test] + fn parse_of_compose_is_identity(d in draft()) { + let raw = compose(&d, "prop@example.cz", 1_700_000_000); + let back = parse(&raw).unwrap(); + prop_assert_eq!(&back.subject, &d.subject); + prop_assert_eq!(&back.from, &vec![d.from.clone()]); + prop_assert_eq!(&back.to, &d.to); + prop_assert_eq!(&back.cc, &d.cc); + prop_assert_eq!(back.text.as_deref().unwrap_or("").trim_end(), d.text.trim_end()); + prop_assert_eq!(back.html.as_deref().map(str::trim_end), d.html.as_deref().map(str::trim_end)); + let files: Vec<_> = back.attachments.iter() + .map(|a| (a.filename.clone(), a.content_type.clone(), a.data.clone())).collect(); + let expected: Vec<_> = d.attachments.iter() + .map(|a| (a.filename.clone(), a.content_type.clone(), a.data.clone())).collect(); + prop_assert_eq!(files, expected); + } +} diff --git a/tests/mime.proptest-regressions b/tests/mime.proptest-regressions new file mode 100644 index 0000000..db1349c --- /dev/null +++ b/tests/mime.proptest-regressions @@ -0,0 +1,9 @@ +# Seeds for failure cases proptest has generated in the past. It is +# automatically read and these particular cases re-run before any +# novel cases are generated. +# +# It is recommended to check this file in to source control so that +# everyone who runs the test benefits from these saved cases. +cc 6998aa3983faeb709f1f5e13f945049ca486ff885fe786e0338eb4be3054a60c # shrinks to parts = [] +cc f85abeaf71fce0d1a52d1bab4ed0f7f512db98bf259645719f8acf72a525b044 # shrinks to raw = "" +cc b1b06966991973e916da1a3895fa747e94ac2def84cfb213b4c8fa6222a97119 # shrinks to raw = [] diff --git a/tests/mime.rs b/tests/mime.rs new file mode 100644 index 0000000..023b37d --- /dev/null +++ b/tests/mime.rs @@ -0,0 +1,354 @@ +//! Mandatory: MIME fixtures. Every fixture is built here in code (no corpora in git). + +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 proptest::prelude::*; +use std::collections::HashMap; + +fn b64(data: &[u8]) -> String { + let encoded = base64::engine::general_purpose::STANDARD.encode(data); + let mut out = String::with_capacity(encoded.len() + encoded.len() / 76 * 2); + for chunk in encoded.as_bytes().chunks(76) { + out.push_str(std::str::from_utf8(chunk).unwrap()); + out.push_str("\r\n"); + } + out +} + +/// Deterministic pseudo-random bytes (xorshift), so the 8 MB fixture needs no file. +fn noise(len: usize, mut seed: u64) -> Vec { + let mut out = Vec::with_capacity(len); + while out.len() < len { + seed ^= seed << 13; + seed ^= seed >> 7; + seed ^= seed << 17; + out.extend_from_slice(&seed.to_le_bytes()); + } + out.truncate(len); + out +} + +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, +]; + +fn nested_fixture() -> Vec { + format!( + "From: \"Anna Nováková\" \r\n\ + To: Mark , family@example.cz\r\n\ + Cc: =?UTF-8?Q?Ji=C5=99=C3=AD?= \r\n\ + Subject: =?UTF-8?B?UMWZw61sb2h5IGEgb2Jyw6F6a3k=?=\r\n\ + Date: Sat, 08 Nov 2026 10:00:00 +0100\r\n\ + Message-ID: \r\n\ + In-Reply-To: \r\n\ + References: \r\n\ + MIME-Version: 1.0\r\n\ + Content-Type: multipart/mixed; boundary=\"outer\"\r\n\ + \r\n\ + --outer\r\n\ + Content-Type: multipart/alternative; boundary=\"alt\"\r\n\ + \r\n\ + --alt\r\n\ + Content-Type: text/plain; charset=utf-8\r\n\ + Content-Transfer-Encoding: quoted-printable\r\n\ + \r\n\ + Ahoj, pos=C3=ADl=C3=A1m fotky.\r\n\ + --alt\r\n\ + Content-Type: multipart/related; boundary=\"rel\"\r\n\ + \r\n\ + --rel\r\n\ + Content-Type: text/html; charset=utf-8\r\n\ + \r\n\ +

Ahoj, posílám fotky.

\r\n\ + --rel\r\n\ + Content-Type: image/png\r\n\ + Content-Transfer-Encoding: base64\r\n\ + Content-ID: \r\n\ + Content-Disposition: inline; filename=\"photo.png\"\r\n\ + \r\n\ + {png}\ + --rel--\r\n\ + --alt--\r\n\ + --outer\r\n\ + Content-Type: application/pdf; name=\"=?UTF-8?B?UMWZw61sb2hhLnBkZg==?=\"\r\n\ + Content-Transfer-Encoding: base64\r\n\ + Content-Disposition: attachment; filename=\"=?UTF-8?B?UMWZw61sb2hhLnBkZg==?=\"\r\n\ + \r\n\ + {pdf}\ + --outer--\r\n", + png = b64(PNG_1X1), + pdf = b64(b"%PDF-1.4 fake"), + ) + .into_bytes() +} + +#[test] +fn nested_multipart_bodies_headers_and_attachments() { + let m = parse(&nested_fixture()).unwrap(); + assert_eq!(m.subject, "Přílohy a obrázky"); + assert_eq!(m.message_id.as_deref(), Some("nested-1@example.com")); + assert_eq!(m.in_reply_to, vec!["parent@example.com"]); + assert_eq!(m.references, vec!["root@example.com", "parent@example.com"]); + assert_eq!(m.from[0].name.as_deref(), Some("Anna Nováková")); + assert_eq!(m.from[0].email, "anna@example.com"); + assert_eq!(m.to.len(), 2); + assert_eq!(m.cc[0].name.as_deref(), Some("Jiří")); + assert_eq!(m.date, Some(1_794_128_400)); + assert!(m.text.as_deref().unwrap().contains("posílám fotky")); + assert!(!m.text.as_deref().unwrap().contains('\r'), "line endings are \\n"); + assert!(m.html.as_deref().unwrap().contains("posílám")); + assert_eq!(m.attachments.len(), 2); + let inline = m.attachments.iter().find(|a| a.inline).unwrap(); + assert_eq!(inline.content_id.as_deref(), Some("photo1@example.com")); + assert_eq!(inline.content_type, "image/png"); + assert_eq!(inline.data, PNG_1X1); + let pdf = m.attachments.iter().find(|a| !a.inline).unwrap(); + assert_eq!(pdf.filename, "Příloha.pdf", "RFC 2047 encoded name"); + assert_eq!(pdf.content_type, "application/pdf"); + assert_eq!(pdf.data, b"%PDF-1.4 fake"); +} + +#[test] +fn inline_cid_image_becomes_a_data_uri_in_the_reader() { + let m = parse(&nested_fixture()).unwrap(); + let inline = m.attachments.iter().find(|a| a.inline).unwrap(); + let mut images = HashMap::new(); + images.insert( + 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 }, + ); + assert!(out.html.contains("data:image/png;base64,"), "{}", out.html); + assert!(!out.html.contains("cid"), "{}", out.html); + assert_eq!(out.blocked_images, 0); +} + +#[test] +fn rfc2231_and_rfc2047_names() { + let raw = format!( + "From: =?ISO-8859-2?Q?Ji=F8=ED?= \r\n\ + Subject: =?UTF-8?Q?=C4=8Cesk=C3=BD_p=C5=99edm=C4=9Bt?=\r\n\ + Content-Type: multipart/mixed; boundary=b\r\n\r\n\ + --b\r\nContent-Type: text/plain\r\n\r\nhi\r\n\ + --b\r\nContent-Type: application/octet-stream\r\n\ + Content-Disposition: attachment; filename*=UTF-8''%C5%BEluou%C4%8Dk%C3%BD%20k%C5%AF%C5%88.txt\r\n\ + Content-Transfer-Encoding: base64\r\n\r\n{}--b--\r\n", + b64(b"x") + ); + let m = parse(raw.as_bytes()).unwrap(); + assert_eq!(m.from[0].name.as_deref(), Some("Jiří")); + assert_eq!(m.subject, "Český předmět"); + assert_eq!(m.attachments[0].filename, "žluoučký kůň.txt"); +} + +#[test] +fn broken_charsets_do_not_panic_and_keep_text() { + let unknown = b"Subject: x\r\nContent-Type: text/plain; charset=\"x-no-such-charset\"\r\n\r\nCaf\xE9 ok\r\n"; + 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 m = parse(invalid_utf8).unwrap(); + assert!(m.text.unwrap().contains("bytes")); + + let latin2 = b"Subject: x\r\nContent-Type: text/plain; charset=iso-8859-2\r\n\r\n\xE8esk\xFD\r\n"; + assert_eq!(parse(latin2).unwrap().text.unwrap().trim(), "český"); +} + +#[test] +fn missing_boundaries_do_not_panic() { + let no_param = b"Subject: x\r\nContent-Type: multipart/mixed\r\n\r\njust some text\r\n"; + let m = parse(no_param).unwrap(); + assert_eq!(m.subject, "x"); + + let never_closed = b"Subject: y\r\nContent-Type: multipart/mixed; boundary=zz\r\n\r\n--zz\r\nContent-Type: text/plain\r\n\r\nunterminated body\r\n"; + let m = parse(never_closed).unwrap(); + assert!(m.text.unwrap().contains("unterminated body")); + + let wrong_boundary = b"Subject: z\r\nContent-Type: multipart/mixed; boundary=aa\r\n\r\n--bb\r\nContent-Type: text/plain\r\n\r\nhidden\r\n--bb--\r\n"; + assert!(parse(wrong_boundary).is_ok()); +} + +#[test] +fn eight_megabyte_attachment_round_trips() { + let data = noise(8 * 1024 * 1024, 0x5eed); + let raw = format!( + "Subject: big\r\nContent-Type: multipart/mixed; boundary=big\r\n\r\n\ + --big\r\nContent-Type: text/plain\r\n\r\nsee attached\r\n\ + --big\r\nContent-Type: application/zip\r\nContent-Disposition: attachment; filename=big.zip\r\n\ + Content-Transfer-Encoding: base64\r\n\r\n{}--big--\r\n", + b64(&data) + ); + let m = parse(raw.as_bytes()).unwrap(); + assert_eq!(m.attachments.len(), 1); + assert_eq!(m.attachments[0].data.len(), data.len()); + assert!(m.attachments[0].data == data); +} + +#[test] +fn two_hundred_kilobyte_header_block() { + let mut raw = String::new(); + while raw.len() < 200 * 1024 { + raw.push_str("X-Junk: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n"); + } + raw.push_str("Subject: after the junk\r\nFrom: a@example.com\r\n\r\nbody\r\n"); + let m = parse(raw.as_bytes()).unwrap(); + assert_eq!(m.subject, "after the junk"); + assert_eq!(m.text.unwrap().trim(), "body"); + + // One folded header line of 200 KB. + let mut folded = String::from("Subject: start"); + while folded.len() < 200 * 1024 { + folded.push_str("\r\n word"); + } + folded.push_str("\r\n\r\nbody\r\n"); + let m = parse(folded.as_bytes()).unwrap(); + assert!(m.subject.chars().count() <= epistula_core::mime::MAX_SUBJECT_CHARS); + assert!(m.subject.starts_with("start")); +} + +#[test] +fn hostile_filenames_in_messages_are_made_safe() { + 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!( + "--f\r\nContent-Type: application/octet-stream\r\nContent-Disposition: attachment; filename=\"{name}\"\r\n\r\nx\r\n" + )); + } + raw.push_str("--f--\r\n"); + let m = parse(raw.as_bytes()).unwrap(); + assert_eq!(m.attachments.len(), names.len()); + for a in &m.attachments { + assert!(!a.filename.contains('/') && !a.filename.contains('\\'), "{:?}", a.filename); + assert!(!a.filename.contains(".."), "{:?}", a.filename); + assert!(!a.filename.contains('\u{202E}')); + assert!(!a.filename.eq_ignore_ascii_case("con.txt")); + } +} + +#[test] +fn safe_filename_cases() { + assert_eq!(safe_filename("../../../etc/passwd"), "passwd"); + assert_eq!(safe_filename("..\\..\\Windows\\win.ini"), "win.ini"); + assert_eq!(safe_filename("C:\\Users\\x\\a.doc"), "a.doc"); + assert_eq!(safe_filename("CON"), "_CON"); + assert_eq!(safe_filename("con.txt"), "_con.txt"); + assert_eq!(safe_filename("LPT9.log"), "_LPT9.log"); + assert_eq!(safe_filename("COM1.tar.gz"), "_COM1.tar.gz"); + assert_eq!(safe_filename("aux"), "_aux"); + assert_eq!(safe_filename("NUL."), "_NUL"); + assert_eq!(safe_filename("CONSOLE.txt"), "CONSOLE.txt", "only exact reserved names"); + assert_eq!(safe_filename("invoice\u{202E}fdp.exe"), "invoicefdp.exe"); + assert_eq!(safe_filename("a\u{2066}b\u{200F}c\u{061C}.txt"), "abc.txt"); + assert_eq!(safe_filename("ac:d\"e|f?g*h.txt"), "a_b_c_d_e_f_g_h.txt"); + assert_eq!(safe_filename("tab\there\0nul.txt"), "tabherenul.txt"); + assert_eq!(safe_filename("file.txt. . "), "file.txt"); + assert_eq!(safe_filename(".hidden"), "hidden"); + assert_eq!(safe_filename(""), "attachment"); + assert_eq!(safe_filename("..."), "attachment"); + assert_eq!(safe_filename("/"), "attachment"); + assert_eq!(safe_filename("Příloha – výpis.pdf"), "Příloha – výpis.pdf"); + let long = format!("{}.pdf", "a".repeat(500)); + let cut = safe_filename(&long); + assert_eq!(cut.chars().count(), epistula_core::filename::MAX_FILENAME_CHARS); + assert!(cut.ends_with(".pdf")); +} + +#[test] +fn message_rfc822_attachment_is_kept_as_a_file() { + let raw = b"Subject: fwd\r\nContent-Type: multipart/mixed; boundary=m\r\n\r\n\ +--m\r\nContent-Type: text/plain\r\n\r\nsee inner\r\n\ +--m\r\nContent-Type: message/rfc822\r\n\r\nSubject: inner\r\nFrom: x@example.com\r\n\r\ninner body\r\n\ +--m--\r\n"; + let m = parse(raw).unwrap(); + assert_eq!(m.subject, "fwd"); + assert_eq!(m.attachments.len(), 1); + assert_eq!(m.attachments[0].content_type, "message/rfc822"); + assert!(m.attachments[0].filename.ends_with(".eml")); + assert!(String::from_utf8_lossy(&m.attachments[0].data).contains("inner body")); +} + +#[test] +fn deep_nesting_does_not_overflow() { + let depth = 5000; + let mut raw = String::from("Subject: deep\r\n"); + for i in 0..depth { + raw.push_str(&format!("Content-Type: multipart/mixed; boundary=b{i}\r\n\r\n--b{i}\r\n")); + } + raw.push_str("Content-Type: text/plain\r\n\r\nbottom\r\n"); + let m = parse(raw.as_bytes()).unwrap(); + assert_eq!(m.subject, "deep"); +} + +#[test] +fn too_large_is_refused_and_garbage_is_not_mail() { + let big = vec![b'a'; MAX_MESSAGE_BYTES + 1]; + assert_eq!(parse(&big).unwrap_err(), ParseError::TooLarge); + assert_eq!(parse(b"").unwrap_err(), ParseError::NotMail); +} + +#[test] +fn debug_output_has_no_content() { + let m = parse(&nested_fixture()).unwrap(); + let debug = format!("{m:?} {:?}", m.attachments); + for secret in ["anna", "posílám", "Příloha", "PDF"] { + assert!(!debug.contains(secret), "{debug}"); + } +} + +proptest! { + #![proptest_config(ProptestConfig::with_cases(512))] + + #[test] + fn parse_never_panics_on_bytes(raw in proptest::collection::vec(any::(), 0..4096)) { + let _ = parse(&raw); + } + + #[test] + fn parse_never_panics_on_mime_like_text( + parts in proptest::collection::vec(prop_oneof![ + Just("Content-Type: multipart/mixed; boundary=x\r\n".to_string()), + Just("--x\r\n".to_string()), + Just("--x--\r\n".to_string()), + Just("\r\n".to_string()), + Just("Content-Transfer-Encoding: base64\r\n".to_string()), + Just("Content-Transfer-Encoding: quoted-printable\r\n".to_string()), + Just("Content-Disposition: attachment; filename=\"../a\"\r\n".to_string()), + Just("Subject: =?UTF-8?B?\r\n".to_string()), + Just("=?x?Q?=ZZ?=".to_string()), + "[ -~]{0,40}", + ], 0..60) + ) { + let raw = parts.concat(); + let _ = parse(raw.as_bytes()); + } + + #[test] + fn safe_filename_is_always_safe(raw in "\\PC{0,200}") { + let name = safe_filename(&raw); + prop_assert!(!name.is_empty()); + prop_assert!(name.chars().count() <= epistula_core::filename::MAX_FILENAME_CHARS); + prop_assert!(!name.contains(['/', '\\', ':', '*', '?', '"', '<', '>', '|', '\0'])); + prop_assert!(!name.starts_with('.') && !name.ends_with('.') && !name.ends_with(' ')); + let bidi_or_control = name.chars().any(|c| c.is_control() + || matches!(c, '\u{200E}' | '\u{200F}' | '\u{061C}' | '\u{202A}'..='\u{202E}' | '\u{2066}'..='\u{2069}')); + prop_assert!(!bidi_or_control, "{:?}", name); + let stem = name.split('.').next().unwrap().to_ascii_uppercase(); + let reserved = ["CON", "PRN", "AUX", "NUL"].contains(&stem.as_str()) + || ((stem.starts_with("COM") || stem.starts_with("LPT")) && stem.len() == 4 + && stem.as_bytes()[3].is_ascii_digit()); + prop_assert!(!reserved, "{}", name); + } +} diff --git a/tests/sanitize.proptest-regressions b/tests/sanitize.proptest-regressions new file mode 100644 index 0000000..2848be4 --- /dev/null +++ b/tests/sanitize.proptest-regressions @@ -0,0 +1,9 @@ +# Seeds for failure cases proptest has generated in the past. It is +# automatically read and these particular cases re-run before any +# novel cases are generated. +# +# It is recommended to check this file in to source control so that +# everyone who runs the test benefits from these saved cases. +cc 4e10d11e138d641f5cd862bf9d0328534293c16602b25811c13e17f483d0c012 # shrinks to parts = [], load = false +cc 9298836d4e0c985227afc1ac30519c2685a4e3d945870a0e9f17cc9e627b725c # shrinks to parts = [] +cc 04d94bdb6810dae2da78cbe7203c4f7076050d7986ba6572441864111c45a79e # shrinks to text = "" diff --git a/tests/sanitize.rs b/tests/sanitize.rs new file mode 100644 index 0000000..00b998b --- /dev/null +++ b/tests/sanitize.rs @@ -0,0 +1,309 @@ +//! Mandatory: the hostile HTML corpus and the sanitiser's properties. + +use epistula_core::sanitize::{BLOCKED_IMAGE_SRC, SanitizeOptions, sanitize, text_to_html}; +use proptest::prelude::*; + +fn clean(html: &str) -> String { + sanitize(html, &SanitizeOptions::default()).html +} + +/// Anything executable, anything that loads something, anything that navigates by itself. +const FORBIDDEN: &[&str] = &[ + "alert(1)", + "", + "ipt>alert(1)", + "", + "", + "", + "hi", + "", + "", + "", + "", + "", + "", + "", + "", + "
", + "", + "", + "", + "", + "
x
", + "x", + "", + "", + "
x
", + "ok", + "alert(1)", + "", + "", + "x", + "", + "0", + "x", +]; + +/// The output escapes `:` and `=` in text and attribute values (`:`, `=`); undo that so the checks +/// see what a browser sees. +fn decoded(s: &str) -> String { + s.replace(":", ":").replace("=", "=") +} + +/// Every tag in the output, with its attribute names and decoded values (a small scanner for the serialised +/// form ammonia writes: double-quoted values, no raw `<` in text). +fn tags(out: &str) -> Vec<(String, Vec<(String, String)>)> { + let mut result = Vec::new(); + let mut rest = out; + while let Some(start) = rest.find('<') { + rest = &rest[start + 1..]; + let mut name = String::new(); + let mut chars = rest.char_indices().peekable(); + while let Some(&(_, c)) = chars.peek() { + if c.is_whitespace() || c == '>' || c == '/' && !name.is_empty() { + break; + } + name.push(c); + chars.next(); + } + let mut attrs = Vec::new(); + let mut end = rest.len(); + loop { + while let Some(&(_, c)) = chars.peek() { + if c.is_whitespace() || c == '/' { chars.next(); } else { break; } + } + let Some(&(i, c)) = chars.peek() else { break }; + if c == '>' { end = i + 1; break; } + let mut attr = String::new(); + while let Some(&(_, c)) = chars.peek() { + if c == '=' || c == '>' || c.is_whitespace() { break; } + attr.push(c); + chars.next(); + } + let mut value = String::new(); + if let Some(&(_, '=')) = chars.peek() { + chars.next(); + if let Some(&(_, '"')) = chars.peek() { + chars.next(); + for (_, c) in chars.by_ref() { + if c == '"' { break; } + value.push(c); + } + } + } + let value = decoded(&value).replace("&", "&").replace(""", "\""); + attrs.push((attr.to_ascii_lowercase(), value)); + } + result.push((name.to_ascii_lowercase(), attrs)); + rest = &rest[end.min(rest.len())..]; + } + result +} + +/// What a browser would run or load: script tags, event handler attributes, script URLs. +fn dangerous(out: &str) -> Option { + for (name, attrs) in tags(out) { + if name == "script" || name == "iframe" || name == "object" || name == "embed" || name == "svg" { + return Some(format!("tag {name}")); + } + for (attr, value) in attrs { + if attr.starts_with("on") { + return Some(format!("attribute {attr}")); + } + let compact: String = value.chars().filter(|c| !c.is_whitespace() && !c.is_control()).collect(); + let compact = compact.to_ascii_lowercase(); + if compact.starts_with("javascript:") || compact.starts_with("vbscript:") || compact.starts_with("data:text") { + return Some(format!("url in {attr}")); + } + } + } + None +} + +#[test] +fn hostile_corpus_leaves_nothing_dangerous() { + for input in CORPUS { + let raw = clean(input); + assert_eq!(dangerous(&raw), None, "input {input:?} output {raw:?}"); + let out = decoded(&raw).to_ascii_lowercase(); + for bad in FORBIDDEN { + assert!(!out.contains(bad), "input {input:?}\noutput {out:?}\ncontains {bad:?}"); + } + } +} + +#[test] +fn remote_images_become_placeholders_and_are_counted() { + let html = "

Hi

\"logo\""; + let out = sanitize(html, &SanitizeOptions::default()); + assert_eq!(out.blocked_images, 2); + assert!(!out.html.contains("evil.example"), "{}", out.html); + let placeholder = BLOCKED_IMAGE_SRC.replace(':', ":"); + assert_eq!(out.html.matches(&placeholder).count(), 2, "{}", out.html); + assert!(out.html.contains("alt=\"logo\"")); +} + +#[test] +fn load_images_keeps_remote_images_only() { + let html = "j"; + let out = sanitize(html, &SanitizeOptions { load_remote_images: true, ..Default::default() }); + assert_eq!(out.blocked_images, 0); + assert!(out.html.contains("https://cdn.example/a.png"), "{}", out.html); + let lower = out.html.to_ascii_lowercase(); + assert!(!lower.contains("javascript") && !lower.contains("onerror"), "{}", out.html); +} + +#[test] +fn ordinary_mail_formatting_survives() { + let html = "
\ +

Bold it u s e

\ +
  • one
  1. two
quoted
\ +
cell
\ + link mail
"; + let out = clean(html); + for kept in ["Bold", "it", "u", "