commit 4c1a6457c52c64f708cbb9b86a8d839263fdc15b Author: Mateusz Pstrucha Date: Tue Sep 22 19:00:59 2026 +0200 Initial sync server: IMAP engine, schema, and read API Covers phases 1-2 of the build order in the architecture spec: the IMAP sync engine (IDLE + UIDVALIDITY tracking + jittered reconnect, headers first with lazy body fetch), the full data model, and a minimal REST API for auth, accounts, folders, messages and delta polling. Credentials are encrypted at rest with ChaCha20-Poly1305 rather than libsodium secretbox, to avoid a system dependency for the same construction. Co-Authored-By: Claude Opus 5 diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..0f0996d --- /dev/null +++ b/.env.example @@ -0,0 +1,16 @@ +# Copy to .env for local development (docker-compose reads this automatically +# for the `db` service password; the app reads it via dotenvy at startup). + +DATABASE_URL=postgres://tern:tern@localhost:5432/tern +BIND_ADDR=127.0.0.1:8080 + +# 32 random bytes, base64-encoded. Generate with: openssl rand -base64 32 +# Encrypts stored IMAP/SMTP credentials at rest (see src/crypto.rs). Losing +# this key makes every stored account credential unrecoverable — back it up +# outside the database. +CREDENTIAL_KEY= + +BLOB_STORAGE_DIR=./data/blobs +SESSION_TTL_HOURS=720 + +RUST_LOG=tern_server=debug,tower_http=debug diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..477e9fc --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +/target +.env +/data +*.log +.DS_Store diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..a7789c7 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,3589 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "adler2" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" + +[[package]] +name = "aead" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d122413f284cf2d62fb1b7db97e02edb8cda96d769b16e443a4f6195e35662b0" +dependencies = [ + "crypto-common", + "generic-array", +] + +[[package]] +name = "aes" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" +dependencies = [ + "cfg-if", + "cipher", + "cpufeatures", +] + +[[package]] +name = "ahash" +version = "0.8.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a15f179cd60c4584b8a8c596927aadc462e27f2ca70c04e0071964a73ba7a75" +dependencies = [ + "cfg-if", + "getrandom 0.3.4", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "aho-corasick" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c982642fa9e8606056828ee9a8505737230110bb1099153c79efe865c59d12ba" +dependencies = [ + "memchr", +] + +[[package]] +name = "allocator-api2" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" + +[[package]] +name = "android_system_properties" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae221649c9976a6f6c56ae1facf410f3ddb33cc661c4b7b61020a912d4237fbc" +dependencies = [ + "libc", +] + +[[package]] +name = "anyhow" +version = "1.0.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470" + +[[package]] +name = "arbitrary" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3d036a3c4ab069c7b410a2ce876bd74808d2d0888a82667669f8e783a898bf1" +dependencies = [ + "derive_arbitrary", +] + +[[package]] +name = "argon2" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c3610892ee6e0cbce8ae2700349fcf8f98adb0dbfbee85aec3c9179d29cc072" +dependencies = [ + "base64ct", + "blake2", + "cpufeatures", + "password-hash", +] + +[[package]] +name = "async-channel" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81953c529336010edd6d8e358f886d9581267795c61b19475b71314bffa46d35" +dependencies = [ + "concurrent-queue", + "event-listener 2.5.3", + "futures-core", +] + +[[package]] +name = "async-channel" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "924ed96dd52d1b75e9c1a3e6275715fd320f5f9439fb5a4a11fa51f4221158d2" +dependencies = [ + "concurrent-queue", + "event-listener-strategy", + "futures-core", + "pin-project-lite", +] + +[[package]] +name = "async-compression" +version = "0.4.48" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb61aea1a7def73ee7c350a184f0e70b32c182344e2e75bf70c9b621b83417fd" +dependencies = [ + "compression-codecs", + "compression-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "async-imap" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a6728e0f7931b36d725ac234fcb02539e9f7888dbeaaa8a18d9ea5792181570" +dependencies = [ + "async-channel 2.5.0", + "async-compression", + "base64 0.22.1", + "bytes", + "chrono", + "futures", + "imap-proto", + "log", + "nom", + "pin-project", + "pin-utils", + "self_cell", + "stop-token", + "thiserror 1.0.69", + "tokio", +] + +[[package]] +name = "async-native-tls" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37dd6b179962fe4048a6f81d4c0d7ed419a21fdf49204b4c6b04971693358e79" +dependencies = [ + "native-tls", + "thiserror 2.0.20", + "tokio", + "url", +] + +[[package]] +name = "async-trait" +version = "0.1.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82f6aeea286b8eb4dd3431a1be1b59d290ace00f5bfd8e2a159bc2a05e2c1667" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.6", +] + +[[package]] +name = "atoi" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f28d99ec8bfea296261ca1af174f24225171fea9664ba9003cbebee704810528" +dependencies = [ + "num-traits", +] + +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + +[[package]] +name = "autocfg" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53" + +[[package]] +name = "axum" +version = "0.7.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edca88bc138befd0323b20752846e6587272d3b03b0343c8ea28a6f819e6e71f" +dependencies = [ + "async-trait", + "axum-core", + "axum-macros", + "bytes", + "futures-util", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-util", + "itoa", + "matchit", + "memchr", + "mime", + "percent-encoding", + "pin-project-lite", + "rustversion", + "serde", + "serde_json", + "serde_path_to_error", + "serde_urlencoded", + "sync_wrapper", + "tokio", + "tower", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "axum-core" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09f2bd6146b97ae3359fa0cc6d6b376d9539582c7b4220f041a33ec24c226199" +dependencies = [ + "async-trait", + "bytes", + "futures-util", + "http", + "http-body", + "http-body-util", + "mime", + "pin-project-lite", + "rustversion", + "sync_wrapper", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "axum-macros" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57d123550fa8d071b7255cb0cc04dc302baa6c8c4a79f55701552684d8399bce" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "base64" +version = "0.21.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "base64ct" +version = "1.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2af50177e190e07a26ab74f8b1efbfe2ef87da2116221318cb1c2e82baf7de06" + +[[package]] +name = "bitflags" +version = "2.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06" +dependencies = [ + "serde_core", +] + +[[package]] +name = "blake2" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46502ad458c9a52b69d4d4d32775c788b7a1b85e8bc9d482d92250fc0e3f8efe" +dependencies = [ + "digest", +] + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "bumpalo" +version = "3.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04" + +[[package]] +name = "bzip2" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49ecfb22d906f800d4fe833b6282cf4dc1c298f5057ca0b5445e5c209735ca47" +dependencies = [ + "bzip2-sys", +] + +[[package]] +name = "bzip2-sys" +version = "0.1.13+1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "225bff33b2141874fe80d71e07d6eec4f85c5c216453dd96388240f96e1acc14" +dependencies = [ + "cc", + "pkg-config", +] + +[[package]] +name = "cc" +version = "1.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54413ede23c2daf518f35156dfde027feb2374004d63bd497f983c8db9c0e313" +dependencies = [ + "find-msvc-tools", + "jobserver", + "libc", + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600" + +[[package]] +name = "chacha20" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3613f74bd2eac03dad61bd53dbe620703d4371614fe0bc3b9f04dd36fe4e818" +dependencies = [ + "cfg-if", + "cipher", + "cpufeatures", +] + +[[package]] +name = "chacha20poly1305" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10cd79432192d1c0f4e1a0fef9527696cc039165d729fb41b3f4f4f354c2dc35" +dependencies = [ + "aead", + "chacha20", + "cipher", + "poly1305", + "zeroize", +] + +[[package]] +name = "chrono" +version = "0.4.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aa79e62e7697b8e29b513a68abacf485adcd1fe8284a4316c5ae868e6633327" +dependencies = [ + "iana-time-zone", + "js-sys", + "num-traits", + "serde", + "wasm-bindgen", + "windows-link", +] + +[[package]] +name = "cipher" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" +dependencies = [ + "crypto-common", + "inout", + "zeroize", +] + +[[package]] +name = "compression-codecs" +version = "0.4.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef16c47ba2797aa6a909cc37d39911f3a6743811fe7408ac0b0cc0276b656e9" +dependencies = [ + "compression-core", + "flate2", +] + +[[package]] +name = "compression-core" +version = "0.4.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e8ccc4ea9f6acc32d102c0f6d471d11d913ad15f20c04de743374861fa1d414" + +[[package]] +name = "concurrent-queue" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "const-oid" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" + +[[package]] +name = "constant_time_eq" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c74b8349d32d297c9134b8c88677813a227df8f779daa29bfc29c183fe3dca6" + +[[package]] +name = "core-foundation" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2a6cd9ae233e7f62ba4e9353e81a88df7fc8a5987b8d445b4d90c879bd156f6" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[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.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" +dependencies = [ + "libc", +] + +[[package]] +name = "crc" +version = "3.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5eb8a2a1cd12ab0d987a5d5e825195d372001a4094a0376319d5a0ad71c1ba0d" +dependencies = [ + "crc-catalog", +] + +[[package]] +name = "crc-catalog" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "217698eaf96b4a3f0bc4f3662aaa55bdf913cd54d7204591faa790070c6d0853" + +[[package]] +name = "crc32fast" +version = "1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01a7799fd6b852db0e61728dde9a204c423b44d689dbd432522543614b490e78" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "crossbeam-queue" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03e8bd762f7479489c70ed6c768ddca99d7296857de437a68dcb2a94365b3fae" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a31eee39dddec8330830986fcd7625edb5a24ec90ea038215273bbc3adb08ac6" + +[[package]] +name = "crypto-common" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" +dependencies = [ + "generic-array", + "rand_core", + "typenum", +] + +[[package]] +name = "data-encoding" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4583a4551df46e2792f82ceeac45e850d2e2d5debba0b91f102385cda5b11f06" + +[[package]] +name = "deflate64" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac6b926516df9c60bfa16e107b21086399f8285a44ca9711344b9e553c5146e2" + +[[package]] +name = "der" +version = "0.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7c1832837b905bbfb5101e07cc24c8deddf52f93225eee6ead5f4d63d53ddcb" +dependencies = [ + "const-oid", + "pem-rfc7468", + "zeroize", +] + +[[package]] +name = "deranged" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cd812cc2bc1d69d4764bd80df88b4317eaef9e773c75226407d9bc0876b211c" + +[[package]] +name = "derive_arbitrary" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e567bd82dcff979e4b03460c307b3cdc9e96fde3d73bed1496d2bc75d9dd62a" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "const-oid", + "crypto-common", + "subtle", +] + +[[package]] +name = "displaydoc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6232dd377dcc64799954cbd3a9bb882e9cdc1308ccd87b1c098f1fb2eaf82a8" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.6", +] + +[[package]] +name = "dotenvy" +version = "0.15.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" + +[[package]] +name = "either" +version = "1.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "252afb9ae5eaa683babdc6a068b3f5726eb19e05070c731f9b2a23a7c3e8ed34" +dependencies = [ + "serde", +] + +[[package]] +name = "encoding_rs" +version = "0.8.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b5ef0006ac9ab233c38522f5ae99cae3625151de8f706cacee1cba4b8e2832a" +dependencies = [ + "cfg-if", + "core_detect", + "multiversion", + "multiversion_no_op", + "rustversion", + "scopeguard", + "simdutf8", +] + +[[package]] +name = "enum-as-inner" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1e6a265c649f3f5979b601d26f1d05ada116434c87741c9493cb56218f76cbc" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + +[[package]] +name = "errno" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "etcetera" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "136d1b5283a1ab77bd9257427ffd09d8667ced0570b6f938942bc7568ed5b943" +dependencies = [ + "cfg-if", + "home", + "windows-sys 0.48.0", +] + +[[package]] +name = "event-listener" +version = "2.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" + +[[package]] +name = "event-listener" +version = "5.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a23add41df1562121a9393cb065eab5146a1242410f23a644851e90cfd669d2" +dependencies = [ + "parking", + "pin-project-lite", +] + +[[package]] +name = "event-listener-strategy" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8be9f3dfaaffdae2972880079a491a1a8bb7cbed0b8dd7a347f668b4150a3b93" +dependencies = [ + "event-listener 5.4.2", + "pin-project-lite", +] + +[[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.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef25905e51abafe4dcea6c15fec58c57b601cdbd0ee53d22ea1d3016c587d39b" + +[[package]] +name = "flate2" +version = "1.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e634e2e0ebac1ee034020da1ca582e17ffe4e0f5e985823721e168928136dcb" +dependencies = [ + "crc32fast", + "miniz_oxide", + "zlib-rs", +] + +[[package]] +name = "flume" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da0e4dd2a88388a1f4ccc7c9ce104604dab68d9f408dc34cd45823d5a9069095" +dependencies = [ + "futures-core", + "futures-sink", + "spin", +] + +[[package]] +name = "foldhash" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[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" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a31d2a3fbaaeb2af2368bbdd904aa8e812d3c04a1ee10d3171f52d556e5d0a3" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f9e3d69d39e4862ffed03ed071a76f9a13ba1d9109d355b0f0aa6b15e393c4" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e" + +[[package]] +name = "futures-executor" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "031b47cf1a3c6cc8bc2fc76cd437f521619387907d469316e7c0bc278f1f5432" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-intrusive" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d930c203dd0b6ff06e0201a4a2fe9149b43c684fd4420555b26d21b1a02956f" +dependencies = [ + "futures-core", + "lock_api", + "parking_lot", +] + +[[package]] +name = "futures-io" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53c0fa8157de1303bfffdaa1cc2a673bfffb60102f76b0ef4441659124373fed" + +[[package]] +name = "futures-macro" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb9654ba8355388abeb8dcb4fc62f511300867002afc858860463bdd9fe0c44" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.6", +] + +[[package]] +name = "futures-sink" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1944426bf7d03f1d14f708785e4b33efd750b36d48a157b836b3efc15ede8e1d" + +[[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-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "slab", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "gethostname" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0176e0459c2e4a1fe232f984bca6890e681076abb9934f6cea7c326f3fc47818" +dependencies = [ + "libc", + "windows-targets 0.48.5", +] + +[[package]] +name = "getrandom" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "getrandom" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "r-efi 5.3.0", + "wasip2", + "wasm-bindgen", +] + +[[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 6.0.0", +] + +[[package]] +name = "hashbrown" +version = "0.15.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" +dependencies = [ + "allocator-api2", + "equivalent", + "foldhash", +] + +[[package]] +name = "hashbrown" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" + +[[package]] +name = "hashify" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd1246c0e5493286aeb2dde35b1f4eb9c4ce00e628641210a5e553fc001a1f26" +dependencies = [ + "indexmap", + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "hashlink" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7382cf6263419f2d8df38c55d7da83da5c18aef87fc7a7fc1fb1e344edfe14c1" +dependencies = [ + "hashbrown 0.15.5", +] + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "hickory-proto" +version = "0.24.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92652067c9ce6f66ce53cc38d1169daa36e6e7eb7dd3b63b5103bd9d97117248" +dependencies = [ + "async-trait", + "cfg-if", + "data-encoding", + "enum-as-inner", + "futures-channel", + "futures-io", + "futures-util", + "idna", + "ipnet", + "once_cell", + "rand", + "ring", + "rustls 0.21.12", + "rustls-pemfile 1.0.4", + "thiserror 1.0.69", + "tinyvec", + "tokio", + "tokio-rustls 0.24.1", + "tracing", + "url", +] + +[[package]] +name = "hickory-resolver" +version = "0.24.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbb117a1ca520e111743ab2f6688eddee69db4e0ea242545a604dce8a66fd22e" +dependencies = [ + "cfg-if", + "futures-util", + "hickory-proto", + "ipconfig", + "lru-cache", + "once_cell", + "parking_lot", + "rand", + "resolv-conf", + "rustls 0.21.12", + "smallvec", + "thiserror 1.0.69", + "tokio", + "tokio-rustls 0.24.1", + "tracing", +] + +[[package]] +name = "hkdf" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b5f8eb2ad728638ea2c7d47a21db23b7b58a72ed6a38256b8a1849f15fbbdf7" +dependencies = [ + "hmac", +] + +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest", +] + +[[package]] +name = "home" +version = "0.5.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc627f471c528ff0c4a49e1d5e60450c8f6461dd6d10ba9dcd3a61d3dff7728d" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "http" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "918d3568bebf352712bc2ef3d46a8bcf1a75b373be6539de198e9105cbbf9ce0" +dependencies = [ + "bytes", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2a8f2913ee65f60facd6a5905613afaa448497a0230cc41ce022d93290bc2c" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23169fe34a5fbcdd3f3862e78fb9b6fccd5f02a6dc6f732547005d45631ce71c" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" + +[[package]] +name = "httpdate" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" + +[[package]] +name = "hyper" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "27b501faa50e7a26c3d3560ca625132f4078a17771f4810baf70475ae48cbe43" +dependencies = [ + "atomic-waker", + "bytes", + "futures-channel", + "futures-core", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", +] + +[[package]] +name = "hyper-util" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96547c2556ec9d12fb1578c4eaf448b04993e7fb79cbaad930a656880a6bdfa0" +dependencies = [ + "bytes", + "http", + "http-body", + "hyper", + "pin-project-lite", + "tokio", + "tower-service", +] + +[[package]] +name = "iana-time-zone" +version = "0.1.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "log", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "icu_collections" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa68d21081c4a05d5a901a1c62add574c77048b6a1c67be3b50ce0b60d4ca513" +dependencies = [ + "displaydoc", + "potential_utf", + "utf8_iter", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locale_core" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d56e28588da92eee5c3201a6eff33fabdd49b62269c8938d4ff050ce4d900deb" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_normalizer" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12f9cf5f235641ed274641dd81c3f28d870e276763d0797aeeab72317b1c646f" +dependencies = [ + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1563da1ed3e0b3bf3d74c9b85917ac9c56464d2f57242270c09c9e752f8021a0" + +[[package]] +name = "icu_properties" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e7ca276ad3145661a65914e6daf131ca5120cd3dcee8f8f3214b8875184a148" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_locale_core", + "icu_properties_data", + "icu_provider", + "zerotrie", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e590f038c1464a96894fd6d10127e90a8be4509f56ff7ecef851b15cee0b7caa" + +[[package]] +name = "icu_provider" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d27bbb9d3abbefac45d55f647c9de1d44aafcd1186eb91879afef17c396c3e73" +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 = "imap-proto" +version = "0.16.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25f6af35c6a517aea5c72314abe90134980d2ae6a763809b50c208b3e429d71f" +dependencies = [ + "nom", +] + +[[package]] +name = "indexmap" +version = "2.14.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc4e190f5d26ca7051642629da2c52fc03bde85a03197c99408dcd291734c855" +dependencies = [ + "equivalent", + "hashbrown 0.17.1", +] + +[[package]] +name = "inout" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01" +dependencies = [ + "generic-array", +] + +[[package]] +name = "ipconfig" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d40460c0ce33d6ce4b0630ad68ff63d6661961c48b6dba35e5a4d81cfb48222" +dependencies = [ + "socket2", + "widestring", + "windows-registry", + "windows-result", + "windows-sys 0.61.2", +] + +[[package]] +name = "ipnet" +version = "2.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "791930b43c0d5973160d90a8f3894509f2b273430f5c5c73b668636d0287c5c0" + +[[package]] +name = "itoa" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" + +[[package]] +name = "jobserver" +version = "0.1.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c00acbd29eabad4a2392fa0e921c874934dbbf4194312ad20f04a0ed67a3cb3" +dependencies = [ + "getrandom 0.4.3", + "libc", +] + +[[package]] +name = "js-sys" +version = "0.3.105" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce57d20d1ea864ce2ac172ab472d409214f4fd359f0b2a2775abdf522e2af99e" +dependencies = [ + "cfg-if", + "futures-util", + "wasm-bindgen", +] + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" +dependencies = [ + "spin", +] + +[[package]] +name = "libc" +version = "0.2.189" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2" + +[[package]] +name = "libm" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981" + +[[package]] +name = "libredox" +version = "0.1.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61ff90caf6077a803a240f62fdbe88645a890bbca49ef8174c3cb0404362171d" +dependencies = [ + "bitflags", + "libc", + "plain", + "redox_syscall 0.9.4", +] + +[[package]] +name = "libsqlite3-sys" +version = "0.30.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e99fb7a497b1e3339bc746195567ed8d3e24945ecd636e3619d20b9de9e9149" +dependencies = [ + "pkg-config", + "vcpkg", +] + +[[package]] +name = "linked-hash-map" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" + +[[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.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9f8bd3e56ce4dfc153cf470fffbfa98c7620958b312ca5c3a4b8d5181fd13c6" + +[[package]] +name = "lru-cache" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31e24f1ad8321ca0e8a1e0ac13f23cb668e6f5466c2c57319f6a5cf1cc8e3b1c" +dependencies = [ + "linked-hash-map", +] + +[[package]] +name = "lzma-rs" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "297e814c836ae64db86b36cf2a557ba54368d03f6afcd7d947c266692f71115e" +dependencies = [ + "byteorder", + "crc", +] + +[[package]] +name = "lzma-sys" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fda04ab3764e6cde78b9974eec4f779acaba7c4e84b36eca3cf77c581b85d27" +dependencies = [ + "cc", + "libc", + "pkg-config", +] + +[[package]] +name = "mail-auth" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9bd9d657de66a3d5ac360c3eab8c9f5cac2565f2b97cc032d5de4c900ef470de" +dependencies = [ + "ahash", + "flate2", + "hickory-resolver", + "lru-cache", + "mail-builder", + "mail-parser 0.9.4", + "parking_lot", + "quick-xml", + "ring", + "rustls-pemfile 2.2.0", + "serde", + "serde_json", + "zip", +] + +[[package]] +name = "mail-builder" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25f5871d5270ed80f2ee750b95600c8d69b05f8653ad3be913b2ad2e924fefcb" +dependencies = [ + "gethostname", +] + +[[package]] +name = "mail-parser" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93c3b9e5d8b17faf573330bbc43b37d6e918c0a3bf8a88e7d0a220ebc84af9fc" +dependencies = [ + "encoding_rs", +] + +[[package]] +name = "mail-parser" +version = "0.11.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ec00bda90c6e645a54506c630c2820cd6b1890cfd2b0a169b50f74b2b8c7c86" +dependencies = [ + "hashify", +] + +[[package]] +name = "mail-send" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a575d25cf00ed68e5790b473b29242a47e991c6187785d47b45e31fc5816554" +dependencies = [ + "base64 0.22.1", + "gethostname", + "mail-auth", + "mail-builder", + "md5", + "rand", + "rustls 0.23.45", + "rustls-pki-types", + "smtp-proto", + "tokio", + "tokio-rustls 0.26.5", + "webpki-roots 0.26.11", +] + +[[package]] +name = "matchers" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1525a2a28c7f4fa0fc98bb91ae755d1e2d1505079e05539e35bc876b5d65ae9" +dependencies = [ + "regex-automata", +] + +[[package]] +name = "matchit" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" + +[[package]] +name = "md-5" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf" +dependencies = [ + "cfg-if", + "digest", +] + +[[package]] +name = "md5" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "490cc448043f947bae3cbee9c203358d62dbee0db12107a74be5c30ccfd09771" + +[[package]] +name = "memchr" +version = "2.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + +[[package]] +name = "miniz_oxide" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b63fbc4a50860e98e7b2aa7804ded1db5cbc3aff9193adaff57a6931bf7c4b4c" +dependencies = [ + "adler2", + "simd-adler32", +] + +[[package]] +name = "mio" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b18443e9c262bfe8fa82f51666e2642c53393f7e5c27b3e1aeab922cff5b9d8" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.61.2", +] + +[[package]] +name = "multiversion" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4ca4bea16ffc3f443cf7d866912118196bfef4c6a1556ca00f9f9b00bb43f7c" +dependencies = [ + "multiversion-macros", +] + +[[package]] +name = "multiversion-macros" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d416831a7317ef4b08bee00b69cbbb9c8763da7959a7026244d6266869f9c83" +dependencies = [ + "proc-macro2", + "quote", + "rustversion", + "syn 3.0.6", +] + +[[package]] +name = "multiversion_no_op" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "743fb55ba31b18fb1ecef6bdc9aa2743314978ac084044301a7eee33fb99a20d" + +[[package]] +name = "native-tls" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "465500e14ea162429d264d44189adc38b199b62b1c21eea9f69e4b73cb03bbf2" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + +[[package]] +name = "nu-ansi-term" +version = "0.50.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "num-bigint-dig" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e661dda6640fad38e827a6d4a310ff4763082116fe217f279885c97f511bb0b7" +dependencies = [ + "lazy_static", + "libm", + "num-integer", + "num-iter", + "num-traits", + "rand", + "smallvec", + "zeroize", +] + +[[package]] +name = "num-conv" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "521739c6d2bac4aa25192232afe6841231376b2b26d4d9fae5ecf8ca5772e441" + +[[package]] +name = "num-integer" +version = "0.1.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ce2d95d4b3734dc35aa2f45e1aa22cd416814592a4f9d9205e11affd5b8e10b" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-iter" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c92800bd69a1eac91786bcfe9da64a897eb72911b8dc3095decbd07429e8048b" +dependencies = [ + "num-integer", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", + "libm", +] + +[[package]] +name = "once_cell" +version = "1.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" + +[[package]] +name = "opaque-debug" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" + +[[package]] +name = "openssl" +version = "0.10.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77823a27f0babb03091cb9ed9ef80af3b39dbc82f97e8fa530374b7dafd87a45" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "openssl-probe" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c87def4c32ab89d880effc9e097653c8da5d6ef28e6b539d313baaacfbafcbe" + +[[package]] +name = "openssl-sys" +version = "0.9.117" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b47e7e6bb2c38cd930d25a23b40fa52e068c10e85f3e03a7f5ba5aaca5713695" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parking" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba" + +[[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 0.5.18", + "smallvec", + "windows-link", +] + +[[package]] +name = "password-hash" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "346f04948ba92c43e8469c1ee6736c7563d71012b17d40745260fe106aac2166" +dependencies = [ + "base64ct", + "rand_core", + "subtle", +] + +[[package]] +name = "pbkdf2" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8ed6a7761f76e3b9f92dfb0a60a6a6477c61024b775147ff0973a02653abaf2" +dependencies = [ + "digest", + "hmac", +] + +[[package]] +name = "pem-rfc7468" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88b39c9bfcfc231068454382784bb460aae594343fb030d46e9f50a645418412" +dependencies = [ + "base64ct", +] + +[[package]] +name = "percent-encoding" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" + +[[package]] +name = "pin-project" +version = "1.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2466b2336ed02bcdca6b294417127b90ec92038d1d5c4fbeac971a922e0e0924" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c96395f0a926bc13b1c17622aaddda1ecb55d49c8f1bf9777e4d877800a43f8b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkcs1" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8ffb9f10fa047879315e6625af03c164b16962a5368d724ed16323b68ace47f" +dependencies = [ + "der", + "pkcs8", + "spki", +] + +[[package]] +name = "pkcs8" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +dependencies = [ + "der", + "spki", +] + +[[package]] +name = "pkg-config" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6b464fbc74e149a392436b17d523f769e057cb6877f6a5c4618bc6f11800548" + +[[package]] +name = "plain" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" + +[[package]] +name = "poly1305" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8159bd90725d2df49889a078b54f4f79e87f1f8a8444194cdca81d38f5393abf" +dependencies = [ + "cpufeatures", + "opaque-debug", + "universal-hash", +] + +[[package]] +name = "potential_utf" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d83eb9bc6d8e5cf568e7a1101d60ee05e81ed50ea106026f3d18deeb046d7661" +dependencies = [ + "zerovec", +] + +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + +[[package]] +name = "ppv-lite86" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" +dependencies = [ + "zerocopy", +] + +[[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 = "quick-xml" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d3a6e5838b60e0e8fa7a43f22ade549a37d61f8bdbe636d0d7816191de969c2" +dependencies = [ + "memchr", +] + +[[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 = "5.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" + +[[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.8.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e058c7de0b26af77780c769414d6257830bb240f3c38477dbc2c16e5f54d6d4c" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom 0.2.17", +] + +[[package]] +name = "redox_syscall" +version = "0.5.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" +dependencies = [ + "bitflags", +] + +[[package]] +name = "redox_syscall" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "737970939a87c6fa31e7acad13307bccbb017a073b695b6089a2c484f929e20e" +dependencies = [ + "bitflags", +] + +[[package]] +name = "regex-automata" +version = "0.4.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad8553b9b26413251cbf30e620595c7a41b3887f03da04579c0e6b0d6a06b4b2" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4" + +[[package]] +name = "resolv-conf" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e061d1b48cb8d38042de4ae0a7a6401009d6143dc80d2e2d6f31f0bdd6470c7" + +[[package]] +name = "ring" +version = "0.17.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" +dependencies = [ + "cc", + "cfg-if", + "getrandom 0.2.17", + "libc", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rsa" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8573f03f5883dcaebdfcf4725caa1ecb9c15b2ef50c43a07b816e06799bb12d" +dependencies = [ + "const-oid", + "digest", + "num-bigint-dig", + "num-integer", + "num-traits", + "pkcs1", + "pkcs8", + "rand_core", + "signature", + "spki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustix" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "891efababe418670775f199f0d233d84843c227a0949a883ce15b37c78d6629d" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.61.2", +] + +[[package]] +name = "rustls" +version = "0.21.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f56a14d1f48b391359b22f731fd4bd7e43c97f3c50eee276f3aa09c94784d3e" +dependencies = [ + "log", + "ring", + "rustls-webpki 0.101.7", + "sct", +] + +[[package]] +name = "rustls" +version = "0.23.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d41d731c7d2f962d1ccc364cec258de3c0e93b38c2fb3ba97ac74513048d634" +dependencies = [ + "once_cell", + "ring", + "rustls-pki-types", + "rustls-webpki 0.103.15", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" +dependencies = [ + "base64 0.21.7", +] + +[[package]] +name = "rustls-pemfile" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f4925028c7eb5d1fcdaf196971378ed9d2c1c4efc7dc5d011256f76c99c0a96" +dependencies = [ + "zeroize", +] + +[[package]] +name = "rustls-webpki" +version = "0.101.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765" +dependencies = [ + "ring", + "untrusted", +] + +[[package]] +name = "rustls-webpki" +version = "0.103.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3c3cf1d8b1e7d4927e2d154c3fcb02979afb9939629c62cd9048d4f07b60ac2" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "rustversion" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f" + +[[package]] +name = "ryu" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f" + +[[package]] +name = "schannel" +version = "0.1.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91c1b7e4904c873ef0710c1f407dde2e6287de2bebc1bbbf7d430bb7cbffd939" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "sct" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" +dependencies = [ + "ring", + "untrusted", +] + +[[package]] +name = "security-framework" +version = "3.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7f4bc775c73d9a02cde8bf7b2ec4c9d12743edf609006c7facc23998404cd1d" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2691df843ecc5d231c0b14ece2acc3efb62c0a398c7e1d875f3983ce020e3" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "self_cell" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ab42ca02749e120097e328d91d415325bdf43b1c72c4c8badf37375fe40a813" + +[[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 3.0.6", +] + +[[package]] +name = "serde_json" +version = "1.0.151" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c841b55ecdae098c80dcae9cf767f6f8a0c2cdb3416bbef72181df4d0fe73f14" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "serde_path_to_error" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10a9ff822e371bb5403e391ecd83e182e0e77ba7f6fe0160b795797109d1b457" +dependencies = [ + "itoa", + "serde", + "serde_core", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha1" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a978451301f4db1d02937a4ab3ccce137717b81826e79b7d49ffe3244a13c3b8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "sha2" +version = "0.10.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "shlex" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" + +[[package]] +name = "signal-hook-registry" +version = "1.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b" +dependencies = [ + "errno", + "libc", +] + +[[package]] +name = "signature" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +dependencies = [ + "digest", + "rand_core", +] + +[[package]] +name = "simd-adler32" +version = "0.3.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a219298ac11a56ea9a6d2120044824d6f01aeb034955e7af7bc16858527deea" + +[[package]] +name = "simdutf8" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3a9fe34e3e7a50316060351f37187a3f546bce95496156754b601a5fa71b76e" + +[[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.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba467056f1b547ed52077911161fc86985becbc60e8e1857c8a144dab0def891" +dependencies = [ + "serde", +] + +[[package]] +name = "smtp-proto" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8003eb09806ff2ae4661dd0dca27cbd9f65ba85de06cc0302c364b0d661ba368" + +[[package]] +name = "socket2" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3d1e2c7f27f8d4cb10542a02c49005dbd6e93095799d6f3be745fae9f8fedd4" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "spin" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3763264f6b73151db08c50ff20d7d8a0b8796e021cdea7ceedad07b80155fa0e" +dependencies = [ + "lock_api", +] + +[[package]] +name = "spki" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" +dependencies = [ + "base64ct", + "der", +] + +[[package]] +name = "sqlx" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fefb893899429669dcdd979aff487bd78f4064e5e7907e4269081e0ef7d97dc" +dependencies = [ + "sqlx-core", + "sqlx-macros", + "sqlx-mysql", + "sqlx-postgres", + "sqlx-sqlite", +] + +[[package]] +name = "sqlx-core" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee6798b1838b6a0f69c007c133b8df5866302197e404e8b6ee8ed3e3a5e68dc6" +dependencies = [ + "base64 0.22.1", + "bytes", + "chrono", + "crc", + "crossbeam-queue", + "either", + "event-listener 5.4.2", + "futures-core", + "futures-intrusive", + "futures-io", + "futures-util", + "hashbrown 0.15.5", + "hashlink", + "indexmap", + "log", + "memchr", + "once_cell", + "percent-encoding", + "rustls 0.23.45", + "serde", + "serde_json", + "sha2", + "smallvec", + "thiserror 2.0.20", + "tokio", + "tokio-stream", + "tracing", + "url", + "uuid", + "webpki-roots 0.26.11", +] + +[[package]] +name = "sqlx-macros" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2d452988ccaacfbf5e0bdbc348fb91d7c8af5bee192173ac3636b5fb6e6715d" +dependencies = [ + "proc-macro2", + "quote", + "sqlx-core", + "sqlx-macros-core", + "syn 2.0.119", +] + +[[package]] +name = "sqlx-macros-core" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19a9c1841124ac5a61741f96e1d9e2ec77424bf323962dd894bdb93f37d5219b" +dependencies = [ + "dotenvy", + "either", + "heck", + "hex", + "once_cell", + "proc-macro2", + "quote", + "serde", + "serde_json", + "sha2", + "sqlx-core", + "sqlx-mysql", + "sqlx-postgres", + "sqlx-sqlite", + "syn 2.0.119", + "tokio", + "url", +] + +[[package]] +name = "sqlx-mysql" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa003f0038df784eb8fecbbac13affe3da23b45194bd57dba231c8f48199c526" +dependencies = [ + "atoi", + "base64 0.22.1", + "bitflags", + "byteorder", + "bytes", + "chrono", + "crc", + "digest", + "dotenvy", + "either", + "futures-channel", + "futures-core", + "futures-io", + "futures-util", + "generic-array", + "hex", + "hkdf", + "hmac", + "itoa", + "log", + "md-5", + "memchr", + "once_cell", + "percent-encoding", + "rand", + "rsa", + "serde", + "sha1", + "sha2", + "smallvec", + "sqlx-core", + "stringprep", + "thiserror 2.0.20", + "tracing", + "uuid", + "whoami", +] + +[[package]] +name = "sqlx-postgres" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db58fcd5a53cf07c184b154801ff91347e4c30d17a3562a635ff028ad5deda46" +dependencies = [ + "atoi", + "base64 0.22.1", + "bitflags", + "byteorder", + "chrono", + "crc", + "dotenvy", + "etcetera", + "futures-channel", + "futures-core", + "futures-util", + "hex", + "hkdf", + "hmac", + "home", + "itoa", + "log", + "md-5", + "memchr", + "once_cell", + "rand", + "serde", + "serde_json", + "sha2", + "smallvec", + "sqlx-core", + "stringprep", + "thiserror 2.0.20", + "tracing", + "uuid", + "whoami", +] + +[[package]] +name = "sqlx-sqlite" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2d12fe70b2c1b4401038055f90f151b78208de1f9f89a7dbfd41587a10c3eea" +dependencies = [ + "atoi", + "chrono", + "flume", + "futures-channel", + "futures-core", + "futures-executor", + "futures-intrusive", + "futures-util", + "libsqlite3-sys", + "log", + "percent-encoding", + "serde", + "serde_urlencoded", + "sqlx-core", + "thiserror 2.0.20", + "tracing", + "url", + "uuid", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" + +[[package]] +name = "stop-token" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af91f480ee899ab2d9f8435bfdfc14d08a5754bd9d3fef1f1a1c23336aad6c8b" +dependencies = [ + "async-channel 1.9.0", + "cfg-if", + "futures-core", + "pin-project-lite", +] + +[[package]] +name = "stringprep" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b4df3d392d81bd458a8a621b8bffbd2302a12ffe288a9d931670948749463b1" +dependencies = [ + "unicode-bidi", + "unicode-normalization", + "unicode-properties", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.119" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "3.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8593e8e72159ed2257d083c7a454a85cbf854f37a0966d8d483aff8c8a3ebcee" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" + +[[package]] +name = "synstructure" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "901704edd0dfe137f1987838ee4f259e4e063c31371bdb423f7ae38ec6f77f02" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.6", +] + +[[package]] +name = "tempfile" +version = "3.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd" +dependencies = [ + "fastrand", + "getrandom 0.4.3", + "once_cell", + "rustix", + "windows-sys 0.61.2", +] + +[[package]] +name = "tern-server" +version = "0.1.0" +dependencies = [ + "anyhow", + "argon2", + "async-imap", + "async-native-tls", + "axum", + "base64 0.22.1", + "chacha20poly1305", + "chrono", + "dotenvy", + "futures", + "hex", + "mail-parser 0.11.9", + "mail-send", + "rand", + "serde", + "serde_json", + "sha2", + "sqlx", + "thiserror 2.0.20", + "tokio", + "tokio-test", + "tower", + "tower-http", + "tracing", + "tracing-subscriber", + "uuid", +] + +[[package]] +name = "thiserror" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" +dependencies = [ + "thiserror-impl 1.0.69", +] + +[[package]] +name = "thiserror" +version = "2.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec86235f5fcc2a73650310756d2ac5b138a5780bbbdfae3eeccec992c435ba4f" +dependencies = [ + "thiserror-impl 2.0.20", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc04cd3e1236dd4a98afca4569f2deb3f120e5422a4023be2cb683f8486292af" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.6", +] + +[[package]] +name = "thread_local" +version = "1.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ad99c4c6d32803332c548b1af0540b357b3f5fc0be8f6c6bfe8b2e6ae784070" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "time" +version = "0.3.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb87b95ec50ddfa440816d227a17b2ccbdda963a316a727fda0fc4334f7d134" +dependencies = [ + "deranged", + "num-conv", + "powerfmt", + "serde_core", + "time-core", +] + +[[package]] +name = "time-core" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e1c906769ad99c88eaa54e728060edef082f8e358ff32030cb7c7d315e81109" + +[[package]] +name = "tinystr" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1e27c91459209c2986af3dcf603a5a74a4368754ce37414f59acc971167f643" +dependencies = [ + "displaydoc", + "zerovec", +] + +[[package]] +name = "tinyvec" +version = "1.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd3ca314f692efd6c868f8408f53fe444634a845f96c028b97d35f6a1f79f0ee" + +[[package]] +name = "tokio" +version = "1.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "202caea871b69668250d242070849eb495be178ed697a3e98aebce5bc81a0bed" +dependencies = [ + "bytes", + "libc", + "mio", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.61.2", +] + +[[package]] +name = "tokio-macros" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78773a2a397f451582ce068015985c33193cf6dea8b74d2a639fe457b2f07b0e" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.6", +] + +[[package]] +name = "tokio-rustls" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081" +dependencies = [ + "rustls 0.21.12", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0c85f2c3ef0b1cd58b36682f4b17aaa995f0e5db534d85692b4903abce21f67" +dependencies = [ + "rustls 0.23.45", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3d06f0b082ba57c26b79407372e57cf2a1e28124f78e9479fe80322cf53420b" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-test" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f6d24790a10a7af737693a3e8f1d03faef7e6ca0cc99aae5066f533766de545" +dependencies = [ + "futures-core", + "tokio", + "tokio-stream", +] + +[[package]] +name = "tower" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebe5ef63511595f1344e2d5cfa636d973292adc0eec1f0ad45fae9f0851ab1d4" +dependencies = [ + "futures-core", + "futures-util", + "pin-project-lite", + "sync_wrapper", + "tokio", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-http" +version = "0.6.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cfcf7e2740e6fc6d4d688b4ef00650406bb94adf4731e43c096c3a19fe40840" +dependencies = [ + "bitflags", + "bytes", + "http", + "http-body", + "pin-project-lite", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" +dependencies = [ + "log", + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "tracing-core" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" +dependencies = [ + "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb7f578e5945fb242538965c2d0b04418d38ec25c79d160cd279bf0731c8d319" +dependencies = [ + "matchers", + "nu-ansi-term", + "once_cell", + "regex-automata", + "sharded-slab", + "smallvec", + "thread_local", + "tracing", + "tracing-core", + "tracing-log", +] + +[[package]] +name = "typenum" +version = "1.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20" + +[[package]] +name = "unicode-bidi" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c1cb5db39152898a79168971543b1cb5020dff7fe43c8dc468b0885f5e29df5" + +[[package]] +name = "unicode-ident" +version = "1.0.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d245f478577f809a851594d02313b640fb437e0bb33866753cff937863096954" + +[[package]] +name = "unicode-normalization" +version = "0.1.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fd4f6878c9cb28d874b009da9e8d183b5abc80117c40bbd187a1fde336be6e8" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-properties" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7df058c713841ad818f1dc5d3fd88063241cc61f49f5fbea4b951e8cf5a8d71d" + +[[package]] +name = "universal-hash" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc1de2c688dc15305988b563c3854064043356019f97a4b46276fe734c4f07ea" +dependencies = [ + "crypto-common", + "subtle", +] + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[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.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + +[[package]] +name = "uuid" +version = "1.26.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ef6dac1e96601b4fb3acccccff2139741fcb757cb9a36089bf5be91cfb285ce" +dependencies = [ + "getrandom 0.4.3", + "js-sys", + "serde_core", + "wasm-bindgen", +] + +[[package]] +name = "valuable" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] +name = "wasip2" +version = "1.0.4+wasi-0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b67efb37e106e55ce722a510d6b5f9c17f083e5fc79afc2badeb12cc313d9487" +dependencies = [ + "wit-bindgen", +] + +[[package]] +name = "wasite" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8dad83b4f25e74f184f64c43b150b91efe7647395b42289f38e50566d82855b" + +[[package]] +name = "wasm-bindgen" +version = "0.2.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aecb87a33d3b0c5e3b7aa46336eaf486cffafbd281b195e4c8b80d50df2351bf" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a690d511e3c1a8b3a55e33511e3c2c00c78415cd23650f32b808627f5696b9ed" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "411e4887f0071ef2d2164a9d5fdf2d20efbef78fccd3a78b0c10a1dc5295e48a" +dependencies = [ + "bumpalo", + "proc-macro2", + "quote", + "syn 3.0.6", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81941cd78d0c92026c33e5e01312845a4cb1e9af3407f9134b100dd03144103e" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "webpki-roots" +version = "0.26.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "521bc38abb08001b01866da9f51eb7c5d647a19260e00054a8c7fd5f9e57f7a9" +dependencies = [ + "webpki-roots 1.0.9", +] + +[[package]] +name = "webpki-roots" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dcd9d09a39985f5344844e66b0c530a33843579125f23e21e9f0f220850f22a" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "whoami" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d4a4db5077702ca3015d3d02d74974948aba2ad9e12ab7df718ee64ccd7e97d" +dependencies = [ + "libredox", + "wasite", +] + +[[package]] +name = "widestring" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72069c3113ab32ab29e5584db3c6ec55d416895e60715417b5b883a357c3e471" + +[[package]] +name = "windows-core" +version = "0.62.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-implement" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "windows-interface" +version = "0.59.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-registry" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02752bf7fbdcce7f2a27a742f798510f3e5ad88dbe84871e5168e2120c3d5720" +dependencies = [ + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-result" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-strings" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[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 = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "wit-bindgen" +version = "0.57.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ebf944e87a7c253233ad6766e082e3cd714b5d03812acc24c318f549614536e" + +[[package]] +name = "writeable" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ad82d2a33cdc9674dc7465672f271e096168fcdbe0f799d9e6db8c5892679dc" + +[[package]] +name = "xz2" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "388c44dc09d76f1536602ead6d325eb532f5c122f17782bd57fb47baeeb767e2" +dependencies = [ + "lzma-sys", +] + +[[package]] +name = "yoke" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "709fe23a0424b6a435d82152b1bd3fdfb0833487d5fa90d05d42762a9891fef5" +dependencies = [ + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33811428bee40dbceb6d545e95754741d17a6aef9a4849f0fd62e2ba4f412a78" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.6", + "synstructure", +] + +[[package]] +name = "zerocopy" +version = "0.8.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d35102a9f36d089ccae9e4c6802bc118be4487b80aaffc0ab4e0cf5ce92d2873" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "146c01f5ab44258da43cf276c74a2763db2ff3969c9c652c3f2de07041d0b2bc" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[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 3.0.6", + "synstructure", +] + +[[package]] +name = "zeroize" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13c156562582aa81c60cb29407084cdb54c4164760106ab78e6c5b0858cf64e" +dependencies = [ + "zeroize_derive", +] + +[[package]] +name = "zeroize_derive" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c50655cbb0fe3fc43170059e702f1ce5e19b84cec58dc87b037a09935c2f328" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[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.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb0464e17806c1d976d5cba29399c7f08e516e279e2ba493f63123b5fca67dd8" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.11.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34df6fc39dbd26ddc9c10e6a2984476e13acce22e64e4487636ef494369225da" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.6", +] + +[[package]] +name = "zip" +version = "2.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabe6324e908f85a1c52063ce7aa26b68dcb7eb6dbc83a2d148403c9bc3eba50" +dependencies = [ + "aes", + "arbitrary", + "bzip2", + "constant_time_eq", + "crc32fast", + "crossbeam-utils", + "deflate64", + "displaydoc", + "flate2", + "getrandom 0.3.4", + "hmac", + "indexmap", + "lzma-rs", + "memchr", + "pbkdf2", + "sha1", + "thiserror 2.0.20", + "time", + "xz2", + "zeroize", + "zopfli", + "zstd", +] + +[[package]] +name = "zlib-rs" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b268e58e7c693d7c271f93ffc4ba3b380412554231c85bf61ca7af91042a4112" + +[[package]] +name = "zmij" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b" + +[[package]] +name = "zopfli" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f05cd8797d63865425ff89b5c4a48804f35ba0ce8d125800027ad6017d2b5249" +dependencies = [ + "bumpalo", + "crc32fast", + "log", + "simd-adler32", +] + +[[package]] +name = "zstd" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91ee311a569c327171651566e07972200e76fcfe2242a4fa446149a3881c08a" +dependencies = [ + "zstd-safe", +] + +[[package]] +name = "zstd-safe" +version = "7.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64d80649ab6db9d9f6f9c80a40becd948eda4714a0a5ac8c4d157a32231c7882" +dependencies = [ + "zstd-sys", +] + +[[package]] +name = "zstd-sys" +version = "2.1.0+zstd.1.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ef0a8027ec3ee71300ab3bcbcd0393f434aa72b91ca6d635a39941deae8eea0" +dependencies = [ + "cc", + "pkg-config", +] diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..8338071 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,41 @@ +[package] +name = "tern-server" +version = "0.1.0" +edition = "2021" +description = "Tern sync server — the only component that speaks IMAP/SMTP" + +[dependencies] +tokio = { version = "1", features = ["full"] } +axum = { version = "0.7", features = ["macros"] } +tower = "0.5" +tower-http = { version = "0.6", features = ["trace", "cors"] } + +sqlx = { version = "0.8", features = ["runtime-tokio", "tls-rustls", "postgres", "chrono", "uuid", "migrate"] } + +async-imap = { version = "0.11", default-features = false, features = ["runtime-tokio"] } +async-native-tls = { version = "0.6", default-features = false, features = ["runtime-tokio"] } +mail-parser = "0.11" +mail-send = "0.4" + +serde = { version = "1", features = ["derive"] } +serde_json = "1" +chrono = { version = "0.4", features = ["serde"] } +uuid = { version = "1", features = ["v4", "serde"] } + +argon2 = "0.5" +rand = "0.8" +chacha20poly1305 = "0.10" +base64 = "0.22" +sha2 = "0.10" +hex = "0.4" + +thiserror = "2" +anyhow = "1" +dotenvy = "0.15" +tracing = "0.1" +tracing-subscriber = { version = "0.3", features = ["env-filter"] } + +futures = "0.3" + +[dev-dependencies] +tokio-test = "0.4" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..206f525 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +FROM rust:1-bookworm AS builder +WORKDIR /build +COPY Cargo.toml Cargo.lock* ./ +COPY src ./src +COPY migrations ./migrations +RUN cargo build --release + +FROM debian:bookworm-slim +RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates && rm -rf /var/lib/apt/lists/* +WORKDIR /app +COPY --from=builder /build/target/release/tern-server ./tern-server +COPY migrations ./migrations +EXPOSE 8080 +CMD ["./tern-server"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..daf36b2 --- /dev/null +++ b/README.md @@ -0,0 +1,31 @@ +# tern-server + +The sync server for [Tern](../) — the only component that ever speaks IMAP/SMTP. See [`docs/server-architecture-spec.md`](docs/server-architecture-spec.md) for the full design. + +## What's built (build-order phases 1–2) + +- **DB schema** (`migrations/`): users/sessions, accounts + per-account sync state, messages/bodies/attachments, folders, tags, rules, devices — the full data model from the spec, even though rules/tags/threading execution isn't implemented yet. +- **IMAP sync engine** (`src/imap_sync/`): one task per account — connects over TLS, selects INBOX, tracks `UIDVALIDITY` (re-syncing the account from scratch if it changes), fetches new mail headers-first (`ENVELOPE`/`FLAGS`) then lazily fills in bodies/attachments in a trailing pass, and IDLEs for pushed changes with a periodic renewal and jittered-backoff reconnect on any failure. +- **Minimal REST API** (`src/api/`): local username/password auth (Argon2 + bearer session tokens), account management (IMAP credentials encrypted at rest with ChaCha20-Poly1305), folder listing, cursor-paginated message listing, single-message + thread-by-id fetch, and a polling `/events` delta endpoint. + +## What's explicitly deferred + +Per the spec's suggested build order (§9), not yet built: SMTP sending/outbox, tag & rule *execution* (schema exists, engine doesn't), the JWZ threading algorithm (each message currently gets its own `thread_id` — no linking/merging pass yet), spam header rules, WebSocket push (the `/events` poll endpoint is the interim/fallback path), and the Android/webapp-facing UnifiedPush integration. + +## Running locally + +```bash +cp .env.example .env +openssl rand -base64 32 # paste into .env as CREDENTIAL_KEY +docker compose up -d db +cargo run +``` + +Or the whole stack (server + Postgres + nginx) via `docker compose up -d` once `CREDENTIAL_KEY` is exported in your shell or a `.env` file docker compose picks up. + +Migrations run automatically on startup (`sqlx::migrate!`). + +## Notes on deviations from the spec + +- **Encryption**: §7 suggests libsodium secretbox; this uses ChaCha20-Poly1305 (RustCrypto) instead — same AEAD construction family, but pure Rust with no libsodium system dependency. See `src/crypto.rs`. +- **Web framework**: axum, per your choice between the spec's axum/actix-web options. diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..63271f7 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,50 @@ +services: + db: + image: postgres:16-alpine + restart: unless-stopped + environment: + POSTGRES_USER: tern + POSTGRES_PASSWORD: tern + POSTGRES_DB: tern + volumes: + - db-data:/var/lib/postgresql/data + ports: + - "127.0.0.1:5432:5432" + healthcheck: + test: ["CMD-SHELL", "pg_isready -U tern"] + interval: 5s + timeout: 5s + retries: 10 + + server: + build: . + restart: unless-stopped + depends_on: + db: + condition: service_healthy + environment: + DATABASE_URL: postgres://tern:tern@db:5432/tern + BIND_ADDR: 0.0.0.0:8080 + CREDENTIAL_KEY: ${CREDENTIAL_KEY} + BLOB_STORAGE_DIR: /data/blobs + RUST_LOG: tern_server=info + volumes: + - blob-data:/data/blobs + # Not published directly — nginx is the only thing that should be + # reachable from outside (server-architecture-spec.md §7). + expose: + - "8080" + + nginx: + image: nginx:alpine + restart: unless-stopped + depends_on: + - server + ports: + - "80:80" + volumes: + - ./nginx.conf:/etc/nginx/conf.d/default.conf:ro + +volumes: + db-data: + blob-data: diff --git a/docs/server-architecture-spec.md b/docs/server-architecture-spec.md new file mode 100644 index 0000000..9956fa3 --- /dev/null +++ b/docs/server-architecture-spec.md @@ -0,0 +1,160 @@ +# Modern Email App — Architecture & Planning Doc + +## 1. High-Level Shape + +``` +[IMAP/SMTP server] <--IMAP IDLE + SMTP submission--> [Sync Server / API] <--REST/WS--> [Webapp] + | + |--DB (Postgres/SQLite) + |--Rule Engine + |--Push (UnifiedPush/WS) + | + [Android Client] +``` + +Your server is the **only** thing that ever speaks IMAP/SMTP. Clients only ever talk to your API. This is the right call — it means clients stay dumb, and you can swap the mail-protocol layer later (e.g. add JMAP) without touching clients. + +--- + +## 2. Core Decisions + +1. **Sync direction: one-way.** Server only fetches from IMAP INBOX; it never writes state back to the source server. Sending is the one outbound path, via SMTP submission. This simplifies the whole system considerably — no UID conflict handling, no reconciling flag changes made by another client. +2. **Multi-user, multi-account server.** This is a shared/universal server: multiple people use one deployment. Each user has one local (internal) account plus any number of external IMAP accounts they add. Data model needs a `users` table, with `accounts` belonging to a `user_id`. +3. **Provider support: self-hosted only, for now.** Target is a Docker-based mail server (plain IMAP/SMTP auth). Gmail/Apple (OAuth2/XOAUTH2) is future work — see §11. +4. **Auth: independent, local.** Your own user accounts/sessions, decoupled from IMAP credentials (which are stored server-side, encrypted, per added account). SSO via Authentik is future work — see §11. +5. **Folders: virtual.** The sync engine only ever fetches from IMAP INBOX. All organization (folders, tags, rules) happens inside the app on top of that flat incoming stream — there's no concept of mirroring the source server's folder tree. +6. **Threading: use the standard algorithm.** See §3.6 below. + +--- + +## 3. Server + +### 3.1 IMAP Sync Engine +- One persistent IDLE connection per account per folder (or per account, cycling folders — IDLE only watches one folder at a time per connection, so watching multiple folders means multiple connections or periodic re-select). +- Fallback poll interval (e.g. every 5–15 min) for servers that don't support IDLE, and as a safety net if IDLE silently dies (it does, in practice — TCP connections die without FIN, so you need a NOOP/keepalive heartbeat and a watchdog to detect a stalled IDLE session and reconnect). +- Backoff/reconnect logic with jitter for flaky servers. +- Initial sync: full folder fetch with UID ranges, paged, don't pull full bodies for old mail unless requested (fetch headers/flags first, bodies lazily or in a background pass). +- Track `UIDVALIDITY` per folder — if it changes, your cached UIDs are invalid and you need to re-sync that folder. +- MIME parsing library (don't hand-roll this — e.g. Rust: `mail-parser`; Python: `email` stdlib or `flanker`; Go: `emersion/go-message`; Node: `mailparser`). + +### 3.2 Storage +- Store parsed structure (headers, text/html body, attachment metadata) in DB. +- Store raw MIME blob too (for re-parsing if your parser improves, and for "view source"). **Filesystem** for now (keep large binary out of Postgres) — S3-compatible object storage is future work, see §11. +- Attachments: store by content-hash, dedupe identical attachments across messages; filesystem path derived from the hash. + +### 3.3 Sending +- SMTP submission (port 587, STARTTLS) using stored credentials. +- Outbox/queue table with status (pending/sent/failed) and retry with backoff — don't send synchronously in the request path. +- Draft storage. + +### 3.4 Data Model (sketch) +- `users` (local API auth: username, password hash, etc.) +- `accounts` (user_id, IMAP/SMTP creds encrypted, server host/port, provider type — for future OAuth support) +- `sync_state` (account_id, uidvalidity, last_synced_uid — one row per account, since we only ever watch INBOX) +- `messages` (account_id, uid, message_id header, in_reply_to, references[], from/to/subject, date, flags, thread_id, spam_score, raw_blob_ref) +- `bodies` (message_id, text, html — or separate table if you lazy-load) +- `attachments` (message_id, filename, content_type, size, blob_ref, content_hash) +- `folders` (user_id, name — app-level/virtual, not tied to IMAP) + `message_folders` (message_id, folder_id) if a message can live in more than one virtual folder, otherwise just a `folder_id` column on `messages` +- `tags` (user_id, name, color) + `message_tags` (many-to-many) +- `rules` (user_id, name, conditions JSON, actions JSON, enabled, priority/order) +- `devices` (user_id, for push: unifiedpush endpoint / websocket session) + +### 3.5 Rule Engine +- **Manual rules**: user-defined, run on new-mail arrival (and optionally re-runnable on demand against existing mail). Conditions: header match (from/to/subject/list-id), body contains, regex; Actions: tag, move folder, mark read, delete, notify/don't-notify. +- **Spam rules**: same engine, but with header-parsing conditions specifically for Proxmox Mail Gateway's added headers — it runs SpamAssassin under the hood, so look for: + - `X-SPAM-LEVEL`, `X-SPAM-STATUS`, `X-SPAM-SCORE` (or similarly named, check your PMG config — these are configurable) + - Threshold-based rule: score > N → tag as spam / move to Junk. +- Keep rules as structured JSON (condition tree + action list) rather than free-text DSL, so both webapp and rule-engine can render/edit them without a parser. +- Order/priority matters if multiple rules can match — decide first-match-wins vs all-matches-apply. + +### 3.6 Threading +Use the **JWZ algorithm** (Jamie Zawinski's threading algorithm) rather than building your own — it's the de facto standard (Gmail, Thunderbird, and most mail clients implement a variant of it) and it already handles the annoying edge cases: missing parent messages, out-of-order arrival, duplicate Message-IDs, and messages with no reference headers at all. + +**Headers to parse and store per message:** +- `Message-ID` — unique ID of this message +- `In-Reply-To` — direct parent's Message-ID +- `References` — full ancestor chain (more reliable than In-Reply-To alone; some clients/lists only set one or the other) +- `Subject` — fallback only, used for subject-based grouping when a message has no reference headers (common with some mailing lists that strip them) + +**How it works, roughly:** +1. Build a lookup table of all messages by Message-ID. +2. For each message, walk its `References` (falling back to `In-Reply-To`) to find its parent; link them into a tree. Create placeholder "container" nodes for referenced-but-not-yet-fetched parents (they may arrive later, out of order — since IDLE delivers mail as it arrives, not in thread order). +3. Group root-level containers that share a normalized subject (strip `Re:`/`Fwd:`/`[list-name]` prefixes) when they have no reference-based link, as a fallback. + +**Data model:** +- Store `in_reply_to` and `references` on each message (already added to §3.4). +- Compute a `thread_id` at ingest time — make it its own generated ID (not just "use the root Message-ID"), because threads sometimes need to **merge** later: a message you thought was a new thread turns out to be a reply once a missing ancestor message arrives. A separate `thread_id` with a re-parent/merge step handles this cleanly; reusing the root Message-ID as the thread key doesn't. +- Threading is scoped **per account** (a thread never spans two different IMAP accounts, even for the same user) — keeps this simple and matches how threads actually form. + +**Left to the client/UI layer, not the backend:** whether to display as a collapsed conversation view (one row per thread) or a flat list with grouping. The API just needs to expose `thread_id` on each message and, ideally, a "fetch thread" endpoint — the rendering choice doesn't change the backend work. + +### 3.7 Future: AI tagging/summarization hook +- Don't build this now, but design the rule engine's action list to be extensible — an action type like `run_pipeline: summarize` that enqueues a background job is enough of a hook. Keep it async (job queue), not inline in the sync path, so a slow/down AI backend never blocks mail ingestion. + +### 3.8 Notifications +- **WebSocket**: for webapp, push events as they happen (new mail, flag change, rule action). +- **Polling fallback**: simple `GET /events?since=` for legacy/degraded clients. +- **UnifiedPush**: primary for Android — makes sense given GrapheneOS has no Google Play Services/FCM. Your server acts as the UnifiedPush application server; register the distributor endpoint per device, POST a (minimal, content-free — just "you have new mail, sync now") message on new mail. Keep push payloads content-free and have the client pull the actual message over the authenticated API, so you're not putting email content through a third-party push relay. + +--- + +## 4. API Layer — REST +- Decided: REST, not GraphQL. +- Needs a **delta/sync endpoint** per client (mobile especially): "give me everything changed since cursor X" rather than clients re-fetching full folder listings. +- Pagination on message lists (cursor-based, not offset, since new mail arrives continuously). + +## 5. Webapp +UI/UX is being scoped in a separate doc. Backend-relevant constraints only: +- HTML email rendering: sandbox it (iframe with strict CSP, or sanitize to a safe subset) — untrusted HTML email is a real XSS vector. Block remote image loading by default (common privacy leak vector — read receipts via tracking pixels). + +## 6. Android Client +UI/UX is being scoped in a separate doc. Backend-relevant constraints only: +- UnifiedPush receiver + local notification. +- Local cache (Room/SQLite) synced via the delta endpoint. +- Runs fine as a standard GrapheneOS-compatible app as long as you don't depend on Play Services for anything (auth, push, maps, etc.) — UnifiedPush avoids that for notifications specifically. + +## 7. Security Notes +- Encrypt stored IMAP/SMTP credentials at rest (not just DB access control — actual encryption, e.g. libsodium secretbox with a server-held key, or better, a key derived from something you don't also store in the same DB). +- Server↔IMAP/SMTP: TLS always (implicit TLS or STARTTLS, never plaintext). +- Client↔API: assumed to always sit behind **nginx** as reverse proxy — nginx terminates TLS and forwards plain HTTP internally; the API itself doesn't need to handle certs. Bind the API to localhost/internal network only, never expose it directly. +- Rate-limit login/API auth endpoints (can partly live at the nginx layer too). +- Sanitize all rendered HTML server-side or client-side before display — don't trust the sanitizer step to be "someone else's problem." + +## 8. Explicitly Out of Scope (not planned at all — flag if this changes) +- Calendar/contacts (CalDAV/CardDAV) +- PGP/S-MIME encryption +- POP3 support +- Server-side Sieve filters (your rule engine replaces this) +- Vacation/auto-responder +- Multi-protocol beyond IMAP/SMTP (no JMAP, no Exchange/EWS) +- Two-way IMAP sync (see §2.1 — deliberately one-way) + +## 9. Suggested Build Order +1. IMAP sync engine + DB schema (no clients yet) — prove IDLE + reconnect logic works reliably first, it's the riskiest part. +2. Minimal REST API + folder/message read endpoints. +3. Webapp: read-only mail view. +4. Sending (SMTP submission + outbox). +5. Tags + manual rules + threading. +6. Spam header rules (Proxmox-specific). +7. WebSocket + polling notifications. +8. Android client + UnifiedPush. +9. Future items from §11, as needed. + +--- + +## 10. Stack — Decided +- **Server**: Rust. Suggested crates: `async-imap` (IMAP + IDLE), `lettre` or `mail-send` (SMTP submission), `mail-parser` (MIME parsing), `tokio` (async runtime), `axum` or `actix-web` (REST API), `sqlx` (Postgres access, compile-time checked queries). +- **DB**: Postgres — gives full-text search (`tsvector`) and scales cleanly across multiple users/accounts. +- **Deployment**: Docker Compose (server + Postgres, nginx as reverse proxy in front — see §7). + +--- + +## 11. Future Plans (explicitly deferred, not designed yet) + +These are noted so the current design doesn't accidentally box them out, but none of this is being built now: + +- **Gmail / Apple Mail support** — requires OAuth2/XOAUTH2 for IMAP auth instead of plain password. The `accounts` table already has a `provider type` field for this reason; when this lands, the sync engine needs a token-refresh flow alongside the current password-based auth, and Gmail's IMAP quirks (e.g. `X-GM-THRID`, label-as-folder model) may end up feeding directly into the threading model rather than relying purely on JWZ for that provider. +- **SSO via Authentik** — replace/augment local username+password API auth with OIDC against Authentik. Since API auth is already independent of IMAP credentials (§2.4), this should slot in without touching the mail-sync side at all. +- **AI tagging/sorting/summarization** — hook point already reserved in the rule engine (§3.7): an async, queued pipeline action type, kept off the ingest hot path. +- **Two-way sync** — if a future need arises to reflect read/flag/delete state back to the source IMAP server (e.g. also using a native client on the same mailbox), this would need UID conflict handling and is a substantial change to §2.1's current one-way model — not a small add-on. +- **S3-compatible object storage for attachments/raw blobs** — swap in for the filesystem store from §3.2 once storage needs outgrow a single disk (or you want multi-node deployment). Keep the content-hash-addressed storage scheme from day one so this swap is a storage-backend change, not a data-model change. diff --git a/migrations/0000_extensions.sql b/migrations/0000_extensions.sql new file mode 100644 index 0000000..6a448b8 --- /dev/null +++ b/migrations/0000_extensions.sql @@ -0,0 +1 @@ +CREATE EXTENSION IF NOT EXISTS pgcrypto; -- gen_random_uuid() diff --git a/migrations/0001_users_auth.sql b/migrations/0001_users_auth.sql new file mode 100644 index 0000000..48cb685 --- /dev/null +++ b/migrations/0001_users_auth.sql @@ -0,0 +1,17 @@ +-- Local API auth, independent of IMAP credentials (server-architecture-spec.md §2.4) + +CREATE TABLE users ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + username TEXT NOT NULL UNIQUE, + password_hash TEXT NOT NULL, + created_at TIMESTAMPTZ NOT NULL DEFAULT now() +); + +CREATE TABLE sessions ( + token UUID PRIMARY KEY DEFAULT gen_random_uuid(), + user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE, + created_at TIMESTAMPTZ NOT NULL DEFAULT now(), + expires_at TIMESTAMPTZ NOT NULL +); + +CREATE INDEX sessions_user_id_idx ON sessions(user_id); diff --git a/migrations/0002_accounts_sync.sql b/migrations/0002_accounts_sync.sql new file mode 100644 index 0000000..60fd2e0 --- /dev/null +++ b/migrations/0002_accounts_sync.sql @@ -0,0 +1,32 @@ +-- IMAP/SMTP accounts a user has added, plus per-account sync bookkeeping. +-- One-way sync: server only ever fetches from IMAP INBOX (§2.1), so +-- sync_state has exactly one row per account, not per-folder. + +CREATE TABLE accounts ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE, + name TEXT NOT NULL, + provider_type TEXT NOT NULL DEFAULT 'generic_imap', -- reserved for future oauth providers (gmail, apple) + imap_host TEXT NOT NULL, + imap_port INTEGER NOT NULL DEFAULT 993, + imap_use_tls BOOLEAN NOT NULL DEFAULT true, + smtp_host TEXT NOT NULL, + smtp_port INTEGER NOT NULL DEFAULT 587, + smtp_use_starttls BOOLEAN NOT NULL DEFAULT true, + username TEXT NOT NULL, + -- credentials encrypted at rest (ChaCha20-Poly1305, server-held key) — never stored plaintext + encrypted_password BYTEA NOT NULL, + password_nonce BYTEA NOT NULL, + created_at TIMESTAMPTZ NOT NULL DEFAULT now() +); + +CREATE INDEX accounts_user_id_idx ON accounts(user_id); + +CREATE TABLE sync_state ( + account_id UUID PRIMARY KEY REFERENCES accounts(id) ON DELETE CASCADE, + uidvalidity BIGINT, + last_synced_uid BIGINT NOT NULL DEFAULT 0, + status TEXT NOT NULL DEFAULT 'pending', -- pending | syncing | idle | error + last_error TEXT, + updated_at TIMESTAMPTZ NOT NULL DEFAULT now() +); diff --git a/migrations/0003_messages_bodies_attachments.sql b/migrations/0003_messages_bodies_attachments.sql new file mode 100644 index 0000000..6f51f51 --- /dev/null +++ b/migrations/0003_messages_bodies_attachments.sql @@ -0,0 +1,60 @@ +-- Core message store (server-architecture-spec.md §3.4, §3.6). +-- thread_id is its own generated id (not the root Message-ID) because threads +-- can merge later once a missing ancestor arrives — see §3.6. + +CREATE TABLE folders ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE, + name TEXT NOT NULL, + created_at TIMESTAMPTZ NOT NULL DEFAULT now(), + UNIQUE (user_id, name) +); + +CREATE TABLE messages ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + account_id UUID NOT NULL REFERENCES accounts(id) ON DELETE CASCADE, + folder_id UUID REFERENCES folders(id) ON DELETE SET NULL, + uid BIGINT NOT NULL, + message_id TEXT, -- Message-ID header (not guaranteed unique across servers) + in_reply_to TEXT, + references_ TEXT[] NOT NULL DEFAULT '{}', + thread_id UUID NOT NULL DEFAULT gen_random_uuid(), + from_addr TEXT, + from_name TEXT, + to_addrs TEXT[] NOT NULL DEFAULT '{}', + cc_addrs TEXT[] NOT NULL DEFAULT '{}', + subject TEXT, + sent_at TIMESTAMPTZ, + flags TEXT[] NOT NULL DEFAULT '{}', -- \Seen, \Flagged, etc, plus app flags + spam_score REAL, + body_fetched BOOLEAN NOT NULL DEFAULT false, -- headers-first sync: body may be lazy + raw_blob_ref TEXT, -- filesystem path to the raw MIME blob + created_at TIMESTAMPTZ NOT NULL DEFAULT now(), + UNIQUE (account_id, uid) +); + +CREATE INDEX messages_account_id_idx ON messages(account_id); +CREATE INDEX messages_thread_id_idx ON messages(thread_id); +CREATE INDEX messages_message_id_idx ON messages(message_id); +CREATE INDEX messages_in_reply_to_idx ON messages(in_reply_to); +CREATE INDEX messages_sent_at_idx ON messages(sent_at DESC); +CREATE INDEX messages_folder_id_idx ON messages(folder_id); + +CREATE TABLE bodies ( + message_id UUID PRIMARY KEY REFERENCES messages(id) ON DELETE CASCADE, + text_body TEXT, + html_body TEXT +); + +CREATE TABLE attachments ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + message_id UUID NOT NULL REFERENCES messages(id) ON DELETE CASCADE, + filename TEXT, + content_type TEXT, + size BIGINT NOT NULL, + content_hash TEXT NOT NULL, -- dedupe identical attachments across messages + blob_ref TEXT NOT NULL -- filesystem path derived from content_hash +); + +CREATE INDEX attachments_message_id_idx ON attachments(message_id); +CREATE INDEX attachments_content_hash_idx ON attachments(content_hash); diff --git a/migrations/0004_tags_rules_devices.sql b/migrations/0004_tags_rules_devices.sql new file mode 100644 index 0000000..9b09680 --- /dev/null +++ b/migrations/0004_tags_rules_devices.sql @@ -0,0 +1,43 @@ +-- Tags, rule engine, and push-notification device registrations. +-- Schema only in this phase — the rule engine execution itself is a later +-- build-order phase (server-architecture-spec.md §9, item 5). + +CREATE TABLE tags ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE, + name TEXT NOT NULL, + color TEXT, + UNIQUE (user_id, name) +); + +CREATE TABLE message_tags ( + message_id UUID NOT NULL REFERENCES messages(id) ON DELETE CASCADE, + tag_id UUID NOT NULL REFERENCES tags(id) ON DELETE CASCADE, + PRIMARY KEY (message_id, tag_id) +); + +-- Structured JSON (condition tree + action list) rather than a free-text DSL, +-- so both webapp and rule-engine can render/edit rules without a parser (§3.5). +CREATE TABLE rules ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE, + name TEXT NOT NULL, + conditions JSONB NOT NULL, + actions JSONB NOT NULL, + enabled BOOLEAN NOT NULL DEFAULT true, + priority INTEGER NOT NULL DEFAULT 0, + created_at TIMESTAMPTZ NOT NULL DEFAULT now() +); + +CREATE INDEX rules_user_id_priority_idx ON rules(user_id, priority); + +CREATE TABLE devices ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE, + kind TEXT NOT NULL, -- 'unifiedpush' | 'websocket' + endpoint TEXT, -- unifiedpush distributor endpoint URL + created_at TIMESTAMPTZ NOT NULL DEFAULT now(), + last_seen_at TIMESTAMPTZ +); + +CREATE INDEX devices_user_id_idx ON devices(user_id); diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..b567aea --- /dev/null +++ b/nginx.conf @@ -0,0 +1,22 @@ +# Minimal reverse proxy per server-architecture-spec.md §7: nginx terminates +# TLS (add a cert + `listen 443 ssl;` for real deployment — this is the +# plain-HTTP local-dev shape) and forwards to the API, which never needs to +# be reachable directly. + +server { + listen 80; + server_name _; + + location / { + proxy_pass http://server:8080; + proxy_http_version 1.1; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + + # WebSocket upgrade support, once the WS notification endpoint lands. + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + } +} diff --git a/src/api/accounts.rs b/src/api/accounts.rs new file mode 100644 index 0000000..8a07259 --- /dev/null +++ b/src/api/accounts.rs @@ -0,0 +1,73 @@ +use crate::api::middleware::CurrentUser; +use crate::api::state::AppState; +use crate::error::ApiResult; +use crate::models::account::{Account, AccountPublic}; +use axum::{extract::State, Json}; +use serde::Deserialize; +use uuid::Uuid; + +#[derive(Deserialize)] +pub struct CreateAccountRequest { + pub name: String, + pub imap_host: String, + pub imap_port: i32, + pub smtp_host: String, + pub smtp_port: i32, + pub username: String, + pub password: String, +} + +pub async fn list(State(state): State, user: CurrentUser) -> ApiResult>> { + let accounts: Vec = sqlx::query_as("SELECT * FROM accounts WHERE user_id = $1 ORDER BY created_at") + .bind(user.user_id) + .fetch_all(&state.pool) + .await?; + + Ok(Json(accounts.into_iter().map(AccountPublic::from).collect())) +} + +pub async fn create( + State(state): State, + user: CurrentUser, + Json(req): Json, +) -> ApiResult> { + let encrypted = state.cipher.encrypt(&req.password)?; + + let account: Account = sqlx::query_as( + "INSERT INTO accounts \ + (user_id, name, imap_host, imap_port, smtp_host, smtp_port, username, encrypted_password, password_nonce) \ + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) RETURNING *", + ) + .bind(user.user_id) + .bind(&req.name) + .bind(&req.imap_host) + .bind(req.imap_port) + .bind(&req.smtp_host) + .bind(req.smtp_port) + .bind(&req.username) + .bind(&encrypted.ciphertext) + .bind(&encrypted.nonce) + .fetch_one(&state.pool) + .await?; + + sqlx::query("INSERT INTO sync_state (account_id) VALUES ($1)") + .bind(account.id) + .execute(&state.pool) + .await?; + + Ok(Json(account.into())) +} + +pub async fn delete( + State(state): State, + user: CurrentUser, + axum::extract::Path(account_id): axum::extract::Path, +) -> ApiResult> { + sqlx::query("DELETE FROM accounts WHERE id = $1 AND user_id = $2") + .bind(account_id) + .bind(user.user_id) + .execute(&state.pool) + .await?; + + Ok(Json(serde_json::json!({ "ok": true }))) +} diff --git a/src/api/auth.rs b/src/api/auth.rs new file mode 100644 index 0000000..aef5cdd --- /dev/null +++ b/src/api/auth.rs @@ -0,0 +1,79 @@ +use crate::api::state::AppState; +use crate::auth::{hash_password, verify_password}; +use crate::error::{ApiError, ApiResult}; +use crate::models::User; +use axum::{extract::State, Json}; +use chrono::{Duration, Utc}; +use serde::{Deserialize, Serialize}; +use uuid::Uuid; + +#[derive(Deserialize)] +pub struct RegisterRequest { + pub username: String, + pub password: String, +} + +#[derive(Deserialize)] +pub struct LoginRequest { + pub username: String, + pub password: String, +} + +#[derive(Serialize)] +pub struct SessionResponse { + pub token: Uuid, + pub user_id: Uuid, +} + +pub async fn register(State(state): State, Json(req): Json) -> ApiResult> { + if req.username.trim().is_empty() || req.password.len() < 8 { + return Err(ApiError::BadRequest( + "username must be non-empty and password must be at least 8 characters".into(), + )); + } + + let password_hash = hash_password(&req.password)?; + + let user: User = sqlx::query_as( + "INSERT INTO users (username, password_hash) VALUES ($1, $2) RETURNING *", + ) + .bind(&req.username) + .bind(&password_hash) + .fetch_one(&state.pool) + .await + .map_err(|e| match e { + sqlx::Error::Database(db_err) if db_err.is_unique_violation() => { + ApiError::BadRequest("username already taken".into()) + } + other => ApiError::Sqlx(other), + })?; + + create_session(&state, user.id).await.map(Json) +} + +pub async fn login(State(state): State, Json(req): Json) -> ApiResult> { + let user: Option = sqlx::query_as("SELECT * FROM users WHERE username = $1") + .bind(&req.username) + .fetch_optional(&state.pool) + .await?; + + let user = user.ok_or(ApiError::Unauthorized)?; + if !verify_password(&req.password, &user.password_hash)? { + return Err(ApiError::Unauthorized); + } + + create_session(&state, user.id).await.map(Json) +} + +async fn create_session(state: &AppState, user_id: Uuid) -> ApiResult { + let expires_at = Utc::now() + Duration::hours(state.session_ttl_hours); + let row: (Uuid,) = sqlx::query_as( + "INSERT INTO sessions (user_id, expires_at) VALUES ($1, $2) RETURNING token", + ) + .bind(user_id) + .bind(expires_at) + .fetch_one(&state.pool) + .await?; + + Ok(SessionResponse { token: row.0, user_id }) +} diff --git a/src/api/events.rs b/src/api/events.rs new file mode 100644 index 0000000..c917e9a --- /dev/null +++ b/src/api/events.rs @@ -0,0 +1,49 @@ +//! `GET /events?since=` — the delta/sync endpoint from +//! server-architecture-spec.md §4 and the polling-fallback path from §3.8. +//! WebSocket push is a later build-order phase (§9 item 7); this polling +//! endpoint is what mobile/degraded clients use meanwhile, and stays the +//! fallback afterwards. + +use crate::api::middleware::CurrentUser; +use crate::api::state::AppState; +use crate::error::ApiResult; +use crate::models::Message; +use axum::{ + extract::{Query, State}, + Json, +}; +use chrono::{DateTime, Utc}; +use serde::{Deserialize, Serialize}; + +#[derive(Deserialize)] +pub struct EventsQuery { + pub since: Option>, +} + +#[derive(Serialize)] +pub struct EventsResponse { + pub changed_messages: Vec, + pub cursor: DateTime, +} + +pub async fn poll( + State(state): State, + user: CurrentUser, + Query(q): Query, +) -> ApiResult> { + let since = q.since.unwrap_or_else(|| Utc::now() - chrono::Duration::days(1)); + let cursor = Utc::now(); + + let changed_messages: Vec = sqlx::query_as( + "SELECT m.* FROM messages m JOIN accounts a ON a.id = m.account_id \ + WHERE a.user_id = $1 AND m.created_at > $2 \ + ORDER BY m.created_at ASC \ + LIMIT 500", + ) + .bind(user.user_id) + .bind(since) + .fetch_all(&state.pool) + .await?; + + Ok(Json(EventsResponse { changed_messages, cursor })) +} diff --git a/src/api/folders.rs b/src/api/folders.rs new file mode 100644 index 0000000..da1f765 --- /dev/null +++ b/src/api/folders.rs @@ -0,0 +1,32 @@ +use crate::api::middleware::CurrentUser; +use crate::api::state::AppState; +use crate::error::ApiResult; +use crate::models::Folder; +use axum::{extract::State, Json}; +use serde::Deserialize; + +#[derive(Deserialize)] +pub struct CreateFolderRequest { + pub name: String, +} + +pub async fn list(State(state): State, user: CurrentUser) -> ApiResult>> { + let folders: Vec = sqlx::query_as("SELECT * FROM folders WHERE user_id = $1 ORDER BY name") + .bind(user.user_id) + .fetch_all(&state.pool) + .await?; + Ok(Json(folders)) +} + +pub async fn create( + State(state): State, + user: CurrentUser, + Json(req): Json, +) -> ApiResult> { + let folder: Folder = sqlx::query_as("INSERT INTO folders (user_id, name) VALUES ($1, $2) RETURNING *") + .bind(user.user_id) + .bind(&req.name) + .fetch_one(&state.pool) + .await?; + Ok(Json(folder)) +} diff --git a/src/api/messages.rs b/src/api/messages.rs new file mode 100644 index 0000000..6feda35 --- /dev/null +++ b/src/api/messages.rs @@ -0,0 +1,113 @@ +//! Cursor-based message listing (server-architecture-spec.md §4 — cursor, +//! not offset, since new mail arrives continuously and would shift an +//! offset-based page). The cursor is just the `sent_at` of the last item +//! returned; callers pass it back as `before` to get the next page. + +use crate::api::middleware::CurrentUser; +use crate::api::state::AppState; +use crate::error::{ApiError, ApiResult}; +use crate::models::message::Body; +use crate::models::Message; +use axum::{ + extract::{Path, Query, State}, + Json, +}; +use chrono::{DateTime, Utc}; +use serde::{Deserialize, Serialize}; +use uuid::Uuid; + +#[derive(Deserialize)] +pub struct ListMessagesQuery { + pub folder_id: Option, + pub thread_id: Option, + pub before: Option>, + pub limit: Option, +} + +#[derive(Serialize)] +pub struct ListMessagesResponse { + pub messages: Vec, + pub next_cursor: Option>, +} + +pub async fn list( + State(state): State, + user: CurrentUser, + Query(q): Query, +) -> ApiResult> { + let limit = q.limit.unwrap_or(50).clamp(1, 200); + let before = q.before.unwrap_or_else(Utc::now); + + let messages: Vec = sqlx::query_as( + "SELECT m.* FROM messages m \ + JOIN accounts a ON a.id = m.account_id \ + WHERE a.user_id = $1 \ + AND m.sent_at < $2 \ + AND ($3::uuid IS NULL OR m.folder_id = $3) \ + AND ($4::uuid IS NULL OR m.thread_id = $4) \ + ORDER BY m.sent_at DESC \ + LIMIT $5", + ) + .bind(user.user_id) + .bind(before) + .bind(q.folder_id) + .bind(q.thread_id) + .bind(limit) + .fetch_all(&state.pool) + .await?; + + let next_cursor = messages.last().and_then(|m| m.sent_at); + + Ok(Json(ListMessagesResponse { messages, next_cursor })) +} + +#[derive(Serialize)] +pub struct MessageDetail { + #[serde(flatten)] + pub message: Message, + pub body: Option, +} + +pub async fn get( + State(state): State, + user: CurrentUser, + Path(message_id): Path, +) -> ApiResult> { + let message: Message = sqlx::query_as( + "SELECT m.* FROM messages m JOIN accounts a ON a.id = m.account_id \ + WHERE m.id = $1 AND a.user_id = $2", + ) + .bind(message_id) + .bind(user.user_id) + .fetch_optional(&state.pool) + .await? + .ok_or(ApiError::NotFound)?; + + let body: Option = sqlx::query_as("SELECT * FROM bodies WHERE message_id = $1") + .bind(message_id) + .fetch_optional(&state.pool) + .await?; + + Ok(Json(MessageDetail { message, body })) +} + +/// "Fetch thread" endpoint (§3.6) — the client just needs thread_id exposed +/// plus a way to pull every message in it; how to render it (collapsed vs +/// flat) is left entirely to the client. +pub async fn get_thread( + State(state): State, + user: CurrentUser, + Path(thread_id): Path, +) -> ApiResult>> { + let messages: Vec = sqlx::query_as( + "SELECT m.* FROM messages m JOIN accounts a ON a.id = m.account_id \ + WHERE m.thread_id = $1 AND a.user_id = $2 \ + ORDER BY m.sent_at ASC", + ) + .bind(thread_id) + .bind(user.user_id) + .fetch_all(&state.pool) + .await?; + + Ok(Json(messages)) +} diff --git a/src/api/middleware.rs b/src/api/middleware.rs new file mode 100644 index 0000000..6aad1f6 --- /dev/null +++ b/src/api/middleware.rs @@ -0,0 +1,43 @@ +use crate::api::state::AppState; +use crate::error::ApiError; +use axum::{ + extract::FromRequestParts, + http::request::Parts, +}; +use chrono::Utc; +use uuid::Uuid; + +/// The authenticated user for a request, resolved from a bearer session +/// token (`Authorization: Bearer `). API auth is independent +/// of IMAP credentials (server-architecture-spec.md §2.4) — this is purely +/// local session state. +pub struct CurrentUser { + pub user_id: Uuid, +} + +#[axum::async_trait] +impl FromRequestParts for CurrentUser { + type Rejection = ApiError; + + async fn from_request_parts(parts: &mut Parts, state: &AppState) -> Result { + let header = parts + .headers + .get(axum::http::header::AUTHORIZATION) + .and_then(|v| v.to_str().ok()) + .ok_or(ApiError::Unauthorized)?; + + let token_str = header.strip_prefix("Bearer ").ok_or(ApiError::Unauthorized)?; + let token = Uuid::parse_str(token_str).map_err(|_| ApiError::Unauthorized)?; + + let row: Option<(Uuid, chrono::DateTime)> = + sqlx::query_as("SELECT user_id, expires_at FROM sessions WHERE token = $1") + .bind(token) + .fetch_optional(&state.pool) + .await?; + + match row { + Some((user_id, expires_at)) if expires_at > Utc::now() => Ok(CurrentUser { user_id }), + _ => Err(ApiError::Unauthorized), + } + } +} diff --git a/src/api/mod.rs b/src/api/mod.rs new file mode 100644 index 0000000..eeb9481 --- /dev/null +++ b/src/api/mod.rs @@ -0,0 +1,11 @@ +pub mod accounts; +pub mod auth; +pub mod events; +pub mod folders; +pub mod messages; +pub mod middleware; +pub mod router; +pub mod state; + +pub use router::build; +pub use state::AppState; diff --git a/src/api/router.rs b/src/api/router.rs new file mode 100644 index 0000000..a715a34 --- /dev/null +++ b/src/api/router.rs @@ -0,0 +1,23 @@ +use crate::api::state::AppState; +use crate::api::{accounts, auth, events, folders, messages}; +use axum::routing::{delete, get, post}; +use axum::Router; +use tower_http::cors::CorsLayer; +use tower_http::trace::TraceLayer; + +pub fn build(state: AppState) -> Router { + Router::new() + .route("/api/auth/register", post(auth::register)) + .route("/api/auth/login", post(auth::login)) + .route("/api/accounts", get(accounts::list).post(accounts::create)) + .route("/api/accounts/{id}", delete(accounts::delete)) + .route("/api/folders", get(folders::list).post(folders::create)) + .route("/api/messages", get(messages::list)) + .route("/api/messages/{id}", get(messages::get)) + .route("/api/threads/{id}", get(messages::get_thread)) + .route("/api/events", get(events::poll)) + .route("/healthz", get(|| async { "ok" })) + .layer(TraceLayer::new_for_http()) + .layer(CorsLayer::permissive()) + .with_state(state) +} diff --git a/src/api/state.rs b/src/api/state.rs new file mode 100644 index 0000000..cb49d53 --- /dev/null +++ b/src/api/state.rs @@ -0,0 +1,13 @@ +use crate::config::Config; +use crate::crypto::CredentialCipher; +use crate::storage::BlobStore; +use sqlx::PgPool; + +#[derive(Clone)] +pub struct AppState { + pub pool: PgPool, + pub cipher: CredentialCipher, + pub blobs: BlobStore, + pub session_ttl_hours: i64, + pub config: Config, +} diff --git a/src/auth.rs b/src/auth.rs new file mode 100644 index 0000000..a3f42d6 --- /dev/null +++ b/src/auth.rs @@ -0,0 +1,18 @@ +use anyhow::Result; +use argon2::{ + password_hash::{rand_core::OsRng, PasswordHash, PasswordHasher, PasswordVerifier, SaltString}, + Argon2, +}; + +pub fn hash_password(password: &str) -> Result { + let salt = SaltString::generate(&mut OsRng); + Argon2::default() + .hash_password(password.as_bytes(), &salt) + .map(|h| h.to_string()) + .map_err(|e| anyhow::anyhow!("password hashing failed: {e}")) +} + +pub fn verify_password(password: &str, hash: &str) -> Result { + let parsed = PasswordHash::new(hash).map_err(|e| anyhow::anyhow!("stored password hash is malformed: {e}"))?; + Ok(Argon2::default().verify_password(password.as_bytes(), &parsed).is_ok()) +} diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..e55853a --- /dev/null +++ b/src/config.rs @@ -0,0 +1,49 @@ +use anyhow::{Context, Result}; + +#[derive(Clone, Debug)] +pub struct Config { + pub database_url: String, + pub bind_addr: String, + /// 32-byte key, base64-encoded, used for ChaCha20-Poly1305 encryption of + /// stored IMAP/SMTP credentials (server-architecture-spec.md §7). + pub credential_key: [u8; 32], + /// Directory raw MIME blobs and attachments are stored under (§3.2). + pub blob_storage_dir: std::path::PathBuf, + pub session_ttl_hours: i64, +} + +impl Config { + pub fn from_env() -> Result { + let database_url = std::env::var("DATABASE_URL") + .context("DATABASE_URL must be set (e.g. postgres://tern:tern@localhost/tern)")?; + + let bind_addr = std::env::var("BIND_ADDR").unwrap_or_else(|_| "127.0.0.1:8080".to_string()); + + let key_b64 = std::env::var("CREDENTIAL_KEY").context( + "CREDENTIAL_KEY must be set: a base64-encoded 32-byte key used to encrypt stored \ + IMAP/SMTP credentials at rest. Generate one with: openssl rand -base64 32", + )?; + let key_bytes = base64::Engine::decode(&base64::engine::general_purpose::STANDARD, key_b64.trim()) + .context("CREDENTIAL_KEY is not valid base64")?; + let credential_key: [u8; 32] = key_bytes + .try_into() + .map_err(|v: Vec| anyhow::anyhow!("CREDENTIAL_KEY must decode to exactly 32 bytes, got {}", v.len()))?; + + let blob_storage_dir = std::env::var("BLOB_STORAGE_DIR") + .unwrap_or_else(|_| "./data/blobs".to_string()) + .into(); + + let session_ttl_hours = std::env::var("SESSION_TTL_HOURS") + .ok() + .and_then(|v| v.parse().ok()) + .unwrap_or(24 * 30); + + Ok(Self { + database_url, + bind_addr, + credential_key, + blob_storage_dir, + session_ttl_hours, + }) + } +} diff --git a/src/crypto.rs b/src/crypto.rs new file mode 100644 index 0000000..bd90cfd --- /dev/null +++ b/src/crypto.rs @@ -0,0 +1,71 @@ +//! Encryption at rest for stored IMAP/SMTP credentials. +//! +//! server-architecture-spec.md §7 asks for "libsodium secretbox... or better, a +//! key derived from something you don't also store in the same DB". We use +//! ChaCha20-Poly1305 (RustCrypto, pure Rust, no libsodium system dependency) +//! which is the same construction family as secretbox (XSalsa20-Poly1305) — +//! an AEAD cipher with a random nonce per message. The key itself comes from +//! the `CREDENTIAL_KEY` env var (see config.rs), not from the database. + +use anyhow::{Context, Result}; +use chacha20poly1305::{ + aead::{Aead, KeyInit}, + ChaCha20Poly1305, Key, Nonce, +}; +use rand::RngCore; + +#[derive(Clone)] +pub struct CredentialCipher { + cipher: ChaCha20Poly1305, +} + +pub struct Encrypted { + pub ciphertext: Vec, + pub nonce: Vec, +} + +impl CredentialCipher { + pub fn new(key: &[u8; 32]) -> Self { + Self { + cipher: ChaCha20Poly1305::new(Key::from_slice(key)), + } + } + + pub fn encrypt(&self, plaintext: &str) -> Result { + let mut nonce_bytes = [0u8; 12]; + rand::thread_rng().fill_bytes(&mut nonce_bytes); + let nonce = Nonce::from_slice(&nonce_bytes); + + let ciphertext = self + .cipher + .encrypt(nonce, plaintext.as_bytes()) + .map_err(|e| anyhow::anyhow!("credential encryption failed: {e}"))?; + + Ok(Encrypted { + ciphertext, + nonce: nonce_bytes.to_vec(), + }) + } + + pub fn decrypt(&self, ciphertext: &[u8], nonce: &[u8]) -> Result { + let nonce = Nonce::from_slice(nonce); + let plaintext = self + .cipher + .decrypt(nonce, ciphertext) + .map_err(|e| anyhow::anyhow!("credential decryption failed: {e}"))?; + String::from_utf8(plaintext).context("decrypted credential was not valid utf-8") + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn round_trips() { + let key = [7u8; 32]; + let c = CredentialCipher::new(&key); + let enc = c.encrypt("hunter2").unwrap(); + assert_eq!(c.decrypt(&enc.ciphertext, &enc.nonce).unwrap(), "hunter2"); + } +} diff --git a/src/db.rs b/src/db.rs new file mode 100644 index 0000000..853d89d --- /dev/null +++ b/src/db.rs @@ -0,0 +1,17 @@ +use anyhow::{Context, Result}; +use sqlx::postgres::{PgPool, PgPoolOptions}; + +pub async fn connect(database_url: &str) -> Result { + let pool = PgPoolOptions::new() + .max_connections(10) + .connect(database_url) + .await + .context("failed to connect to Postgres")?; + + sqlx::migrate!("./migrations") + .run(&pool) + .await + .context("failed to run database migrations")?; + + Ok(pool) +} diff --git a/src/error.rs b/src/error.rs new file mode 100644 index 0000000..2bd7ea7 --- /dev/null +++ b/src/error.rs @@ -0,0 +1,41 @@ +use axum::{ + http::StatusCode, + response::{IntoResponse, Response}, + Json, +}; +use serde_json::json; + +#[derive(thiserror::Error, Debug)] +pub enum ApiError { + #[error("not found")] + NotFound, + #[error("unauthorized")] + Unauthorized, + #[error("bad request: {0}")] + BadRequest(String), + #[error(transparent)] + Internal(#[from] anyhow::Error), + #[error(transparent)] + Sqlx(#[from] sqlx::Error), +} + +impl IntoResponse for ApiError { + fn into_response(self) -> Response { + let (status, message) = match &self { + ApiError::NotFound => (StatusCode::NOT_FOUND, self.to_string()), + ApiError::Unauthorized => (StatusCode::UNAUTHORIZED, self.to_string()), + ApiError::BadRequest(_) => (StatusCode::BAD_REQUEST, self.to_string()), + ApiError::Sqlx(e) => { + tracing::error!("db error: {e:#}"); + (StatusCode::INTERNAL_SERVER_ERROR, "internal server error".to_string()) + } + ApiError::Internal(e) => { + tracing::error!("internal error: {e:#}"); + (StatusCode::INTERNAL_SERVER_ERROR, "internal server error".to_string()) + } + }; + (status, Json(json!({ "error": message }))).into_response() + } +} + +pub type ApiResult = Result; diff --git a/src/imap_sync/backoff.rs b/src/imap_sync/backoff.rs new file mode 100644 index 0000000..5845ae6 --- /dev/null +++ b/src/imap_sync/backoff.rs @@ -0,0 +1,36 @@ +//! Jittered exponential backoff for reconnecting to flaky IMAP servers +//! (server-architecture-spec.md §3.1). + +use rand::Rng; +use std::time::Duration; + +pub struct Backoff { + attempt: u32, + base: Duration, + max: Duration, +} + +impl Backoff { + pub fn new() -> Self { + Self { + attempt: 0, + base: Duration::from_secs(1), + max: Duration::from_secs(300), + } + } + + pub fn reset(&mut self) { + self.attempt = 0; + } + + /// Next delay, doubling each call up to `max`, plus up to 30% jitter so + /// many accounts reconnecting at once don't hammer the server in lockstep. + pub fn next_delay(&mut self) -> Duration { + let exp = self.base.as_secs_f64() * 2f64.powi(self.attempt as i32); + let capped = exp.min(self.max.as_secs_f64()); + self.attempt = self.attempt.saturating_add(1); + + let jitter_factor = rand::thread_rng().gen_range(1.0..1.3); + Duration::from_secs_f64(capped * jitter_factor) + } +} diff --git a/src/imap_sync/connection.rs b/src/imap_sync/connection.rs new file mode 100644 index 0000000..76b19b3 --- /dev/null +++ b/src/imap_sync/connection.rs @@ -0,0 +1,383 @@ +//! Per-account IMAP sync: connect, catch up on new mail, then IDLE and react +//! to server pushes. One task per account (spawned by `manager.rs`). +//! +//! Design per server-architecture-spec.md §3.1: +//! - One IDLE connection per account, watching INBOX only (§2.5 — folders +//! are virtual/app-level, the sync engine only ever watches INBOX). +//! - A NOOP-based watchdog: IDLE is re-issued periodically (servers commonly +//! time out an IDLE session around 30 min) and a stalled connection (no +//! response within the watchdog window) forces a reconnect. +//! - Jittered exponential backoff on any connection failure. +//! - Headers first: the initial/catch-up pass stores ENVELOPE + flags +//! immediately; bodies are fetched lazily in a trailing pass so a large +//! backlog doesn't block new-mail visibility. + +use crate::crypto::CredentialCipher; +use crate::imap_sync::backoff::Backoff; +use crate::imap_sync::parse::parse_raw_message; +use crate::models::account::Account; +use crate::storage::BlobStore; +use anyhow::{Context, Result}; +use async_imap::extensions::idle::IdleResponse; +use futures::TryStreamExt; +use sqlx::PgPool; +use std::time::Duration; +use uuid::Uuid; + +/// Re-issue IDLE this often even if the server hasn't timed out, and treat a +/// connection as stalled if nothing happens for this long. +const IDLE_RENEW: Duration = Duration::from_secs(25 * 60); +const BODY_FETCH_BATCH: i64 = 25; + +type ImapSession = async_imap::Session>; + +pub struct AccountSyncer { + pub account: Account, + pub pool: PgPool, + pub cipher: CredentialCipher, + pub blobs: BlobStore, +} + +impl AccountSyncer { + /// Runs forever: connect, sync, idle, reconnect with backoff on failure. + pub async fn run(self) { + let mut backoff = Backoff::new(); + loop { + match self.sync_once().await { + Ok(()) => { + // sync_once only returns Ok on a clean shutdown request. + tracing::info!(account_id = %self.account.id, "sync loop stopped cleanly"); + return; + } + Err(e) => { + tracing::warn!(account_id = %self.account.id, error = %e, "sync connection dropped, reconnecting"); + let _ = self.mark_status("error", Some(&e.to_string())).await; + tokio::time::sleep(backoff.next_delay()).await; + } + } + backoff.reset(); + } + } + + async fn mark_status(&self, status: &str, last_error: Option<&str>) -> Result<()> { + sqlx::query( + "UPDATE sync_state SET status = $2, last_error = $3, updated_at = now() WHERE account_id = $1", + ) + .bind(self.account.id) + .bind(status) + .bind(last_error) + .execute(&self.pool) + .await?; + Ok(()) + } + + async fn sync_once(&self) -> Result<()> { + let password = self + .cipher + .decrypt(&self.account.encrypted_password, &self.account.password_nonce) + .context("decrypting stored IMAP password")?; + + self.mark_status("syncing", None).await?; + + let tcp = tokio::net::TcpStream::connect((self.account.imap_host.as_str(), self.account.imap_port as u16)) + .await + .context("TCP connect to IMAP host failed")?; + + let tls = async_native_tls::TlsConnector::new(); + let tls_stream = tls + .connect(self.account.imap_host.as_str(), tcp) + .await + .context("IMAP TLS handshake failed")?; + + let client = async_imap::Client::new(tls_stream); + let mut session = client + .login(&self.account.username, &password) + .await + .map_err(|(e, _client)| anyhow::anyhow!("IMAP login failed: {e}"))?; + + let mailbox = session.select("INBOX").await.context("SELECT INBOX failed")?; + let server_uidvalidity = mailbox.uid_validity.map(|v| v as i64); + + self.reconcile_uidvalidity(server_uidvalidity).await?; + + // Catch up on anything new, then keep going until told to stop. + // `Session::idle()` consumes the session and hands back a `Handle`; + // `Handle::done()` hands the session back once IDLE ends, so it gets + // threaded through the loop by value rather than by `&mut`. + loop { + self.fetch_new_headers(&mut session).await?; + self.fetch_pending_bodies(&mut session).await?; + self.mark_status("idle", None).await?; + + let (went_idle, returned_session) = self.idle_until_change(session).await?; + session = returned_session; + if !went_idle { + // Server doesn't support IDLE (or it isn't available) — fall + // back to a plain poll interval instead of a tight loop. + tokio::time::sleep(Duration::from_secs(5 * 60)).await; + } + } + } + + async fn reconcile_uidvalidity(&self, server_uidvalidity: Option) -> Result<()> { + let existing: Option<(Option,)> = + sqlx::query_as("SELECT uidvalidity FROM sync_state WHERE account_id = $1") + .bind(self.account.id) + .fetch_optional(&self.pool) + .await?; + + match existing { + None => { + sqlx::query( + "INSERT INTO sync_state (account_id, uidvalidity, last_synced_uid, status) \ + VALUES ($1, $2, 0, 'syncing')", + ) + .bind(self.account.id) + .bind(server_uidvalidity) + .execute(&self.pool) + .await?; + } + Some((stored,)) if stored != server_uidvalidity => { + // UIDVALIDITY changed: every previously cached UID is now + // meaningless. Drop this account's messages and start over. + tracing::warn!(account_id = %self.account.id, "UIDVALIDITY changed, re-syncing folder from scratch"); + let mut tx = self.pool.begin().await?; + sqlx::query("DELETE FROM messages WHERE account_id = $1") + .bind(self.account.id) + .execute(&mut *tx) + .await?; + sqlx::query( + "UPDATE sync_state SET uidvalidity = $2, last_synced_uid = 0, updated_at = now() \ + WHERE account_id = $1", + ) + .bind(self.account.id) + .bind(server_uidvalidity) + .execute(&mut *tx) + .await?; + tx.commit().await?; + } + Some(_) => {} + } + Ok(()) + } + + async fn last_synced_uid(&self) -> Result { + let row: (i64,) = sqlx::query_as("SELECT last_synced_uid FROM sync_state WHERE account_id = $1") + .bind(self.account.id) + .fetch_one(&self.pool) + .await?; + Ok(row.0) + } + + /// Headers-first catch-up pass: fetch ENVELOPE + FLAGS for any UID beyond + /// the last one we've stored, insert stub message rows (body_fetched = + /// false). Bodies are filled in by `fetch_pending_bodies`. + async fn fetch_new_headers( + &self, + session: &mut ImapSession, + ) -> Result<()> { + let last_uid = self.last_synced_uid().await?; + let range = format!("{}:*", last_uid + 1); + + let fetches: Vec<_> = session + .uid_fetch(&range, "(UID FLAGS ENVELOPE)") + .await + .context("UID FETCH (headers) failed")? + .try_collect() + .await + .context("reading UID FETCH response")?; + + let mut max_uid = last_uid; + for f in &fetches { + let Some(uid) = f.uid else { continue }; + if uid as i64 <= last_uid { + // The "N:*" range syntax always includes the highest UID in + // the mailbox even when N is past it; skip anything we + // already have. + continue; + } + max_uid = max_uid.max(uid as i64); + + let envelope = f.envelope(); + let subject = envelope + .and_then(|e| e.subject.as_ref()) + .map(|s| String::from_utf8_lossy(s).to_string()); + let message_id = envelope + .and_then(|e| e.message_id.as_ref()) + .map(|s| String::from_utf8_lossy(s).to_string()); + let in_reply_to = envelope + .and_then(|e| e.in_reply_to.as_ref()) + .map(|s| String::from_utf8_lossy(s).to_string()); + + let flags: Vec = f.flags().map(|flag| format!("{flag:?}")).collect(); + + sqlx::query( + "INSERT INTO messages \ + (account_id, uid, message_id, in_reply_to, subject, flags, body_fetched) \ + VALUES ($1, $2, $3, $4, $5, $6, false) \ + ON CONFLICT (account_id, uid) DO UPDATE SET flags = EXCLUDED.flags", + ) + .bind(self.account.id) + .bind(uid as i64) + .bind(&message_id) + .bind(&in_reply_to) + .bind(&subject) + .bind(&flags) + .execute(&self.pool) + .await?; + } + + if max_uid > last_uid { + sqlx::query("UPDATE sync_state SET last_synced_uid = $2, updated_at = now() WHERE account_id = $1") + .bind(self.account.id) + .bind(max_uid) + .execute(&self.pool) + .await?; + } + + Ok(()) + } + + /// Trailing pass: pull full bodies for a batch of messages that only + /// have headers so far, parse and store them, then mark body_fetched. + async fn fetch_pending_bodies( + &self, + session: &mut ImapSession, + ) -> Result<()> { + loop { + let pending: Vec<(Uuid, i64)> = sqlx::query_as( + "SELECT id, uid FROM messages WHERE account_id = $1 AND body_fetched = false \ + ORDER BY uid ASC LIMIT $2", + ) + .bind(self.account.id) + .bind(BODY_FETCH_BATCH) + .fetch_all(&self.pool) + .await?; + + if pending.is_empty() { + return Ok(()); + } + + let uid_set = pending + .iter() + .map(|(_, uid)| uid.to_string()) + .collect::>() + .join(","); + + let fetches: Vec<_> = session + .uid_fetch(&uid_set, "(UID RFC822)") + .await + .context("UID FETCH (body) failed")? + .try_collect() + .await + .context("reading UID FETCH body response")?; + + for f in &fetches { + let (Some(uid), Some(raw)) = (f.uid, f.body()) else { continue }; + let Some((row_id, _)) = pending.iter().find(|(_, u)| *u == uid as i64) else { continue }; + + if let Err(e) = self.store_body(*row_id, raw).await { + tracing::error!(account_id = %self.account.id, uid, error = %e, "failed to store message body"); + } + } + } + } + + async fn store_body(&self, message_row_id: Uuid, raw: &[u8]) -> Result<()> { + let parsed = parse_raw_message(raw)?; + let (_, raw_blob_ref) = self.blobs.put(&parsed.raw).await?; + + let mut tx = self.pool.begin().await?; + + sqlx::query( + "UPDATE messages SET \ + message_id = COALESCE($2, message_id), \ + in_reply_to = COALESCE($3, in_reply_to), \ + references_ = $4, \ + from_addr = $5, from_name = $6, \ + to_addrs = $7, cc_addrs = $8, \ + subject = COALESCE($9, subject), \ + sent_at = $10, \ + raw_blob_ref = $11, \ + body_fetched = true \ + WHERE id = $1", + ) + .bind(message_row_id) + .bind(&parsed.message_id) + .bind(&parsed.in_reply_to) + .bind(&parsed.references) + .bind(&parsed.from_addr) + .bind(&parsed.from_name) + .bind(&parsed.to_addrs) + .bind(&parsed.cc_addrs) + .bind(&parsed.subject) + .bind(parsed.sent_at) + .bind(&raw_blob_ref) + .execute(&mut *tx) + .await?; + + sqlx::query( + "INSERT INTO bodies (message_id, text_body, html_body) VALUES ($1, $2, $3) \ + ON CONFLICT (message_id) DO UPDATE SET text_body = EXCLUDED.text_body, html_body = EXCLUDED.html_body", + ) + .bind(message_row_id) + .bind(&parsed.text_body) + .bind(&parsed.html_body) + .execute(&mut *tx) + .await?; + + for att in &parsed.attachments { + let (content_hash, blob_ref) = self.blobs.put(&att.data).await?; + sqlx::query( + "INSERT INTO attachments (message_id, filename, content_type, size, content_hash, blob_ref) \ + VALUES ($1, $2, $3, $4, $5, $6)", + ) + .bind(message_row_id) + .bind(&att.filename) + .bind(&att.content_type) + .bind(att.data.len() as i64) + .bind(&content_hash) + .bind(&blob_ref) + .execute(&mut *tx) + .await?; + } + + tx.commit().await?; + Ok(()) + } + + /// Issues IDLE and waits for either a mailbox change or the renewal + /// timeout. Returns `Ok((true, session))` if IDLE was used, or + /// `Ok((false, session))` if the server rejected it (caller should fall + /// back to polling) — either way the session is handed back so the + /// caller can keep using it. `Session::idle()` takes the session by + /// value; `Handle::done()` gives it back once IDLE ends. + async fn idle_until_change(&self, session: ImapSession) -> Result<(bool, ImapSession)> { + let mut handle = session.idle(); + if let Err(e) = handle.init().await { + tracing::warn!(account_id = %self.account.id, error = %e, "server rejected IDLE, falling back to polling"); + let session = handle.done().await.context("recovering session after failed IDLE init")?; + return Ok((false, session)); + } + + let (idle_wait, _stop_source) = handle.wait_with_timeout(IDLE_RENEW); + let wait_result = idle_wait.await; + + let session = handle.done().await.context("DONE after IDLE failed")?; + + match wait_result { + Ok(IdleResponse::NewData(_)) => { + tracing::debug!(account_id = %self.account.id, "IDLE reported new data"); + } + Ok(IdleResponse::Timeout) => { + // Just a renewal tick — nothing necessarily changed. + } + Ok(IdleResponse::ManualInterrupt) => {} + Err(e) => { + return Err(anyhow::anyhow!("IDLE wait failed: {e}")); + } + } + + Ok((true, session)) + } +} diff --git a/src/imap_sync/manager.rs b/src/imap_sync/manager.rs new file mode 100644 index 0000000..4658ce7 --- /dev/null +++ b/src/imap_sync/manager.rs @@ -0,0 +1,47 @@ +//! Spawns and tracks one sync task per account. Polls for newly-added +//! accounts periodically rather than requiring a restart to pick them up. + +use crate::crypto::CredentialCipher; +use crate::imap_sync::connection::AccountSyncer; +use crate::models::account::Account; +use crate::storage::BlobStore; +use sqlx::PgPool; +use std::collections::HashMap; +use std::time::Duration; +use uuid::Uuid; + +const ACCOUNT_POLL_INTERVAL: Duration = Duration::from_secs(30); + +pub async fn run(pool: PgPool, cipher: CredentialCipher, blobs: BlobStore) { + let mut running: HashMap> = HashMap::new(); + + loop { + running.retain(|_, handle| !handle.is_finished()); + + match sqlx::query_as::<_, Account>("SELECT * FROM accounts") + .fetch_all(&pool) + .await + { + Ok(accounts) => { + for account in accounts { + if running.contains_key(&account.id) { + continue; + } + tracing::info!(account_id = %account.id, name = %account.name, "starting sync task"); + let syncer = AccountSyncer { + account, + pool: pool.clone(), + cipher: cipher.clone(), + blobs: blobs.clone(), + }; + let id = syncer.account.id; + let handle = tokio::spawn(syncer.run()); + running.insert(id, handle); + } + } + Err(e) => tracing::error!(error = %e, "failed to list accounts for sync manager"), + } + + tokio::time::sleep(ACCOUNT_POLL_INTERVAL).await; + } +} diff --git a/src/imap_sync/mod.rs b/src/imap_sync/mod.rs new file mode 100644 index 0000000..9484c42 --- /dev/null +++ b/src/imap_sync/mod.rs @@ -0,0 +1,6 @@ +pub mod backoff; +pub mod connection; +pub mod manager; +pub mod parse; + +pub use manager::run; diff --git a/src/imap_sync/parse.rs b/src/imap_sync/parse.rs new file mode 100644 index 0000000..5c718e0 --- /dev/null +++ b/src/imap_sync/parse.rs @@ -0,0 +1,86 @@ +//! Turn a raw MIME blob into a `ParsedMessage` ready for insertion. +//! Threading headers (Message-ID / In-Reply-To / References) are parsed here +//! per server-architecture-spec.md §3.6, though the JWZ linking/merging pass +//! itself is a later build-order phase — for now each message just carries +//! its own generated `thread_id` and these headers for future re-threading. + +use crate::models::message::{ParsedAttachment, ParsedMessage}; +use chrono::{DateTime, Utc}; +use mail_parser::{Address, MessageParser, MimeHeaders}; + +pub fn parse_raw_message(raw: &[u8]) -> anyhow::Result { + let message = MessageParser::default() + .parse(raw) + .ok_or_else(|| anyhow::anyhow!("mail-parser failed to parse message"))?; + + let message_id = message.message_id().map(String::from); + let in_reply_to = message.in_reply_to().as_text().map(|s| s.to_string()); + let references: Vec = message + .references() + .as_text_list() + .map(|list| list.into_iter().map(|s| s.to_string()).collect()) + .unwrap_or_default(); + + let (from_addr, from_name) = message + .from() + .and_then(first_address) + .unwrap_or((None, None)); + + let to_addrs = message + .to() + .map(all_addresses) + .unwrap_or_default(); + let cc_addrs = message + .cc() + .map(all_addresses) + .unwrap_or_default(); + + let subject = message.subject().map(|s| s.to_string()); + let sent_at: Option> = message + .date() + .and_then(|d| DateTime::parse_from_rfc3339(&d.to_rfc3339()).ok()) + .map(|d| d.with_timezone(&Utc)); + + let text_body = message.body_text(0).map(|s| s.to_string()); + let html_body = message.body_html(0).map(|s| s.to_string()); + + let attachments = message + .attachments() + .map(|a| ParsedAttachment { + filename: a.attachment_name().map(|s| s.to_string()), + content_type: a.content_type().map(|ct| ct.ctype().to_string()), + data: a.contents().to_vec(), + }) + .collect(); + + Ok(ParsedMessage { + message_id, + in_reply_to, + references, + from_addr, + from_name, + to_addrs, + cc_addrs, + subject, + sent_at, + text_body, + html_body, + attachments, + raw: raw.to_vec(), + }) +} + +fn first_address(addr: &Address) -> Option<(Option, Option)> { + addr.first().map(|a| { + ( + a.address().map(|s| s.to_string()), + a.name().map(|s| s.to_string()), + ) + }) +} + +fn all_addresses(addr: &Address) -> Vec { + addr.iter() + .filter_map(|a| a.address().map(|s| s.to_string())) + .collect() +} diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..51d62b4 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,9 @@ +pub mod api; +pub mod auth; +pub mod config; +pub mod crypto; +pub mod db; +pub mod error; +pub mod imap_sync; +pub mod models; +pub mod storage; diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..1f377d7 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,40 @@ +use tern_server::api::{self, AppState}; +use tern_server::config::Config; +use tern_server::crypto::CredentialCipher; +use tern_server::storage::BlobStore; +use tern_server::{db, imap_sync}; + +#[tokio::main] +async fn main() -> anyhow::Result<()> { + let _ = dotenvy::dotenv(); + tracing_subscriber::fmt() + .with_env_filter(tracing_subscriber::EnvFilter::from_default_env().add_directive("tern_server=info".parse()?)) + .init(); + + let config = Config::from_env()?; + tern_server::storage::ensure_dir(&config.blob_storage_dir)?; + + let pool = db::connect(&config.database_url).await?; + let cipher = CredentialCipher::new(&config.credential_key); + let blobs = BlobStore::new(config.blob_storage_dir.clone()); + + // The sync manager owns one long-running task per IMAP account + // (server-architecture-spec.md §3.1) — it runs alongside the API server. + tokio::spawn(imap_sync::run(pool.clone(), cipher.clone(), blobs.clone())); + + let state = AppState { + pool, + cipher, + blobs, + session_ttl_hours: config.session_ttl_hours, + config: config.clone(), + }; + + let app = api::build(state); + + tracing::info!("listening on {}", config.bind_addr); + let listener = tokio::net::TcpListener::bind(&config.bind_addr).await?; + axum::serve(listener, app).await?; + + Ok(()) +} diff --git a/src/models/account.rs b/src/models/account.rs new file mode 100644 index 0000000..d42bb03 --- /dev/null +++ b/src/models/account.rs @@ -0,0 +1,61 @@ +use chrono::{DateTime, Utc}; +use serde::Serialize; +use uuid::Uuid; + +#[derive(Debug, Clone, sqlx::FromRow)] +pub struct Account { + pub id: Uuid, + pub user_id: Uuid, + pub name: String, + pub provider_type: String, + pub imap_host: String, + pub imap_port: i32, + pub imap_use_tls: bool, + pub smtp_host: String, + pub smtp_port: i32, + pub smtp_use_starttls: bool, + pub username: String, + pub encrypted_password: Vec, + pub password_nonce: Vec, + pub created_at: DateTime, +} + +/// What the API actually returns — never the encrypted credential blob. +#[derive(Debug, Clone, Serialize)] +pub struct AccountPublic { + pub id: Uuid, + pub name: String, + pub provider_type: String, + pub imap_host: String, + pub imap_port: i32, + pub smtp_host: String, + pub smtp_port: i32, + pub username: String, + pub created_at: DateTime, +} + +impl From for AccountPublic { + fn from(a: Account) -> Self { + Self { + id: a.id, + name: a.name, + provider_type: a.provider_type, + imap_host: a.imap_host, + imap_port: a.imap_port, + smtp_host: a.smtp_host, + smtp_port: a.smtp_port, + username: a.username, + created_at: a.created_at, + } + } +} + +#[derive(Debug, Clone, sqlx::FromRow)] +pub struct SyncState { + pub account_id: Uuid, + pub uidvalidity: Option, + pub last_synced_uid: i64, + pub status: String, + pub last_error: Option, + pub updated_at: DateTime, +} diff --git a/src/models/folder.rs b/src/models/folder.rs new file mode 100644 index 0000000..2746fac --- /dev/null +++ b/src/models/folder.rs @@ -0,0 +1,11 @@ +use chrono::{DateTime, Utc}; +use serde::Serialize; +use uuid::Uuid; + +#[derive(Debug, Clone, sqlx::FromRow, Serialize)] +pub struct Folder { + pub id: Uuid, + pub user_id: Uuid, + pub name: String, + pub created_at: DateTime, +} diff --git a/src/models/message.rs b/src/models/message.rs new file mode 100644 index 0000000..f629a9e --- /dev/null +++ b/src/models/message.rs @@ -0,0 +1,58 @@ +use chrono::{DateTime, Utc}; +use serde::Serialize; +use uuid::Uuid; + +#[derive(Debug, Clone, sqlx::FromRow, Serialize)] +pub struct Message { + pub id: Uuid, + pub account_id: Uuid, + pub folder_id: Option, + pub uid: i64, + pub message_id: Option, + pub in_reply_to: Option, + pub references_: Vec, + pub thread_id: Uuid, + pub from_addr: Option, + pub from_name: Option, + pub to_addrs: Vec, + pub cc_addrs: Vec, + pub subject: Option, + pub sent_at: Option>, + pub flags: Vec, + pub spam_score: Option, + pub body_fetched: bool, + pub raw_blob_ref: Option, + pub created_at: DateTime, +} + +#[derive(Debug, Clone, sqlx::FromRow, Serialize)] +pub struct Body { + pub message_id: Uuid, + pub text_body: Option, + pub html_body: Option, +} + +/// Fields extracted from a raw MIME message, ready to insert (imap_sync::parse). +#[derive(Debug, Clone)] +pub struct ParsedMessage { + pub message_id: Option, + pub in_reply_to: Option, + pub references: Vec, + pub from_addr: Option, + pub from_name: Option, + pub to_addrs: Vec, + pub cc_addrs: Vec, + pub subject: Option, + pub sent_at: Option>, + pub text_body: Option, + pub html_body: Option, + pub attachments: Vec, + pub raw: Vec, +} + +#[derive(Debug, Clone)] +pub struct ParsedAttachment { + pub filename: Option, + pub content_type: Option, + pub data: Vec, +} diff --git a/src/models/mod.rs b/src/models/mod.rs new file mode 100644 index 0000000..03c2595 --- /dev/null +++ b/src/models/mod.rs @@ -0,0 +1,9 @@ +pub mod account; +pub mod folder; +pub mod message; +pub mod user; + +pub use account::Account; +pub use folder::Folder; +pub use message::{Body, Message}; +pub use user::User; diff --git a/src/models/user.rs b/src/models/user.rs new file mode 100644 index 0000000..a53cfaf --- /dev/null +++ b/src/models/user.rs @@ -0,0 +1,12 @@ +use chrono::{DateTime, Utc}; +use serde::Serialize; +use uuid::Uuid; + +#[derive(Debug, Clone, sqlx::FromRow, Serialize)] +pub struct User { + pub id: Uuid, + pub username: String, + #[serde(skip_serializing)] + pub password_hash: String, + pub created_at: DateTime, +} diff --git a/src/storage.rs b/src/storage.rs new file mode 100644 index 0000000..0c65559 --- /dev/null +++ b/src/storage.rs @@ -0,0 +1,67 @@ +//! Filesystem, content-hash-addressed blob storage for raw MIME messages and +//! attachments (server-architecture-spec.md §3.2). Kept content-hash-addressed +//! from day one so a future swap to S3-compatible storage (§11) is a +//! backend change, not a data-model change. + +use anyhow::{Context, Result}; +use sha2::{Digest, Sha256}; +use std::path::{Path, PathBuf}; + +#[derive(Clone)] +pub struct BlobStore { + root: PathBuf, +} + +impl BlobStore { + pub fn new(root: PathBuf) -> Self { + Self { root } + } + + pub fn hash(data: &[u8]) -> String { + let mut hasher = Sha256::new(); + hasher.update(data); + hex::encode(hasher.finalize()) + } + + fn path_for_hash(&self, hash: &str) -> PathBuf { + // shard by the first 2 hex chars to avoid one giant flat directory + self.root.join(&hash[0..2]).join(hash) + } + + /// Writes `data` under its content hash if not already present. Returns + /// the hash and the path it was stored at (relative to `root`, so the + /// stored `blob_ref` doesn't embed an absolute deployment path). + pub async fn put(&self, data: &[u8]) -> Result<(String, String)> { + let hash = Self::hash(data); + let full_path = self.path_for_hash(&hash); + + if !tokio::fs::try_exists(&full_path).await.unwrap_or(false) { + if let Some(parent) = full_path.parent() { + tokio::fs::create_dir_all(parent) + .await + .with_context(|| format!("creating blob directory {}", parent.display()))?; + } + tokio::fs::write(&full_path, data) + .await + .with_context(|| format!("writing blob {}", full_path.display()))?; + } + + let rel_ref = format!("{}/{}", &hash[0..2], hash); + Ok((hash, rel_ref)) + } + + pub async fn read(&self, blob_ref: &str) -> Result> { + let path = self.resolve(blob_ref); + tokio::fs::read(&path) + .await + .with_context(|| format!("reading blob {}", path.display())) + } + + pub fn resolve(&self, blob_ref: &str) -> PathBuf { + self.root.join(blob_ref) + } +} + +pub fn ensure_dir(path: &Path) -> Result<()> { + std::fs::create_dir_all(path).with_context(|| format!("creating directory {}", path.display())) +}