mirror of
https://github.com/lennart-k/rustical.git
synced 2026-01-30 16:28:21 +00:00
Compare commits
14 Commits
v0.12.2
...
d9da123ff4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d9da123ff4 | ||
|
|
eba2f0da9f | ||
|
|
291bd967da | ||
|
|
002814a564 | ||
|
|
ba13aaa703 | ||
|
|
7a02bfeffc | ||
|
|
1b69148d6f | ||
|
|
f4de80c6b9 | ||
|
|
7a1ec3e351 | ||
|
|
eb7bdd0018 | ||
|
|
8e583e24cb | ||
|
|
5e5017a185 | ||
|
|
3c87191f69 | ||
|
|
d1947a159b |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -16,3 +16,5 @@ site
|
|||||||
# Frontend
|
# Frontend
|
||||||
**/node_modules
|
**/node_modules
|
||||||
**/.vite
|
**/.vite
|
||||||
|
|
||||||
|
**/*.snap.new
|
||||||
|
|||||||
281
Cargo.lock
generated
281
Cargo.lock
generated
@@ -154,7 +154,7 @@ dependencies = [
|
|||||||
"rustc-hash",
|
"rustc-hash",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
"syn 2.0.112",
|
"syn 2.0.114",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -200,7 +200,7 @@ checksum = "9767c17d33a63daf6da5872ffaf2ab0c289cd73ce7ed4f41d5ddf9149c004873"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.112",
|
"syn 2.0.114",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -335,7 +335,7 @@ checksum = "9035ad2d096bed7955a320ee7e2230574d28fd3c3a0f186cbea1ff3c7eed5dbb"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.112",
|
"syn 2.0.114",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -477,9 +477,9 @@ checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "base64ct"
|
name = "base64ct"
|
||||||
version = "1.8.1"
|
version = "1.8.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0e050f626429857a27ddccb31e0aca21356bfa709c04041aefddac081a8f068a"
|
checksum = "2af50177e190e07a26ab74f8b1efbfe2ef87da2116221318cb1c2e82baf7de06"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "basic-toml"
|
name = "basic-toml"
|
||||||
@@ -573,9 +573,9 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cc"
|
name = "cc"
|
||||||
version = "1.2.51"
|
version = "1.2.52"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7a0aeaff4ff1a90589618835a598e545176939b97874f7abc7851caa0618f203"
|
checksum = "cd4932aefd12402b36c60956a4fe0035421f544799057659ff86f923657aada3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"find-msvc-tools",
|
"find-msvc-tools",
|
||||||
"shlex",
|
"shlex",
|
||||||
@@ -623,7 +623,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "a6139a8597ed92cf816dfb33f5dd6cf0bb93a6adc938f11039f371bc5bcd26c3"
|
checksum = "a6139a8597ed92cf816dfb33f5dd6cf0bb93a6adc938f11039f371bc5bcd26c3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"phf",
|
"phf 0.12.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -655,9 +655,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap"
|
name = "clap"
|
||||||
version = "4.5.53"
|
version = "4.5.54"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c9e340e012a1bf4935f5282ed1436d1489548e8f72308207ea5df0e23d2d03f8"
|
checksum = "c6e6ff9dcd79cff5cd969a17a545d79e84ab086e444102a591e288a8aa3ce394"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap_builder",
|
"clap_builder",
|
||||||
"clap_derive",
|
"clap_derive",
|
||||||
@@ -665,9 +665,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap_builder"
|
name = "clap_builder"
|
||||||
version = "4.5.53"
|
version = "4.5.54"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d76b5d13eaa18c901fd2f7fca939fefe3a0727a953561fefdf3b2922b8569d00"
|
checksum = "fa42cf4d2b7a41bc8f663a7cab4031ebafa1bf3875705bfaf8466dc60ab52c00"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anstream",
|
"anstream",
|
||||||
"anstyle",
|
"anstyle",
|
||||||
@@ -684,7 +684,7 @@ dependencies = [
|
|||||||
"heck",
|
"heck",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.112",
|
"syn 2.0.114",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -898,7 +898,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.112",
|
"syn 2.0.114",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -932,7 +932,7 @@ dependencies = [
|
|||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"strsim",
|
"strsim",
|
||||||
"syn 2.0.112",
|
"syn 2.0.114",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -945,7 +945,7 @@ dependencies = [
|
|||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"strsim",
|
"strsim",
|
||||||
"syn 2.0.112",
|
"syn 2.0.114",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -956,7 +956,7 @@ checksum = "d38308df82d1080de0afee5d069fa14b0326a88c14f15c5ccda35b4a6c414c81"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"darling_core 0.21.3",
|
"darling_core 0.21.3",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.112",
|
"syn 2.0.114",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -967,7 +967,7 @@ checksum = "ac3984ec7bd6cfa798e62b4a642426a5be0e68f9401cfc2a01e3fa9ea2fcdb8d"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"darling_core 0.23.0",
|
"darling_core 0.23.0",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.112",
|
"syn 2.0.114",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1010,7 +1010,7 @@ dependencies = [
|
|||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"rustc_version",
|
"rustc_version",
|
||||||
"syn 2.0.112",
|
"syn 2.0.114",
|
||||||
"unicode-xid",
|
"unicode-xid",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -1034,7 +1034,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.112",
|
"syn 2.0.114",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1241,9 +1241,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "find-msvc-tools"
|
name = "find-msvc-tools"
|
||||||
version = "0.1.6"
|
version = "0.1.7"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "645cbb3a84e60b7531617d5ae4e57f7e27308f6445f5abf653209ea76dec8dff"
|
checksum = "f449e6c6c08c865631d4890cfacf252b3d396c9bcc83adb6623cdb02a8336c41"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "flume"
|
name = "flume"
|
||||||
@@ -1371,7 +1371,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.112",
|
"syn 2.0.114",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1422,9 +1422,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "getrandom"
|
name = "getrandom"
|
||||||
version = "0.2.16"
|
version = "0.2.17"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592"
|
checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"js-sys",
|
"js-sys",
|
||||||
@@ -1484,9 +1484,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "h2"
|
name = "h2"
|
||||||
version = "0.4.12"
|
version = "0.4.13"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f3c0b69cfcb4e1b9f1bf2f53f95f766e4661169728ec61cd3fe5a0166f2d1386"
|
checksum = "2f44da3a8150a6703ed5d34e164b875fd14c2cdab9af1252a9a1020bde2bdc54"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"atomic-waker",
|
"atomic-waker",
|
||||||
"bytes",
|
"bytes",
|
||||||
@@ -1494,7 +1494,7 @@ dependencies = [
|
|||||||
"futures-core",
|
"futures-core",
|
||||||
"futures-sink",
|
"futures-sink",
|
||||||
"http",
|
"http",
|
||||||
"indexmap 2.12.1",
|
"indexmap 2.13.0",
|
||||||
"slab",
|
"slab",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tokio-util",
|
"tokio-util",
|
||||||
@@ -1771,13 +1771,14 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "ical"
|
name = "ical"
|
||||||
version = "0.11.0"
|
version = "0.11.0"
|
||||||
source = "git+https://github.com/lennart-k/ical-rs#dcd3b106758a054f46a5172103abb17972ad032d"
|
source = "git+https://github.com/lennart-k/ical-rs?branch=dev#28e982f928a73f5af13f1e59e28da419567bf93f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"chrono-tz",
|
"chrono-tz",
|
||||||
"derive_more",
|
"derive_more",
|
||||||
"itertools 0.14.0",
|
"itertools 0.14.0",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
|
"phf 0.13.1",
|
||||||
"regex",
|
"regex",
|
||||||
"rrule",
|
"rrule",
|
||||||
"thiserror 2.0.17",
|
"thiserror 2.0.17",
|
||||||
@@ -1904,9 +1905,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "indexmap"
|
name = "indexmap"
|
||||||
version = "2.12.1"
|
version = "2.13.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0ad4bb2b565bca0645f4d68c5c9af97fba094e9791da685bf83cb5f3ce74acf2"
|
checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"equivalent",
|
"equivalent",
|
||||||
"hashbrown 0.16.1",
|
"hashbrown 0.16.1",
|
||||||
@@ -1922,9 +1923,9 @@ checksum = "c8fae54786f62fb2918dcfae3d568594e50eb9b5c25bf04371af6fe7516452fb"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "insta"
|
name = "insta"
|
||||||
version = "1.45.1"
|
version = "1.46.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "983e3b24350c84ab8a65151f537d67afbbf7153bb9f1110e03e9fa9b07f67a5c"
|
checksum = "1b66886d14d18d420ab5052cbff544fc5d34d0b2cdd35eb5976aaa10a4a472e5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"console",
|
"console",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
@@ -2018,9 +2019,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.178"
|
version = "0.2.180"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "37c93d8daa9d8a012fd8ab92f088405fb202ea0b6ab73ee2482ae66af4f42091"
|
checksum = "bcc35a38544a891a5f7c865aca548a982ccb3b8650a5b06d0fd33a10283c56fc"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libm"
|
name = "libm"
|
||||||
@@ -2241,7 +2242,7 @@ checksum = "51e219e79014df21a225b1860a479e2dcd7cbd9130f4defd4bd0e191ea31d67d"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"base64 0.22.1",
|
"base64 0.22.1",
|
||||||
"chrono",
|
"chrono",
|
||||||
"getrandom 0.2.16",
|
"getrandom 0.2.17",
|
||||||
"http",
|
"http",
|
||||||
"rand 0.8.5",
|
"rand 0.8.5",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
@@ -2334,7 +2335,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.112",
|
"syn 2.0.114",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -2520,7 +2521,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "1a2a4764cc1f8d961d802af27193c6f4f0124bd0e76e8393cf818e18880f0524"
|
checksum = "1a2a4764cc1f8d961d802af27193c6f4f0124bd0e76e8393cf818e18880f0524"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"argon2",
|
"argon2",
|
||||||
"getrandom 0.2.16",
|
"getrandom 0.2.17",
|
||||||
"password-hash",
|
"password-hash",
|
||||||
"pbkdf2",
|
"pbkdf2",
|
||||||
"rand_core 0.6.4",
|
"rand_core 0.6.4",
|
||||||
@@ -2569,7 +2570,7 @@ dependencies = [
|
|||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"proc-macro2-diagnostics",
|
"proc-macro2-diagnostics",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.112",
|
"syn 2.0.114",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -2593,7 +2594,18 @@ version = "0.12.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "913273894cec178f401a31ec4b656318d95473527be05c0752cc41cdc32be8b7"
|
checksum = "913273894cec178f401a31ec4b656318d95473527be05c0752cc41cdc32be8b7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"phf_shared",
|
"phf_shared 0.12.1",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "phf"
|
||||||
|
version = "0.13.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c1562dc717473dbaa4c1f85a36410e03c047b2e7df7f45ee938fbef64ae7fadf"
|
||||||
|
dependencies = [
|
||||||
|
"phf_macros",
|
||||||
|
"phf_shared 0.13.1",
|
||||||
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -2602,8 +2614,8 @@ version = "0.12.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "efbdcb6f01d193b17f0b9c3360fa7e0e620991b193ff08702f78b3ce365d7e61"
|
checksum = "efbdcb6f01d193b17f0b9c3360fa7e0e620991b193ff08702f78b3ce365d7e61"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"phf_generator",
|
"phf_generator 0.12.1",
|
||||||
"phf_shared",
|
"phf_shared 0.12.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -2613,7 +2625,30 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "2cbb1126afed61dd6368748dae63b1ee7dc480191c6262a3b4ff1e29d86a6c5b"
|
checksum = "2cbb1126afed61dd6368748dae63b1ee7dc480191c6262a3b4ff1e29d86a6c5b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"fastrand",
|
"fastrand",
|
||||||
"phf_shared",
|
"phf_shared 0.12.1",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "phf_generator"
|
||||||
|
version = "0.13.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "135ace3a761e564ec88c03a77317a7c6b80bb7f7135ef2544dbe054243b89737"
|
||||||
|
dependencies = [
|
||||||
|
"fastrand",
|
||||||
|
"phf_shared 0.13.1",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "phf_macros"
|
||||||
|
version = "0.13.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "812f032b54b1e759ccd5f8b6677695d5268c588701effba24601f6932f8269ef"
|
||||||
|
dependencies = [
|
||||||
|
"phf_generator 0.13.1",
|
||||||
|
"phf_shared 0.13.1",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.114",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -2625,6 +2660,15 @@ dependencies = [
|
|||||||
"siphasher",
|
"siphasher",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "phf_shared"
|
||||||
|
version = "0.13.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e57fef6bc5981e38c2ce2d63bfa546861309f875b8a75f092d1d54ae2d64f266"
|
||||||
|
dependencies = [
|
||||||
|
"siphasher",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pin-project"
|
name = "pin-project"
|
||||||
version = "1.1.10"
|
version = "1.1.10"
|
||||||
@@ -2642,7 +2686,7 @@ checksum = "6e918e4ff8c4549eb882f14b3a4bc8c8bc93de829416eacf579f1207a8fbf861"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.112",
|
"syn 2.0.114",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -2781,9 +2825,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.104"
|
version = "1.0.105"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9695f8df41bb4f3d222c95a67532365f569318332d03d5f3f67f37b20e6ebdf0"
|
checksum = "535d180e0ecab6268a3e718bb9fd44db66bbbc256257165fc699dadf70d16fe7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"unicode-ident",
|
"unicode-ident",
|
||||||
]
|
]
|
||||||
@@ -2796,16 +2840,16 @@ checksum = "af066a9c399a26e020ada66a034357a868728e72cd426f3adcd35f80d88d88c8"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.112",
|
"syn 2.0.114",
|
||||||
"version_check",
|
"version_check",
|
||||||
"yansi",
|
"yansi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "prost"
|
name = "prost"
|
||||||
version = "0.14.1"
|
version = "0.14.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7231bd9b3d3d33c86b58adbac74b5ec0ad9f496b19d22801d773636feaa95f3d"
|
checksum = "d2ea70524a2f82d518bce41317d0fae74151505651af45faf1ffbd6fd33f0568"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bytes",
|
"bytes",
|
||||||
"prost-derive",
|
"prost-derive",
|
||||||
@@ -2813,15 +2857,15 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "prost-derive"
|
name = "prost-derive"
|
||||||
version = "0.14.1"
|
version = "0.14.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9120690fafc389a67ba3803df527d0ec9cbbc9cc45e4cc20b332996dfb672425"
|
checksum = "27c6023962132f4b30eb4c172c91ce92d933da334c59c23cddee82358ddafb0b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"itertools 0.14.0",
|
"itertools 0.14.0",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.112",
|
"syn 2.0.114",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -2890,9 +2934,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "quote"
|
name = "quote"
|
||||||
version = "1.0.42"
|
version = "1.0.43"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a338cc41d27e6cc6dce6cefc13a0729dfbb81c262b1f519331575dd80ef3067f"
|
checksum = "dc74d9a594b72ae6656596548f56f667211f8a97b3d4c3d467150794690dc40a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
]
|
]
|
||||||
@@ -2950,7 +2994,7 @@ version = "0.6.4"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
|
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"getrandom 0.2.16",
|
"getrandom 0.2.17",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -3017,7 +3061,7 @@ checksum = "b7186006dcb21920990093f30e3dea63b7d6e977bf1256be20c3563a5db070da"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.112",
|
"syn 2.0.114",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -3116,7 +3160,7 @@ checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"cc",
|
"cc",
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"getrandom 0.2.16",
|
"getrandom 0.2.17",
|
||||||
"libc",
|
"libc",
|
||||||
"untrusted",
|
"untrusted",
|
||||||
"windows-sys 0.52.0",
|
"windows-sys 0.52.0",
|
||||||
@@ -3148,9 +3192,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rsa"
|
name = "rsa"
|
||||||
version = "0.9.9"
|
version = "0.9.10"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "40a0376c50d0358279d9d643e4bf7b7be212f1f4ff1da9070a7b54d22ef75c88"
|
checksum = "b8573f03f5883dcaebdfcf4725caa1ecb9c15b2ef50c43a07b816e06799bb12d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"const-oid",
|
"const-oid",
|
||||||
"digest",
|
"digest",
|
||||||
@@ -3191,7 +3235,7 @@ dependencies = [
|
|||||||
"regex",
|
"regex",
|
||||||
"relative-path",
|
"relative-path",
|
||||||
"rustc_version",
|
"rustc_version",
|
||||||
"syn 2.0.112",
|
"syn 2.0.114",
|
||||||
"unicode-ident",
|
"unicode-ident",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -3203,7 +3247,7 @@ checksum = "b3a8fb4672e840a587a66fc577a5491375df51ddb88f2a2c2a792598c326fe14"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"quote",
|
"quote",
|
||||||
"rand 0.8.5",
|
"rand 0.8.5",
|
||||||
"syn 2.0.112",
|
"syn 2.0.114",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -3236,7 +3280,7 @@ dependencies = [
|
|||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"rust-embed-utils",
|
"rust-embed-utils",
|
||||||
"syn 2.0.112",
|
"syn 2.0.114",
|
||||||
"walkdir",
|
"walkdir",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -3306,7 +3350,7 @@ dependencies = [
|
|||||||
"serde",
|
"serde",
|
||||||
"sqlx",
|
"sqlx",
|
||||||
"tokio",
|
"tokio",
|
||||||
"toml 0.9.10+spec-1.1.0",
|
"toml 0.9.11+spec-1.1.0",
|
||||||
"tower",
|
"tower",
|
||||||
"tower-http",
|
"tower-http",
|
||||||
"tower-sessions",
|
"tower-sessions",
|
||||||
@@ -3555,6 +3599,7 @@ dependencies = [
|
|||||||
"chrono",
|
"chrono",
|
||||||
"criterion",
|
"criterion",
|
||||||
"derive_more",
|
"derive_more",
|
||||||
|
"ical",
|
||||||
"password-auth",
|
"password-auth",
|
||||||
"password-hash",
|
"password-hash",
|
||||||
"pbkdf2",
|
"pbkdf2",
|
||||||
@@ -3594,9 +3639,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustls"
|
name = "rustls"
|
||||||
version = "0.23.35"
|
version = "0.23.36"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "533f54bc6a7d4f647e46ad909549eda97bf5afc1585190ef692b4286b198bd8f"
|
checksum = "c665f33d38cea657d9614f766881e4d510e0eda4239891eea56b4cadcf01801b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"ring",
|
"ring",
|
||||||
@@ -3735,14 +3780,14 @@ checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.112",
|
"syn 2.0.114",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_json"
|
name = "serde_json"
|
||||||
version = "1.0.148"
|
version = "1.0.149"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3084b546a1dd6289475996f182a22aba973866ea8e8b02c51d9f46b1336a22da"
|
checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"itoa",
|
"itoa",
|
||||||
"memchr",
|
"memchr",
|
||||||
@@ -3811,7 +3856,7 @@ dependencies = [
|
|||||||
"chrono",
|
"chrono",
|
||||||
"hex",
|
"hex",
|
||||||
"indexmap 1.9.3",
|
"indexmap 1.9.3",
|
||||||
"indexmap 2.12.1",
|
"indexmap 2.13.0",
|
||||||
"schemars 0.9.0",
|
"schemars 0.9.0",
|
||||||
"schemars 1.2.0",
|
"schemars 1.2.0",
|
||||||
"serde_core",
|
"serde_core",
|
||||||
@@ -3829,7 +3874,7 @@ dependencies = [
|
|||||||
"darling 0.21.3",
|
"darling 0.21.3",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.112",
|
"syn 2.0.114",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -3991,7 +4036,7 @@ dependencies = [
|
|||||||
"futures-util",
|
"futures-util",
|
||||||
"hashbrown 0.15.5",
|
"hashbrown 0.15.5",
|
||||||
"hashlink",
|
"hashlink",
|
||||||
"indexmap 2.12.1",
|
"indexmap 2.13.0",
|
||||||
"log",
|
"log",
|
||||||
"memchr",
|
"memchr",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
@@ -4018,7 +4063,7 @@ dependencies = [
|
|||||||
"quote",
|
"quote",
|
||||||
"sqlx-core",
|
"sqlx-core",
|
||||||
"sqlx-macros-core",
|
"sqlx-macros-core",
|
||||||
"syn 2.0.112",
|
"syn 2.0.114",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -4041,7 +4086,7 @@ dependencies = [
|
|||||||
"sqlx-mysql",
|
"sqlx-mysql",
|
||||||
"sqlx-postgres",
|
"sqlx-postgres",
|
||||||
"sqlx-sqlite",
|
"sqlx-sqlite",
|
||||||
"syn 2.0.112",
|
"syn 2.0.114",
|
||||||
"tokio",
|
"tokio",
|
||||||
"url",
|
"url",
|
||||||
]
|
]
|
||||||
@@ -4193,7 +4238,7 @@ dependencies = [
|
|||||||
"heck",
|
"heck",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.112",
|
"syn 2.0.114",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -4215,9 +4260,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "2.0.112"
|
version = "2.0.114"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "21f182278bf2d2bcb3c88b1b08a37df029d71ce3d3ae26168e3c653b213b99d4"
|
checksum = "d4d107df263a3013ef9b1879b0df87d706ff80f65a86ea879bd9c31f9b307c2a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
@@ -4241,7 +4286,7 @@ checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.112",
|
"syn 2.0.114",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -4283,7 +4328,7 @@ checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.112",
|
"syn 2.0.114",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -4294,7 +4339,7 @@ checksum = "3ff15c8ecd7de3849db632e14d18d2571fa09dfc5ed93479bc4485c7a517c913"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.112",
|
"syn 2.0.114",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -4374,9 +4419,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tokio"
|
name = "tokio"
|
||||||
version = "1.48.0"
|
version = "1.49.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ff360e02eab121e0bc37a2d3b4d4dc622e6eda3a8e5253d5435ecf5bd4c68408"
|
checksum = "72a2903cd7736441aac9df9d7688bd0ce48edccaadf181c3b90be801e81d3d86"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bytes",
|
"bytes",
|
||||||
"libc",
|
"libc",
|
||||||
@@ -4398,7 +4443,7 @@ checksum = "af407857209536a95c8e56f8231ef2c2e2aff839b22e07a1ffcbc617e9db9fa5"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.112",
|
"syn 2.0.114",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -4413,9 +4458,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tokio-stream"
|
name = "tokio-stream"
|
||||||
version = "0.1.17"
|
version = "0.1.18"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "eca58d7bba4a75707817a2c44174253f9236b2d5fbd055602e9d5c07c139a047"
|
checksum = "32da49809aab5c3bc678af03902d4ccddea2a87d028d86392a4b1560c6906c70"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"futures-core",
|
"futures-core",
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
@@ -4424,9 +4469,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tokio-util"
|
name = "tokio-util"
|
||||||
version = "0.7.17"
|
version = "0.7.18"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2efa149fe76073d6e8fd97ef4f4eca7b67f599660115591483572e406e165594"
|
checksum = "9ae9cec805b01e8fc3fd2fe289f89149a9b66dd16786abd8b19cfa7b48cb0098"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bytes",
|
"bytes",
|
||||||
"futures-core",
|
"futures-core",
|
||||||
@@ -4449,11 +4494,11 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "toml"
|
name = "toml"
|
||||||
version = "0.9.10+spec-1.1.0"
|
version = "0.9.11+spec-1.1.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0825052159284a1a8b4d6c0c86cbc801f2da5afd2b225fa548c72f2e74002f48"
|
checksum = "f3afc9a848309fe1aaffaed6e1546a7a14de1f935dc9d89d32afd9a44bab7c46"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"indexmap 2.12.1",
|
"indexmap 2.13.0",
|
||||||
"serde_core",
|
"serde_core",
|
||||||
"serde_spanned 1.0.4",
|
"serde_spanned 1.0.4",
|
||||||
"toml_datetime 0.7.5+spec-1.1.0",
|
"toml_datetime 0.7.5+spec-1.1.0",
|
||||||
@@ -4486,7 +4531,7 @@ version = "0.22.27"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a"
|
checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"indexmap 2.12.1",
|
"indexmap 2.13.0",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_spanned 0.6.9",
|
"serde_spanned 0.6.9",
|
||||||
"toml_datetime 0.6.11",
|
"toml_datetime 0.6.11",
|
||||||
@@ -4500,7 +4545,7 @@ version = "0.23.10+spec-1.0.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "84c8b9f757e028cee9fa244aea147aab2a9ec09d5325a9b01e0a49730c2b5269"
|
checksum = "84c8b9f757e028cee9fa244aea147aab2a9ec09d5325a9b01e0a49730c2b5269"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"indexmap 2.12.1",
|
"indexmap 2.13.0",
|
||||||
"toml_datetime 0.7.5+spec-1.1.0",
|
"toml_datetime 0.7.5+spec-1.1.0",
|
||||||
"toml_parser",
|
"toml_parser",
|
||||||
"winnow",
|
"winnow",
|
||||||
@@ -4572,7 +4617,7 @@ checksum = "d039ad9159c98b70ecfd540b2573b97f7f52c3e8d9f8ad57a24b916a536975f9"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"futures-core",
|
"futures-core",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"indexmap 2.12.1",
|
"indexmap 2.13.0",
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
"slab",
|
"slab",
|
||||||
"sync_wrapper",
|
"sync_wrapper",
|
||||||
@@ -4710,7 +4755,7 @@ checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.112",
|
"syn 2.0.114",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -4736,16 +4781,13 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tracing-opentelemetry"
|
name = "tracing-opentelemetry"
|
||||||
version = "0.32.0"
|
version = "0.32.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1e6e5658463dd88089aba75c7791e1d3120633b1bfde22478b28f625a9bb1b8e"
|
checksum = "1ac28f2d093c6c477eaa76b23525478f38de514fa9aeb1285738d4b97a9552fc"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"js-sys",
|
"js-sys",
|
||||||
"opentelemetry",
|
"opentelemetry",
|
||||||
"opentelemetry_sdk",
|
|
||||||
"rustversion",
|
|
||||||
"smallvec",
|
"smallvec",
|
||||||
"thiserror 2.0.17",
|
|
||||||
"tracing",
|
"tracing",
|
||||||
"tracing-core",
|
"tracing-core",
|
||||||
"tracing-log",
|
"tracing-log",
|
||||||
@@ -4794,9 +4836,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicase"
|
name = "unicase"
|
||||||
version = "2.8.1"
|
version = "2.9.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "75b844d17643ee918803943289730bec8aac480150456169e647ed0b576ba539"
|
checksum = "dbc4bc3a9f746d862c45cb89d705aa10f187bb96c76001afab07a0d35ce60142"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-bidi"
|
name = "unicode-bidi"
|
||||||
@@ -4845,14 +4887,15 @@ checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "url"
|
name = "url"
|
||||||
version = "2.5.7"
|
version = "2.5.8"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "08bc136a29a3d1758e07a9cca267be308aeebf5cfd5a10f3f67ab2097683ef5b"
|
checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"form_urlencoded",
|
"form_urlencoded",
|
||||||
"idna",
|
"idna",
|
||||||
"percent-encoding",
|
"percent-encoding",
|
||||||
"serde",
|
"serde",
|
||||||
|
"serde_derive",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -4910,7 +4953,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "f6728de8767c8dea44f41b88115a205ed23adc3302e1b4342be59d922934dae5"
|
checksum = "f6728de8767c8dea44f41b88115a205ed23adc3302e1b4342be59d922934dae5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"glob",
|
"glob",
|
||||||
"phf",
|
"phf 0.12.1",
|
||||||
"phf_codegen",
|
"phf_codegen",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -4999,7 +5042,7 @@ dependencies = [
|
|||||||
"bumpalo",
|
"bumpalo",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.112",
|
"syn 2.0.114",
|
||||||
"wasm-bindgen-shared",
|
"wasm-bindgen-shared",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -5034,9 +5077,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "webpki-roots"
|
name = "webpki-roots"
|
||||||
version = "1.0.4"
|
version = "1.0.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b2878ef029c47c6e8cf779119f20fcf52bde7ad42a731b2a304bc221df17571e"
|
checksum = "12bed680863276c63889429bfd6cab3b99943659923822de1c8a39c49e4d722c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"rustls-pki-types",
|
"rustls-pki-types",
|
||||||
]
|
]
|
||||||
@@ -5103,7 +5146,7 @@ checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.112",
|
"syn 2.0.114",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -5114,7 +5157,7 @@ checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.112",
|
"syn 2.0.114",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -5402,7 +5445,7 @@ dependencies = [
|
|||||||
"itertools 0.14.0",
|
"itertools 0.14.0",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.112",
|
"syn 2.0.114",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -5430,28 +5473,28 @@ checksum = "b659052874eb698efe5b9e8cf382204678a0086ebf46982b79d6ca3182927e5d"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.112",
|
"syn 2.0.114",
|
||||||
"synstructure",
|
"synstructure",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zerocopy"
|
name = "zerocopy"
|
||||||
version = "0.8.31"
|
version = "0.8.33"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "fd74ec98b9250adb3ca554bdde269adf631549f51d8a8f8f0a10b50f1cb298c3"
|
checksum = "668f5168d10b9ee831de31933dc111a459c97ec93225beb307aed970d1372dfd"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"zerocopy-derive",
|
"zerocopy-derive",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zerocopy-derive"
|
name = "zerocopy-derive"
|
||||||
version = "0.8.31"
|
version = "0.8.33"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d8a8d209fdf45cf5138cbb5a506f6b52522a25afccc534d1475dad8e31105c6a"
|
checksum = "2c7962b26b0a8685668b671ee4b54d007a67d4eaf05fda79ac0ecf41e32270f1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.112",
|
"syn 2.0.114",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -5471,7 +5514,7 @@ checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.112",
|
"syn 2.0.114",
|
||||||
"synstructure",
|
"synstructure",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -5511,11 +5554,11 @@ checksum = "eadce39539ca5cb3985590102671f2567e659fca9666581ad3411d59207951f3"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.112",
|
"syn 2.0.114",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zmij"
|
name = "zmij"
|
||||||
version = "1.0.5"
|
version = "1.0.13"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e3280a1b827474fcd5dbef4b35a674deb52ba5c312363aef9135317df179d81b"
|
checksum = "ac93432f5b761b22864c774aac244fa5c0fd877678a4c37ebf6cf42208f9c9ec"
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ strum = "0.27"
|
|||||||
strum_macros = "0.27"
|
strum_macros = "0.27"
|
||||||
serde_json = { version = "1.0", features = ["raw_value"] }
|
serde_json = { version = "1.0", features = ["raw_value"] }
|
||||||
sqlx-sqlite = { version = "0.8", features = ["bundled"] }
|
sqlx-sqlite = { version = "0.8", features = ["bundled"] }
|
||||||
ical = { git = "https://github.com/lennart-k/ical-rs", features = [
|
ical = { git = "https://github.com/lennart-k/ical-rs", branch = "dev", features = [
|
||||||
"chrono-tz",
|
"chrono-tz",
|
||||||
] }
|
] }
|
||||||
toml = "0.9"
|
toml = "0.9"
|
||||||
|
|||||||
@@ -5,13 +5,11 @@ use axum::extract::State;
|
|||||||
use axum::{extract::Path, response::Response};
|
use axum::{extract::Path, response::Response};
|
||||||
use headers::{ContentType, HeaderMapExt};
|
use headers::{ContentType, HeaderMapExt};
|
||||||
use http::{HeaderValue, Method, StatusCode, header};
|
use http::{HeaderValue, Method, StatusCode, header};
|
||||||
use ical::builder::calendar::IcalCalendarBuilder;
|
use ical::component::IcalCalendar;
|
||||||
use ical::generator::Emitter;
|
use ical::generator::Emitter;
|
||||||
use ical::property::Property;
|
use ical::property::ContentLine;
|
||||||
use percent_encoding::{CONTROLS, utf8_percent_encode};
|
use percent_encoding::{CONTROLS, utf8_percent_encode};
|
||||||
use rustical_ical::{CalendarObjectComponent, EventObject};
|
|
||||||
use rustical_store::{CalendarStore, SubscriptionStore, auth::Principal};
|
use rustical_store::{CalendarStore, SubscriptionStore, auth::Principal};
|
||||||
use std::collections::HashMap;
|
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use tracing::instrument;
|
use tracing::instrument;
|
||||||
|
|
||||||
@@ -33,60 +31,45 @@ pub async fn route_get<C: CalendarStore, S: SubscriptionStore>(
|
|||||||
return Err(crate::Error::Unauthorized);
|
return Err(crate::Error::Unauthorized);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut vtimezones = HashMap::new();
|
let objects = cal_store
|
||||||
let objects = cal_store.get_objects(&principal, &calendar_id).await?;
|
.get_objects(&principal, &calendar_id)
|
||||||
|
.await?
|
||||||
|
.into_iter()
|
||||||
|
.map(|(_, object)| object.into())
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
let mut props = vec![];
|
||||||
|
|
||||||
let mut ical_calendar_builder = IcalCalendarBuilder::version("2.0")
|
|
||||||
.gregorian()
|
|
||||||
.prodid("RustiCal");
|
|
||||||
if let Some(displayname) = calendar.meta.displayname {
|
if let Some(displayname) = calendar.meta.displayname {
|
||||||
ical_calendar_builder = ical_calendar_builder.set(Property {
|
props.push(ContentLine {
|
||||||
name: "X-WR-CALNAME".to_owned(),
|
name: "X-WR-CALNAME".to_owned(),
|
||||||
value: Some(displayname),
|
value: Some(displayname),
|
||||||
params: vec![],
|
params: vec![].into(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if let Some(description) = calendar.meta.description {
|
if let Some(description) = calendar.meta.description {
|
||||||
ical_calendar_builder = ical_calendar_builder.set(Property {
|
props.push(ContentLine {
|
||||||
name: "X-WR-CALDESC".to_owned(),
|
name: "X-WR-CALDESC".to_owned(),
|
||||||
value: Some(description),
|
value: Some(description),
|
||||||
params: vec![],
|
params: vec![].into(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if let Some(color) = calendar.meta.color {
|
||||||
|
props.push(ContentLine {
|
||||||
|
name: "X-WR-CALCOLOR".to_owned(),
|
||||||
|
value: Some(color),
|
||||||
|
params: vec![].into(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if let Some(timezone_id) = calendar.timezone_id {
|
if let Some(timezone_id) = calendar.timezone_id {
|
||||||
ical_calendar_builder = ical_calendar_builder.set(Property {
|
props.push(ContentLine {
|
||||||
name: "X-WR-TIMEZONE".to_owned(),
|
name: "X-WR-TIMEZONE".to_owned(),
|
||||||
value: Some(timezone_id),
|
value: Some(timezone_id),
|
||||||
params: vec![],
|
params: vec![].into(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
for object in &objects {
|
let export_calendar = IcalCalendar::from_objects("RustiCal Export".to_owned(), objects, props);
|
||||||
vtimezones.extend(object.get_vtimezones());
|
|
||||||
match object.get_data() {
|
|
||||||
CalendarObjectComponent::Event(EventObject { event, .. }, overrides) => {
|
|
||||||
ical_calendar_builder = ical_calendar_builder
|
|
||||||
.add_event(event.clone())
|
|
||||||
.add_events(overrides.iter().map(|ev| ev.event.clone()));
|
|
||||||
}
|
|
||||||
CalendarObjectComponent::Todo(todo, overrides) => {
|
|
||||||
ical_calendar_builder = ical_calendar_builder
|
|
||||||
.add_todo(todo.clone())
|
|
||||||
.add_todos(overrides.iter().cloned());
|
|
||||||
}
|
|
||||||
CalendarObjectComponent::Journal(journal, overrides) => {
|
|
||||||
ical_calendar_builder = ical_calendar_builder
|
|
||||||
.add_journal(journal.clone())
|
|
||||||
.add_journals(overrides.iter().cloned());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ical_calendar_builder = ical_calendar_builder.add_timezones(vtimezones.into_values().cloned());
|
|
||||||
|
|
||||||
let ical_calendar = ical_calendar_builder
|
|
||||||
.build()
|
|
||||||
.map_err(|parser_error| Error::IcalError(parser_error.into()))?;
|
|
||||||
|
|
||||||
let mut resp = Response::builder().status(StatusCode::OK);
|
let mut resp = Response::builder().status(StatusCode::OK);
|
||||||
let hdrs = resp.headers_mut().unwrap();
|
let hdrs = resp.headers_mut().unwrap();
|
||||||
@@ -104,6 +87,6 @@ pub async fn route_get<C: CalendarStore, S: SubscriptionStore>(
|
|||||||
if matches!(method, Method::HEAD) {
|
if matches!(method, Method::HEAD) {
|
||||||
Ok(resp.body(Body::empty()).unwrap())
|
Ok(resp.body(Body::empty()).unwrap())
|
||||||
} else {
|
} else {
|
||||||
Ok(resp.body(Body::new(ical_calendar.generate())).unwrap())
|
Ok(resp.body(Body::new(export_calendar.generate())).unwrap())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,12 +5,9 @@ use axum::{
|
|||||||
response::{IntoResponse, Response},
|
response::{IntoResponse, Response},
|
||||||
};
|
};
|
||||||
use http::StatusCode;
|
use http::StatusCode;
|
||||||
use ical::{
|
use ical::parser::{Component, ComponentMut};
|
||||||
generator::Emitter,
|
|
||||||
parser::{Component, ComponentMut},
|
|
||||||
};
|
|
||||||
use rustical_dav::header::Overwrite;
|
use rustical_dav::header::Overwrite;
|
||||||
use rustical_ical::{CalendarObject, CalendarObjectType};
|
use rustical_ical::CalendarObjectType;
|
||||||
use rustical_store::{
|
use rustical_store::{
|
||||||
Calendar, CalendarMetadata, CalendarStore, SubscriptionStore, auth::Principal,
|
Calendar, CalendarMetadata, CalendarStore, SubscriptionStore, auth::Principal,
|
||||||
};
|
};
|
||||||
@@ -29,18 +26,11 @@ pub async fn route_import<C: CalendarStore, S: SubscriptionStore>(
|
|||||||
return Err(Error::Unauthorized);
|
return Err(Error::Unauthorized);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut parser = ical::IcalParser::new(BufReader::new(body.as_bytes()));
|
let parser = ical::IcalParser::new(BufReader::new(body.as_bytes()));
|
||||||
let mut cal = parser
|
let mut cal = parser
|
||||||
.next()
|
.expect_one()
|
||||||
.expect("input must contain calendar")
|
.map_err(rustical_ical::Error::ParserError)?
|
||||||
.unwrap()
|
|
||||||
.mutable();
|
.mutable();
|
||||||
if parser.next().is_some() {
|
|
||||||
return Err(rustical_ical::Error::InvalidData(
|
|
||||||
"multiple calendars, only one allowed".to_owned(),
|
|
||||||
)
|
|
||||||
.into());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Extract calendar metadata
|
// Extract calendar metadata
|
||||||
let displayname = cal
|
let displayname = cal
|
||||||
@@ -49,14 +39,19 @@ pub async fn route_import<C: CalendarStore, S: SubscriptionStore>(
|
|||||||
let description = cal
|
let description = cal
|
||||||
.get_property("X-WR-CALDESC")
|
.get_property("X-WR-CALDESC")
|
||||||
.and_then(|prop| prop.value.clone());
|
.and_then(|prop| prop.value.clone());
|
||||||
|
let color = cal
|
||||||
|
.get_property("X-WR-CALCOLOR")
|
||||||
|
.and_then(|prop| prop.value.clone());
|
||||||
let timezone_id = cal
|
let timezone_id = cal
|
||||||
.get_property("X-WR-TIMEZONE")
|
.get_property("X-WR-TIMEZONE")
|
||||||
.and_then(|prop| prop.value.clone());
|
.and_then(|prop| prop.value.clone());
|
||||||
// These properties should not appear in the expanded calendar objects
|
// These properties should not appear in the expanded calendar objects
|
||||||
cal.remove_property("X-WR-CALNAME");
|
cal.remove_property("X-WR-CALNAME");
|
||||||
cal.remove_property("X-WR-CALDESC");
|
cal.remove_property("X-WR-CALDESC");
|
||||||
|
cal.remove_property("X-WR-CALCOLOR");
|
||||||
cal.remove_property("X-WR-TIMEZONE");
|
cal.remove_property("X-WR-TIMEZONE");
|
||||||
let cal = cal.verify().unwrap();
|
let cal = cal.build(None).unwrap();
|
||||||
|
|
||||||
// Make sure timezone is valid
|
// Make sure timezone is valid
|
||||||
if let Some(timezone_id) = timezone_id.as_ref() {
|
if let Some(timezone_id) = timezone_id.as_ref() {
|
||||||
assert!(
|
assert!(
|
||||||
@@ -64,8 +59,7 @@ pub async fn route_import<C: CalendarStore, S: SubscriptionStore>(
|
|||||||
"Invalid calendar timezone id"
|
"Invalid calendar timezone id"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
// // Extract necessary component types
|
||||||
// Extract necessary component types
|
|
||||||
let mut cal_components = vec![];
|
let mut cal_components = vec![];
|
||||||
if !cal.events.is_empty() {
|
if !cal.events.is_empty() {
|
||||||
cal_components.push(CalendarObjectType::Event);
|
cal_components.push(CalendarObjectType::Event);
|
||||||
@@ -77,13 +71,12 @@ pub async fn route_import<C: CalendarStore, S: SubscriptionStore>(
|
|||||||
cal_components.push(CalendarObjectType::Todo);
|
cal_components.push(CalendarObjectType::Todo);
|
||||||
}
|
}
|
||||||
|
|
||||||
let expanded_cals = cal.expand_calendar();
|
let objects = cal
|
||||||
// Janky way to convert between IcalCalendar and CalendarObject
|
.into_objects()
|
||||||
let objects = expanded_cals
|
.map_err(rustical_ical::Error::ParserError)?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|cal| cal.generate())
|
.map(Into::into)
|
||||||
.map(|ics| CalendarObject::from_ics(ics, None))
|
.collect();
|
||||||
.collect::<Result<Vec<_>, _>>()?;
|
|
||||||
let new_cal = Calendar {
|
let new_cal = Calendar {
|
||||||
principal,
|
principal,
|
||||||
id: cal_id,
|
id: cal_id,
|
||||||
@@ -91,7 +84,7 @@ pub async fn route_import<C: CalendarStore, S: SubscriptionStore>(
|
|||||||
displayname,
|
displayname,
|
||||||
order: 0,
|
order: 0,
|
||||||
description,
|
description,
|
||||||
color: None,
|
color,
|
||||||
},
|
},
|
||||||
timezone_id,
|
timezone_id,
|
||||||
deleted_at: None,
|
deleted_at: None,
|
||||||
|
|||||||
@@ -92,10 +92,11 @@ pub async fn route_mkcalendar<C: CalendarStore, S: SubscriptionStore>(
|
|||||||
.ok_or_else(|| rustical_dav::Error::BadRequest("No timezone data provided".to_owned()))?
|
.ok_or_else(|| rustical_dav::Error::BadRequest("No timezone data provided".to_owned()))?
|
||||||
.map_err(|_| rustical_dav::Error::BadRequest("Error parsing timezone".to_owned()))?;
|
.map_err(|_| rustical_dav::Error::BadRequest("Error parsing timezone".to_owned()))?;
|
||||||
|
|
||||||
let timezone = calendar.timezones.first().ok_or_else(|| {
|
let timezone = calendar.vtimezones.values().next().ok_or_else(|| {
|
||||||
rustical_dav::Error::BadRequest("No timezone data provided".to_owned())
|
rustical_dav::Error::BadRequest("No timezone data provided".to_owned())
|
||||||
})?;
|
})?;
|
||||||
let timezone: chrono_tz::Tz = timezone.try_into().map_err(|_| {
|
let timezone: Option<chrono_tz::Tz> = timezone.into();
|
||||||
|
let timezone = timezone.ok_or_else(|| {
|
||||||
rustical_dav::Error::BadRequest("Cannot translate VTIMEZONE into IANA TZID".to_owned())
|
rustical_dav::Error::BadRequest("Cannot translate VTIMEZONE into IANA TZID".to_owned())
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ pub async fn get_objects_calendar_multiget<C: CalendarStore>(
|
|||||||
principal: &str,
|
principal: &str,
|
||||||
cal_id: &str,
|
cal_id: &str,
|
||||||
store: &C,
|
store: &C,
|
||||||
) -> Result<(Vec<CalendarObject>, Vec<String>), Error> {
|
) -> Result<(Vec<(String, CalendarObject)>, Vec<String>), Error> {
|
||||||
let mut result = vec![];
|
let mut result = vec![];
|
||||||
let mut not_found = vec![];
|
let mut not_found = vec![];
|
||||||
|
|
||||||
@@ -32,7 +32,7 @@ pub async fn get_objects_calendar_multiget<C: CalendarStore>(
|
|||||||
let filename = filename.trim_start_matches('/');
|
let filename = filename.trim_start_matches('/');
|
||||||
if let Some(object_id) = filename.strip_suffix(".ics") {
|
if let Some(object_id) = filename.strip_suffix(".ics") {
|
||||||
match store.get_object(principal, cal_id, object_id, false).await {
|
match store.get_object(principal, cal_id, object_id, false).await {
|
||||||
Ok(object) => result.push(object),
|
Ok(object) => result.push((object_id.to_owned(), object)),
|
||||||
Err(rustical_store::Error::NotFound) => not_found.push(href.to_string()),
|
Err(rustical_store::Error::NotFound) => not_found.push(href.to_string()),
|
||||||
Err(err) => return Err(err.into()),
|
Err(err) => return Err(err.into()),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
use crate::calendar::methods::report::calendar_query::{
|
use crate::calendar::methods::report::calendar_query::{
|
||||||
TimeRangeElement,
|
TimeRangeElement, prop_filter::PropFilterElement,
|
||||||
prop_filter::{PropFilterElement, PropFilterable},
|
};
|
||||||
|
use ical::{
|
||||||
|
component::IcalCalendarObject,
|
||||||
|
parser::{Component, ical::component::IcalTimeZone},
|
||||||
};
|
};
|
||||||
use ical::parser::ical::component::IcalTimeZone;
|
|
||||||
use rustical_ical::{CalendarObject, CalendarObjectComponent, CalendarObjectType};
|
|
||||||
use rustical_xml::XmlDeserialize;
|
use rustical_xml::XmlDeserialize;
|
||||||
|
|
||||||
#[derive(XmlDeserialize, Clone, Debug, PartialEq)]
|
#[derive(XmlDeserialize, Clone, Debug, PartialEq)]
|
||||||
@@ -24,9 +25,7 @@ pub struct CompFilterElement {
|
|||||||
pub(crate) name: String,
|
pub(crate) name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait CompFilterable: PropFilterable + Sized {
|
pub trait CompFilterable: Component + Sized {
|
||||||
fn get_comp_name(&self) -> &'static str;
|
|
||||||
|
|
||||||
fn match_time_range(&self, time_range: &TimeRangeElement) -> bool;
|
fn match_time_range(&self, time_range: &TimeRangeElement) -> bool;
|
||||||
|
|
||||||
fn match_subcomponents(&self, comp_filter: &CompFilterElement) -> bool;
|
fn match_subcomponents(&self, comp_filter: &CompFilterElement) -> bool;
|
||||||
@@ -68,11 +67,7 @@ pub trait CompFilterable: PropFilterable + Sized {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CompFilterable for CalendarObject {
|
impl CompFilterable for IcalCalendarObject {
|
||||||
fn get_comp_name(&self) -> &'static str {
|
|
||||||
"VCALENDAR"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn match_time_range(&self, _time_range: &TimeRangeElement) -> bool {
|
fn match_time_range(&self, _time_range: &TimeRangeElement) -> bool {
|
||||||
// VCALENDAR has no concept of time range
|
// VCALENDAR has no concept of time range
|
||||||
false
|
false
|
||||||
@@ -83,7 +78,7 @@ impl CompFilterable for CalendarObject {
|
|||||||
.get_vtimezones()
|
.get_vtimezones()
|
||||||
.values()
|
.values()
|
||||||
.map(|tz| tz.matches(comp_filter))
|
.map(|tz| tz.matches(comp_filter))
|
||||||
.chain([self.get_data().matches(comp_filter)]);
|
.chain([self.matches(comp_filter)]);
|
||||||
|
|
||||||
if comp_filter.is_not_defined.is_some() {
|
if comp_filter.is_not_defined.is_some() {
|
||||||
matches.all(|x| x)
|
matches.all(|x| x)
|
||||||
@@ -94,10 +89,6 @@ impl CompFilterable for CalendarObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl CompFilterable for IcalTimeZone {
|
impl CompFilterable for IcalTimeZone {
|
||||||
fn get_comp_name(&self) -> &'static str {
|
|
||||||
"VTIMEZONE"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn match_time_range(&self, _time_range: &TimeRangeElement) -> bool {
|
fn match_time_range(&self, _time_range: &TimeRangeElement) -> bool {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
@@ -107,33 +98,6 @@ impl CompFilterable for IcalTimeZone {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CompFilterable for CalendarObjectComponent {
|
|
||||||
fn get_comp_name(&self) -> &'static str {
|
|
||||||
CalendarObjectType::from(self).as_str()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn match_time_range(&self, time_range: &TimeRangeElement) -> bool {
|
|
||||||
if let Some(start) = &time_range.start
|
|
||||||
&& let Some(last_occurence) = self.get_last_occurence().unwrap_or(None)
|
|
||||||
&& **start > last_occurence.utc()
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if let Some(end) = &time_range.end
|
|
||||||
&& let Some(first_occurence) = self.get_first_occurence().unwrap_or(None)
|
|
||||||
&& **end < first_occurence.utc()
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
fn match_subcomponents(&self, _comp_filter: &CompFilterElement) -> bool {
|
|
||||||
// TODO: Properly check subcomponents
|
|
||||||
true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use chrono::{TimeZone, Utc};
|
use chrono::{TimeZone, Utc};
|
||||||
@@ -166,7 +130,7 @@ END:VCALENDAR";
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_comp_filter_matching() {
|
fn test_comp_filter_matching() {
|
||||||
let object = CalendarObject::from_ics(ICS.to_string(), None).unwrap();
|
let object = CalendarObject::from_ics(ICS.to_string()).unwrap();
|
||||||
|
|
||||||
let comp_filter = CompFilterElement {
|
let comp_filter = CompFilterElement {
|
||||||
is_not_defined: Some(()),
|
is_not_defined: Some(()),
|
||||||
@@ -175,7 +139,10 @@ END:VCALENDAR";
|
|||||||
prop_filter: vec![],
|
prop_filter: vec![],
|
||||||
comp_filter: vec![],
|
comp_filter: vec![],
|
||||||
};
|
};
|
||||||
assert!(!object.matches(&comp_filter), "filter: wants no VCALENDAR");
|
assert!(
|
||||||
|
!object.get_inner().matches(&comp_filter),
|
||||||
|
"filter: wants no VCALENDAR"
|
||||||
|
);
|
||||||
|
|
||||||
let comp_filter = CompFilterElement {
|
let comp_filter = CompFilterElement {
|
||||||
is_not_defined: None,
|
is_not_defined: None,
|
||||||
@@ -190,7 +157,10 @@ END:VCALENDAR";
|
|||||||
comp_filter: vec![],
|
comp_filter: vec![],
|
||||||
}],
|
}],
|
||||||
};
|
};
|
||||||
assert!(!object.matches(&comp_filter), "filter matches VTODO");
|
assert!(
|
||||||
|
!object.get_inner().matches(&comp_filter),
|
||||||
|
"filter matches VTODO"
|
||||||
|
);
|
||||||
|
|
||||||
let comp_filter = CompFilterElement {
|
let comp_filter = CompFilterElement {
|
||||||
is_not_defined: None,
|
is_not_defined: None,
|
||||||
@@ -205,7 +175,10 @@ END:VCALENDAR";
|
|||||||
comp_filter: vec![],
|
comp_filter: vec![],
|
||||||
}],
|
}],
|
||||||
};
|
};
|
||||||
assert!(object.matches(&comp_filter), "filter matches VEVENT");
|
assert!(
|
||||||
|
object.get_inner().matches(&comp_filter),
|
||||||
|
"filter matches VEVENT"
|
||||||
|
);
|
||||||
|
|
||||||
let comp_filter = CompFilterElement {
|
let comp_filter = CompFilterElement {
|
||||||
is_not_defined: None,
|
is_not_defined: None,
|
||||||
@@ -252,13 +225,13 @@ END:VCALENDAR";
|
|||||||
}],
|
}],
|
||||||
};
|
};
|
||||||
assert!(
|
assert!(
|
||||||
object.matches(&comp_filter),
|
object.get_inner().matches(&comp_filter),
|
||||||
"Some prop filters on VCALENDAR and VEVENT"
|
"Some prop filters on VCALENDAR and VEVENT"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn test_comp_filter_time_range() {
|
fn test_comp_filter_time_range() {
|
||||||
let object = CalendarObject::from_ics(ICS.to_string(), None).unwrap();
|
let object = CalendarObject::from_ics(ICS.to_string()).unwrap();
|
||||||
|
|
||||||
let comp_filter = CompFilterElement {
|
let comp_filter = CompFilterElement {
|
||||||
is_not_defined: None,
|
is_not_defined: None,
|
||||||
@@ -281,7 +254,7 @@ END:VCALENDAR";
|
|||||||
}],
|
}],
|
||||||
};
|
};
|
||||||
assert!(
|
assert!(
|
||||||
object.matches(&comp_filter),
|
object.get_inner().matches(&comp_filter),
|
||||||
"event should lie in time range"
|
"event should lie in time range"
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -306,14 +279,14 @@ END:VCALENDAR";
|
|||||||
}],
|
}],
|
||||||
};
|
};
|
||||||
assert!(
|
assert!(
|
||||||
!object.matches(&comp_filter),
|
!object.get_inner().matches(&comp_filter),
|
||||||
"event should not lie in time range"
|
"event should not lie in time range"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_match_timezone() {
|
fn test_match_timezone() {
|
||||||
let object = CalendarObject::from_ics(ICS.to_string(), None).unwrap();
|
let object = CalendarObject::from_ics(ICS.to_string()).unwrap();
|
||||||
|
|
||||||
let comp_filter = CompFilterElement {
|
let comp_filter = CompFilterElement {
|
||||||
is_not_defined: None,
|
is_not_defined: None,
|
||||||
@@ -340,7 +313,7 @@ END:VCALENDAR";
|
|||||||
}],
|
}],
|
||||||
};
|
};
|
||||||
assert!(
|
assert!(
|
||||||
object.matches(&comp_filter),
|
object.get_inner().matches(&comp_filter),
|
||||||
"Timezone should be Europe/Berlin"
|
"Timezone should be Europe/Berlin"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
use super::comp_filter::{CompFilterElement, CompFilterable};
|
use super::comp_filter::{CompFilterElement, CompFilterable};
|
||||||
use crate::calendar_object::CalendarObjectPropWrapperName;
|
use crate::calendar_object::CalendarObjectPropWrapperName;
|
||||||
use ical::property::Property;
|
use ical::{component::IcalCalendarObject, property::ContentLine};
|
||||||
use rustical_dav::xml::{PropfindType, TextMatchElement};
|
use rustical_dav::xml::{PropfindType, TextMatchElement};
|
||||||
use rustical_ical::{CalendarObject, UtcDateTime};
|
use rustical_ical::UtcDateTime;
|
||||||
use rustical_store::calendar_store::CalendarQuery;
|
use rustical_store::calendar_store::CalendarQuery;
|
||||||
use rustical_xml::{XmlDeserialize, XmlRootTag};
|
use rustical_xml::{XmlDeserialize, XmlRootTag};
|
||||||
|
|
||||||
@@ -30,8 +30,8 @@ pub struct ParamFilterElement {
|
|||||||
|
|
||||||
impl ParamFilterElement {
|
impl ParamFilterElement {
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn match_property(&self, prop: &Property) -> bool {
|
pub fn match_property(&self, prop: &ContentLine) -> bool {
|
||||||
let Some(param) = prop.get_param(&self.name) else {
|
let Some(param) = prop.params.get_param(&self.name) else {
|
||||||
return self.is_not_defined.is_some();
|
return self.is_not_defined.is_some();
|
||||||
};
|
};
|
||||||
if self.is_not_defined.is_some() {
|
if self.is_not_defined.is_some() {
|
||||||
@@ -57,7 +57,7 @@ pub struct FilterElement {
|
|||||||
|
|
||||||
impl FilterElement {
|
impl FilterElement {
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn matches(&self, cal_object: &CalendarObject) -> bool {
|
pub fn matches(&self, cal_object: &IcalCalendarObject) -> bool {
|
||||||
cal_object.matches(&self.comp_filter)
|
cal_object.matches(&self.comp_filter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,19 +11,19 @@ mod tests;
|
|||||||
pub use comp_filter::{CompFilterElement, CompFilterable};
|
pub use comp_filter::{CompFilterElement, CompFilterable};
|
||||||
pub use elements::*;
|
pub use elements::*;
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
pub use prop_filter::{PropFilterElement, PropFilterable};
|
pub use prop_filter::PropFilterElement;
|
||||||
|
|
||||||
pub async fn get_objects_calendar_query<C: CalendarStore>(
|
pub async fn get_objects_calendar_query<C: CalendarStore>(
|
||||||
cal_query: &CalendarQueryRequest,
|
cal_query: &CalendarQueryRequest,
|
||||||
principal: &str,
|
principal: &str,
|
||||||
cal_id: &str,
|
cal_id: &str,
|
||||||
store: &C,
|
store: &C,
|
||||||
) -> Result<Vec<CalendarObject>, Error> {
|
) -> Result<Vec<(String, CalendarObject)>, Error> {
|
||||||
let mut objects = store
|
let mut objects = store
|
||||||
.calendar_query(principal, cal_id, cal_query.into())
|
.calendar_query(principal, cal_id, cal_query.into())
|
||||||
.await?;
|
.await?;
|
||||||
if let Some(filter) = &cal_query.filter {
|
if let Some(filter) = &cal_query.filter {
|
||||||
objects.retain(|object| filter.matches(object));
|
objects.retain(|(_id, object)| filter.matches(object.get_inner()));
|
||||||
}
|
}
|
||||||
Ok(objects)
|
Ok(objects)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,8 @@
|
|||||||
use super::{ParamFilterElement, TimeRangeElement};
|
use super::{ParamFilterElement, TimeRangeElement};
|
||||||
use ical::{
|
use ical::{parser::Component, property::ContentLine, types::CalDateTime};
|
||||||
generator::{IcalCalendar, IcalEvent},
|
|
||||||
parser::{
|
|
||||||
Component,
|
|
||||||
ical::component::{IcalJournal, IcalTimeZone, IcalTodo},
|
|
||||||
},
|
|
||||||
property::Property,
|
|
||||||
};
|
|
||||||
use rustical_dav::xml::TextMatchElement;
|
use rustical_dav::xml::TextMatchElement;
|
||||||
use rustical_ical::{CalDateTime, CalendarObject, CalendarObjectComponent, UtcDateTime};
|
use rustical_ical::UtcDateTime;
|
||||||
use rustical_xml::XmlDeserialize;
|
use rustical_xml::XmlDeserialize;
|
||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
#[derive(XmlDeserialize, Clone, Debug, PartialEq, Eq)]
|
#[derive(XmlDeserialize, Clone, Debug, PartialEq, Eq)]
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
@@ -31,10 +23,10 @@ pub struct PropFilterElement {
|
|||||||
|
|
||||||
impl PropFilterElement {
|
impl PropFilterElement {
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn match_property(&self, property: &Property) -> bool {
|
pub fn match_property(&self, property: &ContentLine) -> bool {
|
||||||
if let Some(TimeRangeElement { start, end }) = &self.time_range {
|
if let Some(TimeRangeElement { start, end }) = &self.time_range {
|
||||||
// TODO: Respect timezones
|
// TODO: Respect timezones
|
||||||
let Ok(timestamp) = CalDateTime::parse_prop(property, &HashMap::default()) else {
|
let Ok(timestamp) = CalDateTime::parse_prop(property, None) else {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
let timestamp = timestamp.utc();
|
let timestamp = timestamp.utc();
|
||||||
@@ -68,64 +60,14 @@ impl PropFilterElement {
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn match_component(&self, comp: &impl PropFilterable) -> bool {
|
pub fn match_component(&self, comp: &impl Component) -> bool {
|
||||||
let properties = comp.get_named_properties(&self.name);
|
let mut properties = comp.get_named_properties(&self.name);
|
||||||
if self.is_not_defined.is_some() {
|
if self.is_not_defined.is_some() {
|
||||||
return properties.is_empty();
|
return properties.next().is_none();
|
||||||
}
|
}
|
||||||
|
|
||||||
// The filter matches when one property instance matches
|
// The filter matches when one property instance matches
|
||||||
// Example where this matters: We have multiple attendees and want to match one
|
// Example where this matters: We have multiple attendees and want to match one
|
||||||
properties.iter().any(|prop| self.match_property(prop))
|
properties.any(|prop| self.match_property(prop))
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait PropFilterable {
|
|
||||||
fn get_named_properties(&self, name: &str) -> Vec<&Property>;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PropFilterable for CalendarObject {
|
|
||||||
fn get_named_properties(&self, name: &str) -> Vec<&Property> {
|
|
||||||
Self::get_named_properties(self, name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PropFilterable for IcalEvent {
|
|
||||||
fn get_named_properties(&self, name: &str) -> Vec<&Property> {
|
|
||||||
Component::get_named_properties(self, name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PropFilterable for IcalTodo {
|
|
||||||
fn get_named_properties(&self, name: &str) -> Vec<&Property> {
|
|
||||||
Component::get_named_properties(self, name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PropFilterable for IcalJournal {
|
|
||||||
fn get_named_properties(&self, name: &str) -> Vec<&Property> {
|
|
||||||
Component::get_named_properties(self, name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PropFilterable for IcalCalendar {
|
|
||||||
fn get_named_properties(&self, name: &str) -> Vec<&Property> {
|
|
||||||
Component::get_named_properties(self, name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PropFilterable for IcalTimeZone {
|
|
||||||
fn get_named_properties(&self, name: &str) -> Vec<&Property> {
|
|
||||||
Component::get_named_properties(self, name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PropFilterable for CalendarObjectComponent {
|
|
||||||
fn get_named_properties(&self, name: &str) -> Vec<&Property> {
|
|
||||||
match self {
|
|
||||||
Self::Event(event, _) => PropFilterable::get_named_properties(&event.event, name),
|
|
||||||
Self::Todo(todo, _) => PropFilterable::get_named_properties(todo, name),
|
|
||||||
Self::Journal(journal, _) => PropFilterable::get_named_properties(journal, name),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ const FILTER_2: &str = r#"
|
|||||||
#[case(ICS_1, FILTER_1, true)]
|
#[case(ICS_1, FILTER_1, true)]
|
||||||
#[case(ICS_1, FILTER_2, false)]
|
#[case(ICS_1, FILTER_2, false)]
|
||||||
fn yeet(#[case] ics: &str, #[case] filter: &str, #[case] matches: bool) {
|
fn yeet(#[case] ics: &str, #[case] filter: &str, #[case] matches: bool) {
|
||||||
let obj = CalendarObject::from_ics(ics.to_owned(), None).unwrap();
|
let obj = CalendarObject::from_ics(ics.to_owned()).unwrap();
|
||||||
let filter = FilterElement::parse_str(filter).unwrap();
|
let filter = FilterElement::parse_str(filter).unwrap();
|
||||||
assert_eq!(matches, filter.matches(&obj));
|
assert_eq!(matches, filter.matches(obj.get_inner()));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ impl ReportRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn objects_response(
|
fn objects_response(
|
||||||
objects: Vec<CalendarObject>,
|
objects: Vec<(String, CalendarObject)>,
|
||||||
not_found: Vec<String>,
|
not_found: Vec<String>,
|
||||||
path: &str,
|
path: &str,
|
||||||
principal: &str,
|
principal: &str,
|
||||||
@@ -60,11 +60,12 @@ fn objects_response(
|
|||||||
prop: &PropfindType<CalendarObjectPropWrapperName>,
|
prop: &PropfindType<CalendarObjectPropWrapperName>,
|
||||||
) -> Result<MultistatusElement<CalendarObjectPropWrapper, String>, Error> {
|
) -> Result<MultistatusElement<CalendarObjectPropWrapper, String>, Error> {
|
||||||
let mut responses = Vec::new();
|
let mut responses = Vec::new();
|
||||||
for object in objects {
|
for (object_id, object) in objects {
|
||||||
let path = format!("{}/{}.ics", path, object.get_id());
|
let path = format!("{path}/{object_id}.ics");
|
||||||
responses.push(
|
responses.push(
|
||||||
CalendarObjectResource {
|
CalendarObjectResource {
|
||||||
object,
|
object,
|
||||||
|
object_id,
|
||||||
principal: principal.to_owned(),
|
principal: principal.to_owned(),
|
||||||
}
|
}
|
||||||
.propfind(&path, prop, None, puri, user)?,
|
.propfind(&path, prop, None, puri, user)?,
|
||||||
|
|||||||
@@ -32,11 +32,12 @@ pub async fn handle_sync_collection<C: CalendarStore>(
|
|||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let mut responses = Vec::new();
|
let mut responses = Vec::new();
|
||||||
for object in new_objects {
|
for (object_id, object) in new_objects {
|
||||||
let path = format!("{}/{}.ics", path, object.get_id());
|
let path = format!("{}/{}.ics", path, &object_id);
|
||||||
responses.push(
|
responses.push(
|
||||||
CalendarObjectResource {
|
CalendarObjectResource {
|
||||||
object,
|
object,
|
||||||
|
object_id,
|
||||||
principal: principal.to_owned(),
|
principal: principal.to_owned(),
|
||||||
}
|
}
|
||||||
.propfind(&path, &sync_collection.prop, None, puri, user)?,
|
.propfind(&path, &sync_collection.prop, None, puri, user)?,
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ use crate::calendar::prop::{ReportMethod, SupportedCollationSet};
|
|||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use derive_more::derive::{From, Into};
|
use derive_more::derive::{From, Into};
|
||||||
use ical::IcalParser;
|
use ical::IcalParser;
|
||||||
|
use ical::types::CalDateTime;
|
||||||
use rustical_dav::extensions::{
|
use rustical_dav::extensions::{
|
||||||
CommonPropertiesExtension, CommonPropertiesProp, SyncTokenExtension, SyncTokenExtensionProp,
|
CommonPropertiesExtension, CommonPropertiesProp, SyncTokenExtension, SyncTokenExtensionProp,
|
||||||
};
|
};
|
||||||
@@ -11,7 +12,6 @@ use rustical_dav::privileges::UserPrivilegeSet;
|
|||||||
use rustical_dav::resource::{PrincipalUri, Resource, ResourceName};
|
use rustical_dav::resource::{PrincipalUri, Resource, ResourceName};
|
||||||
use rustical_dav::xml::{HrefElement, Resourcetype, ResourcetypeInner, SupportedReportSet};
|
use rustical_dav::xml::{HrefElement, Resourcetype, ResourcetypeInner, SupportedReportSet};
|
||||||
use rustical_dav_push::{DavPushExtension, DavPushExtensionProp};
|
use rustical_dav_push::{DavPushExtension, DavPushExtensionProp};
|
||||||
use rustical_ical::CalDateTime;
|
|
||||||
use rustical_store::Calendar;
|
use rustical_store::Calendar;
|
||||||
use rustical_store::auth::Principal;
|
use rustical_store::auth::Principal;
|
||||||
use rustical_xml::{EnumVariants, PropName};
|
use rustical_xml::{EnumVariants, PropName};
|
||||||
@@ -215,13 +215,13 @@ impl Resource for CalendarResource {
|
|||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let timezone = calendar.timezones.first().ok_or_else(|| {
|
let timezone = calendar.vtimezones.values().next().ok_or_else(|| {
|
||||||
rustical_dav::Error::BadRequest("No timezone data provided".to_owned())
|
rustical_dav::Error::BadRequest("No timezone data provided".to_owned())
|
||||||
})?;
|
})?;
|
||||||
let timezone: chrono_tz::Tz = timezone.try_into().map_err(|_| {
|
let timezone: Option<chrono_tz::Tz> = timezone.into();
|
||||||
|
let timezone = timezone.ok_or_else(|| {
|
||||||
rustical_dav::Error::BadRequest("No timezone data provided".to_owned())
|
rustical_dav::Error::BadRequest("No timezone data provided".to_owned())
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
self.cal.timezone_id = Some(timezone.name().to_owned());
|
self.cal.timezone_id = Some(timezone.name().to_owned());
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -78,8 +78,9 @@ impl<C: CalendarStore, S: SubscriptionStore> ResourceService for CalendarResourc
|
|||||||
.get_objects(principal, cal_id)
|
.get_objects(principal, cal_id)
|
||||||
.await?
|
.await?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|object| CalendarObjectResource {
|
.map(|(object_id, object)| CalendarObjectResource {
|
||||||
object,
|
object,
|
||||||
|
object_id,
|
||||||
principal: principal.to_owned(),
|
principal: principal.to_owned(),
|
||||||
})
|
})
|
||||||
.collect())
|
.collect())
|
||||||
@@ -91,7 +92,7 @@ impl<C: CalendarStore, S: SubscriptionStore> ResourceService for CalendarResourc
|
|||||||
file: Self::Resource,
|
file: Self::Resource,
|
||||||
) -> Result<(), Self::Error> {
|
) -> Result<(), Self::Error> {
|
||||||
self.cal_store
|
self.cal_store
|
||||||
.update_calendar(principal.to_owned(), cal_id.to_owned(), file.into())
|
.update_calendar(principal, cal_id, file.into())
|
||||||
.await?;
|
.await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,13 +94,13 @@ pub async fn put_event<C: CalendarStore>(
|
|||||||
true
|
true
|
||||||
};
|
};
|
||||||
|
|
||||||
let Ok(object) = CalendarObject::from_ics(body.clone(), Some(object_id)) else {
|
let Ok(object) = CalendarObject::from_ics(body.clone()) else {
|
||||||
debug!("invalid calendar data:\n{body}");
|
debug!("invalid calendar data:\n{body}");
|
||||||
return Err(Error::PreconditionFailed(Precondition::ValidCalendarData));
|
return Err(Error::PreconditionFailed(Precondition::ValidCalendarData));
|
||||||
};
|
};
|
||||||
let etag = object.get_etag();
|
let etag = object.get_etag();
|
||||||
cal_store
|
cal_store
|
||||||
.put_object(principal, calendar_id, object, overwrite)
|
.put_object(&principal, &calendar_id, &object_id, object, overwrite)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let mut headers = HeaderMap::new();
|
let mut headers = HeaderMap::new();
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
use std::borrow::Cow;
|
|
||||||
|
|
||||||
use super::prop::{
|
use super::prop::{
|
||||||
CalendarData, CalendarObjectProp, CalendarObjectPropName, CalendarObjectPropWrapper,
|
CalendarData, CalendarObjectProp, CalendarObjectPropName, CalendarObjectPropWrapper,
|
||||||
CalendarObjectPropWrapperName,
|
CalendarObjectPropWrapperName,
|
||||||
};
|
};
|
||||||
use crate::Error;
|
use crate::Error;
|
||||||
use derive_more::derive::{From, Into};
|
use derive_more::derive::{From, Into};
|
||||||
|
use ical::generator::Emitter;
|
||||||
use rustical_dav::{
|
use rustical_dav::{
|
||||||
extensions::CommonPropertiesExtension,
|
extensions::CommonPropertiesExtension,
|
||||||
privileges::UserPrivilegeSet,
|
privileges::UserPrivilegeSet,
|
||||||
@@ -14,16 +13,18 @@ use rustical_dav::{
|
|||||||
};
|
};
|
||||||
use rustical_ical::CalendarObject;
|
use rustical_ical::CalendarObject;
|
||||||
use rustical_store::auth::Principal;
|
use rustical_store::auth::Principal;
|
||||||
|
use std::borrow::Cow;
|
||||||
|
|
||||||
#[derive(Clone, From, Into)]
|
#[derive(Clone, From, Into)]
|
||||||
pub struct CalendarObjectResource {
|
pub struct CalendarObjectResource {
|
||||||
pub object: CalendarObject,
|
pub object: CalendarObject,
|
||||||
|
pub object_id: String,
|
||||||
pub principal: String,
|
pub principal: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ResourceName for CalendarObjectResource {
|
impl ResourceName for CalendarObjectResource {
|
||||||
fn get_name(&self) -> Cow<'_, str> {
|
fn get_name(&self) -> Cow<'_, str> {
|
||||||
Cow::from(format!("{}.ics", self.object.get_id()))
|
Cow::from(format!("{}.ics", self.object_id))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,14 +54,18 @@ impl Resource for CalendarObjectResource {
|
|||||||
CalendarObjectProp::Getetag(self.object.get_etag())
|
CalendarObjectProp::Getetag(self.object.get_etag())
|
||||||
}
|
}
|
||||||
CalendarObjectPropName::CalendarData(CalendarData { expand, .. }) => {
|
CalendarObjectPropName::CalendarData(CalendarData { expand, .. }) => {
|
||||||
CalendarObjectProp::CalendarData(if let Some(expand) = expand.as_ref() {
|
CalendarObjectProp::CalendarData(expand.as_ref().map_or_else(
|
||||||
self.object.expand_recurrence(
|
|| self.object.get_ics().to_owned(),
|
||||||
Some(expand.start.to_utc()),
|
|expand| {
|
||||||
Some(expand.end.to_utc()),
|
self.object
|
||||||
)?
|
.get_inner()
|
||||||
} else {
|
.expand_recurrence(
|
||||||
self.object.get_ics().to_owned()
|
Some(expand.start.to_utc()),
|
||||||
})
|
Some(expand.end.to_utc()),
|
||||||
|
)
|
||||||
|
.generate()
|
||||||
|
},
|
||||||
|
))
|
||||||
}
|
}
|
||||||
CalendarObjectPropName::Getcontenttype => {
|
CalendarObjectPropName::Getcontenttype => {
|
||||||
CalendarObjectProp::Getcontenttype("text/calendar;charset=utf-8")
|
CalendarObjectProp::Getcontenttype("text/calendar;charset=utf-8")
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ impl<C: CalendarStore> ResourceService for CalendarObjectResourceService<C> {
|
|||||||
.await?;
|
.await?;
|
||||||
Ok(CalendarObjectResource {
|
Ok(CalendarObjectResource {
|
||||||
object,
|
object,
|
||||||
|
object_id: object_id.to_owned(),
|
||||||
principal: principal.to_owned(),
|
principal: principal.to_owned(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -103,10 +103,10 @@ pub async fn put_object<AS: AddressbookStore>(
|
|||||||
true
|
true
|
||||||
};
|
};
|
||||||
|
|
||||||
let object = AddressObject::from_vcf(object_id, body)?;
|
let object = AddressObject::from_vcf(body)?;
|
||||||
let etag = object.get_etag();
|
let etag = object.get_etag();
|
||||||
addr_store
|
addr_store
|
||||||
.put_object(principal, addressbook_id, object, overwrite)
|
.put_object(&principal, &addressbook_id, &object_id, object, overwrite)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let mut headers = HeaderMap::new();
|
let mut headers = HeaderMap::new();
|
||||||
|
|||||||
@@ -21,11 +21,12 @@ use rustical_store::auth::Principal;
|
|||||||
pub struct AddressObjectResource {
|
pub struct AddressObjectResource {
|
||||||
pub object: AddressObject,
|
pub object: AddressObject,
|
||||||
pub principal: String,
|
pub principal: String,
|
||||||
|
pub object_id: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ResourceName for AddressObjectResource {
|
impl ResourceName for AddressObjectResource {
|
||||||
fn get_name(&self) -> Cow<'_, str> {
|
fn get_name(&self) -> Cow<'_, str> {
|
||||||
Cow::from(format!("{}.vcf", self.object.get_id()))
|
Cow::from(format!("{}.vcf", self.object_id))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,7 +70,8 @@ impl Resource for AddressObjectResource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_displayname(&self) -> Option<&str> {
|
fn get_displayname(&self) -> Option<&str> {
|
||||||
self.object.get_full_name()
|
todo!()
|
||||||
|
// self.object.get_full_name()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_owner(&self) -> Option<&str> {
|
fn get_owner(&self) -> Option<&str> {
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ impl<AS: AddressbookStore> ResourceService for AddressObjectResourceService<AS>
|
|||||||
.await?;
|
.await?;
|
||||||
Ok(AddressObjectResource {
|
Ok(AddressObjectResource {
|
||||||
object,
|
object,
|
||||||
|
object_id: object_id.to_owned(),
|
||||||
principal: principal.to_owned(),
|
principal: principal.to_owned(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ use http::{HeaderValue, Method, StatusCode, header};
|
|||||||
use percent_encoding::{CONTROLS, utf8_percent_encode};
|
use percent_encoding::{CONTROLS, utf8_percent_encode};
|
||||||
use rustical_dav::privileges::UserPrivilege;
|
use rustical_dav::privileges::UserPrivilege;
|
||||||
use rustical_dav::resource::Resource;
|
use rustical_dav::resource::Resource;
|
||||||
use rustical_ical::AddressObject;
|
|
||||||
use rustical_store::auth::Principal;
|
use rustical_store::auth::Principal;
|
||||||
use rustical_store::{AddressbookStore, SubscriptionStore};
|
use rustical_store::{AddressbookStore, SubscriptionStore};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
@@ -40,7 +39,7 @@ pub async fn route_get<AS: AddressbookStore, S: SubscriptionStore>(
|
|||||||
let objects = addr_store.get_objects(&principal, &addressbook_id).await?;
|
let objects = addr_store.get_objects(&principal, &addressbook_id).await?;
|
||||||
let vcf = objects
|
let vcf = objects
|
||||||
.iter()
|
.iter()
|
||||||
.map(AddressObject::get_vcf)
|
.map(|(_id, obj)| obj.get_vcf())
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.join("\r\n");
|
.join("\r\n");
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
use std::io::BufReader;
|
|
||||||
|
|
||||||
use crate::Error;
|
use crate::Error;
|
||||||
use crate::addressbook::AddressbookResourceService;
|
use crate::addressbook::AddressbookResourceService;
|
||||||
use axum::{
|
use axum::{
|
||||||
@@ -9,9 +7,10 @@ use axum::{
|
|||||||
use http::StatusCode;
|
use http::StatusCode;
|
||||||
use ical::{
|
use ical::{
|
||||||
parser::{Component, ComponentMut, vcard},
|
parser::{Component, ComponentMut, vcard},
|
||||||
property::Property,
|
property::ContentLine,
|
||||||
};
|
};
|
||||||
use rustical_store::{Addressbook, AddressbookStore, SubscriptionStore, auth::Principal};
|
use rustical_store::{Addressbook, AddressbookStore, SubscriptionStore, auth::Principal};
|
||||||
|
use std::io::BufReader;
|
||||||
use tracing::instrument;
|
use tracing::instrument;
|
||||||
|
|
||||||
#[instrument(skip(resource_service))]
|
#[instrument(skip(resource_service))]
|
||||||
@@ -33,15 +32,16 @@ pub async fn route_import<AS: AddressbookStore, S: SubscriptionStore>(
|
|||||||
let uid = card.get_uid();
|
let uid = card.get_uid();
|
||||||
if uid.is_none() {
|
if uid.is_none() {
|
||||||
let mut card_mut = card.mutable();
|
let mut card_mut = card.mutable();
|
||||||
card_mut.set_property(Property {
|
card_mut.add_content_line(ContentLine {
|
||||||
name: "UID".to_owned(),
|
name: "UID".to_owned(),
|
||||||
value: Some(uuid::Uuid::new_v4().to_string()),
|
value: Some(uuid::Uuid::new_v4().to_string()),
|
||||||
params: vec![],
|
params: vec![].into(),
|
||||||
});
|
});
|
||||||
card = card_mut.verify().unwrap();
|
card = card_mut.build(None).unwrap();
|
||||||
}
|
}
|
||||||
|
// TODO: Make nicer
|
||||||
objects.push(card.try_into().unwrap());
|
let uid = card.get_uid().unwrap();
|
||||||
|
objects.push((uid.to_owned(), card.into()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if objects.is_empty() {
|
if objects.is_empty() {
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ pub async fn get_objects_addressbook_multiget<AS: AddressbookStore>(
|
|||||||
principal: &str,
|
principal: &str,
|
||||||
addressbook_id: &str,
|
addressbook_id: &str,
|
||||||
store: &AS,
|
store: &AS,
|
||||||
) -> Result<(Vec<AddressObject>, Vec<String>), Error> {
|
) -> Result<(Vec<(String, AddressObject)>, Vec<String>), Error> {
|
||||||
let mut result = vec![];
|
let mut result = vec![];
|
||||||
let mut not_found = vec![];
|
let mut not_found = vec![];
|
||||||
|
|
||||||
@@ -43,7 +43,7 @@ pub async fn get_objects_addressbook_multiget<AS: AddressbookStore>(
|
|||||||
.get_object(principal, addressbook_id, object_id, false)
|
.get_object(principal, addressbook_id, object_id, false)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(object) => result.push(object),
|
Ok(object) => result.push((object_id.to_owned(), object)),
|
||||||
Err(rustical_store::Error::NotFound) => not_found.push(href.to_string()),
|
Err(rustical_store::Error::NotFound) => not_found.push(href.to_string()),
|
||||||
Err(err) => return Err(err.into()),
|
Err(err) => return Err(err.into()),
|
||||||
}
|
}
|
||||||
@@ -74,11 +74,12 @@ pub async fn handle_addressbook_multiget<AS: AddressbookStore>(
|
|||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let mut responses = Vec::new();
|
let mut responses = Vec::new();
|
||||||
for object in objects {
|
for (object_id, object) in objects {
|
||||||
let path = format!("{}/{}.vcf", path, object.get_id());
|
let path = format!("{path}/{object_id}.vcf");
|
||||||
responses.push(
|
responses.push(
|
||||||
AddressObjectResource {
|
AddressObjectResource {
|
||||||
object,
|
object,
|
||||||
|
object_id,
|
||||||
principal: principal.to_owned(),
|
principal: principal.to_owned(),
|
||||||
}
|
}
|
||||||
.propfind(&path, prop, None, puri, user)?,
|
.propfind(&path, prop, None, puri, user)?,
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use crate::{
|
|||||||
addressbook::methods::report::addressbook_query::PropFilterElement,
|
addressbook::methods::report::addressbook_query::PropFilterElement,
|
||||||
};
|
};
|
||||||
use derive_more::{From, Into};
|
use derive_more::{From, Into};
|
||||||
use ical::property::Property;
|
use ical::property::ContentLine;
|
||||||
use rustical_dav::xml::{PropfindType, TextMatchElement};
|
use rustical_dav::xml::{PropfindType, TextMatchElement};
|
||||||
use rustical_ical::{AddressObject, UtcDateTime};
|
use rustical_ical::{AddressObject, UtcDateTime};
|
||||||
use rustical_xml::{ValueDeserialize, XmlDeserialize, XmlRootTag};
|
use rustical_xml::{ValueDeserialize, XmlDeserialize, XmlRootTag};
|
||||||
@@ -32,8 +32,8 @@ pub struct ParamFilterElement {
|
|||||||
|
|
||||||
impl ParamFilterElement {
|
impl ParamFilterElement {
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn match_property(&self, prop: &Property) -> bool {
|
pub fn match_property(&self, prop: &ContentLine) -> bool {
|
||||||
let Some(param) = prop.get_param(&self.name) else {
|
let Some(param) = prop.params.get_param(&self.name) else {
|
||||||
return self.is_not_defined.is_some();
|
return self.is_not_defined.is_some();
|
||||||
};
|
};
|
||||||
if self.is_not_defined.is_some() {
|
if self.is_not_defined.is_some() {
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ pub async fn get_objects_addressbook_query<AS: AddressbookStore>(
|
|||||||
principal: &str,
|
principal: &str,
|
||||||
addressbook_id: &str,
|
addressbook_id: &str,
|
||||||
store: &AS,
|
store: &AS,
|
||||||
) -> Result<Vec<AddressObject>, Error> {
|
) -> Result<Vec<(String, AddressObject)>, Error> {
|
||||||
let mut objects = store.get_objects(principal, addressbook_id).await?;
|
let mut objects = store.get_objects(principal, addressbook_id).await?;
|
||||||
objects.retain(|object| addr_query.filter.matches(object));
|
objects.retain(|(_id, object)| addr_query.filter.matches(object));
|
||||||
Ok(objects)
|
Ok(objects)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use super::{Allof, ParamFilterElement};
|
use super::{Allof, ParamFilterElement};
|
||||||
use ical::{parser::Component, property::Property};
|
use ical::{parser::Component, property::ContentLine};
|
||||||
use rustical_dav::xml::TextMatchElement;
|
use rustical_dav::xml::TextMatchElement;
|
||||||
use rustical_ical::AddressObject;
|
use rustical_ical::AddressObject;
|
||||||
use rustical_xml::XmlDeserialize;
|
use rustical_xml::XmlDeserialize;
|
||||||
@@ -31,7 +31,7 @@ pub struct PropFilterElement {
|
|||||||
|
|
||||||
impl PropFilterElement {
|
impl PropFilterElement {
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn match_property(&self, property: &Property) -> bool {
|
pub fn match_property(&self, property: &ContentLine) -> bool {
|
||||||
if self.param_filter.is_empty() && self.text_match.is_empty() {
|
if self.param_filter.is_empty() && self.text_match.is_empty() {
|
||||||
// Filter empty
|
// Filter empty
|
||||||
return true;
|
return true;
|
||||||
@@ -56,22 +56,22 @@ impl PropFilterElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn match_component(&self, comp: &impl PropFilterable) -> bool {
|
pub fn match_component(&self, comp: &impl PropFilterable) -> bool {
|
||||||
let properties = comp.get_named_properties(&self.name);
|
let mut properties = comp.get_named_properties(&self.name);
|
||||||
if self.is_not_defined.is_some() {
|
if self.is_not_defined.is_some() {
|
||||||
return properties.is_empty();
|
return properties.next().is_none();
|
||||||
}
|
}
|
||||||
|
|
||||||
// The filter matches when one property instance matches
|
// The filter matches when one property instance matches
|
||||||
properties.iter().any(|prop| self.match_property(prop))
|
properties.any(|prop| self.match_property(prop))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait PropFilterable {
|
pub trait PropFilterable {
|
||||||
fn get_named_properties(&self, name: &str) -> Vec<&Property>;
|
fn get_named_properties<'a>(&'a self, name: &'a str) -> impl Iterator<Item = &'a ContentLine>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PropFilterable for AddressObject {
|
impl PropFilterable for AddressObject {
|
||||||
fn get_named_properties(&self, name: &str) -> Vec<&Property> {
|
fn get_named_properties<'a>(&'a self, name: &'a str) -> impl Iterator<Item = &'a ContentLine> {
|
||||||
self.get_vcard().get_named_properties(name)
|
self.get_vcard().get_named_properties(name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ const FILTER_2: &str = r#"
|
|||||||
#[case(VCF_2, FILTER_2, true)]
|
#[case(VCF_2, FILTER_2, true)]
|
||||||
fn test_filter(#[case] vcf: &str, #[case] filter: &str, #[case] matches: bool) {
|
fn test_filter(#[case] vcf: &str, #[case] filter: &str, #[case] matches: bool) {
|
||||||
dbg!(vcf);
|
dbg!(vcf);
|
||||||
let obj = AddressObject::from_vcf(String::new(), vcf.to_owned()).unwrap();
|
let obj = AddressObject::from_vcf(vcf.to_owned()).unwrap();
|
||||||
let filter = FilterElement::parse_str(filter).unwrap();
|
let filter = FilterElement::parse_str(filter).unwrap();
|
||||||
assert_eq!(matches, filter.matches(&obj));
|
assert_eq!(matches, filter.matches(&obj));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ impl ReportRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn objects_response(
|
fn objects_response(
|
||||||
objects: Vec<AddressObject>,
|
objects: Vec<(String, AddressObject)>,
|
||||||
not_found: Vec<String>,
|
not_found: Vec<String>,
|
||||||
path: &str,
|
path: &str,
|
||||||
principal: &str,
|
principal: &str,
|
||||||
@@ -64,11 +64,12 @@ fn objects_response(
|
|||||||
prop: &PropfindType<AddressObjectPropWrapperName>,
|
prop: &PropfindType<AddressObjectPropWrapperName>,
|
||||||
) -> Result<MultistatusElement<AddressObjectPropWrapper, String>, Error> {
|
) -> Result<MultistatusElement<AddressObjectPropWrapper, String>, Error> {
|
||||||
let mut responses = Vec::new();
|
let mut responses = Vec::new();
|
||||||
for object in objects {
|
for (object_id, object) in objects {
|
||||||
let path = format!("{}/{}.vcf", path, object.get_id());
|
let path = format!("{}/{}.vcf", path, &object_id);
|
||||||
responses.push(
|
responses.push(
|
||||||
AddressObjectResource {
|
AddressObjectResource {
|
||||||
object,
|
object,
|
||||||
|
object_id,
|
||||||
principal: principal.to_owned(),
|
principal: principal.to_owned(),
|
||||||
}
|
}
|
||||||
.propfind(&path, prop, None, puri, user)?,
|
.propfind(&path, prop, None, puri, user)?,
|
||||||
|
|||||||
@@ -32,11 +32,12 @@ pub async fn handle_sync_collection<AS: AddressbookStore>(
|
|||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let mut responses = Vec::new();
|
let mut responses = Vec::new();
|
||||||
for object in new_objects {
|
for (object_id, object) in new_objects {
|
||||||
let path = format!("{}/{}.vcf", path.trim_end_matches('/'), object.get_id());
|
let path = format!("{}/{}.vcf", path.trim_end_matches('/'), object_id);
|
||||||
responses.push(
|
responses.push(
|
||||||
AddressObjectResource {
|
AddressObjectResource {
|
||||||
object,
|
object,
|
||||||
|
object_id,
|
||||||
principal: principal.to_owned(),
|
principal: principal.to_owned(),
|
||||||
}
|
}
|
||||||
.propfind(&path, &sync_collection.prop, None, puri, user)?,
|
.propfind(&path, &sync_collection.prop, None, puri, user)?,
|
||||||
|
|||||||
@@ -78,7 +78,8 @@ impl<AS: AddressbookStore, S: SubscriptionStore> ResourceService
|
|||||||
.get_objects(principal, addressbook_id)
|
.get_objects(principal, addressbook_id)
|
||||||
.await?
|
.await?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|object| AddressObjectResource {
|
.map(|(object_id, object)| AddressObjectResource {
|
||||||
|
object_id,
|
||||||
object,
|
object,
|
||||||
principal: principal.to_owned(),
|
principal: principal.to_owned(),
|
||||||
})
|
})
|
||||||
@@ -91,7 +92,7 @@ impl<AS: AddressbookStore, S: SubscriptionStore> ResourceService
|
|||||||
file: Self::Resource,
|
file: Self::Resource,
|
||||||
) -> Result<(), Self::Error> {
|
) -> Result<(), Self::Error> {
|
||||||
self.addr_store
|
self.addr_store
|
||||||
.update_addressbook(principal.to_owned(), addressbook_id.to_owned(), file.into())
|
.update_addressbook(principal, addressbook_id, file.into())
|
||||||
.await?;
|
.await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use ical::property::Property;
|
use ical::property::ContentLine;
|
||||||
use rustical_xml::{ValueDeserialize, XmlDeserialize};
|
use rustical_xml::{ValueDeserialize, XmlDeserialize};
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
@@ -128,7 +128,7 @@ impl TextMatchElement {
|
|||||||
negate_condition.0 ^ matches
|
negate_condition.0 ^ matches
|
||||||
}
|
}
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn match_property(&self, property: &Property) -> bool {
|
pub fn match_property(&self, property: &ContentLine) -> bool {
|
||||||
let text = property.value.as_deref().unwrap_or("");
|
let text = property.value.as_deref().unwrap_or("");
|
||||||
self.match_text(text)
|
self.match_text(text)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,59 +1,32 @@
|
|||||||
use crate::{CalDateTime, LOCAL_DATE};
|
|
||||||
use crate::{CalendarObject, Error};
|
use crate::{CalendarObject, Error};
|
||||||
use chrono::Datelike;
|
|
||||||
use ical::generator::Emitter;
|
use ical::generator::Emitter;
|
||||||
use ical::parser::{
|
use ical::parser::vcard::{self, component::VcardContact};
|
||||||
Component,
|
|
||||||
vcard::{self, component::VcardContact},
|
|
||||||
};
|
|
||||||
use sha2::{Digest, Sha256};
|
use sha2::{Digest, Sha256};
|
||||||
use std::{collections::HashMap, io::BufReader};
|
use std::{collections::HashMap, io::BufReader};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct AddressObject {
|
pub struct AddressObject {
|
||||||
id: String,
|
|
||||||
vcf: String,
|
vcf: String,
|
||||||
vcard: VcardContact,
|
vcard: VcardContact,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<VcardContact> for AddressObject {
|
impl From<VcardContact> for AddressObject {
|
||||||
type Error = Error;
|
fn from(vcard: VcardContact) -> Self {
|
||||||
|
|
||||||
fn try_from(vcard: VcardContact) -> Result<Self, Self::Error> {
|
|
||||||
let uid = vcard
|
|
||||||
.get_uid()
|
|
||||||
.ok_or_else(|| Error::InvalidData("missing UID".to_owned()))?
|
|
||||||
.to_owned();
|
|
||||||
let vcf = vcard.generate();
|
let vcf = vcard.generate();
|
||||||
Ok(Self {
|
Self { vcf, vcard }
|
||||||
vcf,
|
|
||||||
vcard,
|
|
||||||
id: uid,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AddressObject {
|
impl AddressObject {
|
||||||
pub fn from_vcf(id: String, vcf: String) -> Result<Self, Error> {
|
pub fn from_vcf(vcf: String) -> Result<Self, Error> {
|
||||||
let mut parser = vcard::VcardParser::new(BufReader::new(vcf.as_bytes()));
|
let parser = vcard::VcardParser::new(BufReader::new(vcf.as_bytes()));
|
||||||
let vcard = parser.next().ok_or(Error::MissingContact)??;
|
let vcard = parser.expect_one()?;
|
||||||
if parser.next().is_some() {
|
Ok(Self { vcf, vcard })
|
||||||
return Err(Error::InvalidData(
|
|
||||||
"multiple vcards, only one allowed".to_owned(),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
Ok(Self { id, vcf, vcard })
|
|
||||||
}
|
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub fn get_id(&self) -> &str {
|
|
||||||
&self.id
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn get_etag(&self) -> String {
|
pub fn get_etag(&self) -> String {
|
||||||
let mut hasher = Sha256::new();
|
let mut hasher = Sha256::new();
|
||||||
hasher.update(self.get_id());
|
|
||||||
hasher.update(self.get_vcf());
|
hasher.update(self.get_vcf());
|
||||||
format!("\"{:x}\"", hasher.finalize())
|
format!("\"{:x}\"", hasher.finalize())
|
||||||
}
|
}
|
||||||
@@ -63,109 +36,12 @@ impl AddressObject {
|
|||||||
&self.vcf
|
&self.vcf
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub fn get_anniversary(&self) -> Option<(CalDateTime, bool)> {
|
|
||||||
let prop = self.vcard.get_property("ANNIVERSARY")?.value.as_deref()?;
|
|
||||||
CalDateTime::parse_vcard(prop).ok()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub fn get_birthday(&self) -> Option<(CalDateTime, bool)> {
|
|
||||||
let prop = self.vcard.get_property("BDAY")?.value.as_deref()?;
|
|
||||||
CalDateTime::parse_vcard(prop).ok()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub fn get_full_name(&self) -> Option<&str> {
|
|
||||||
let prop = self.vcard.get_property("FN")?;
|
|
||||||
prop.value.as_deref()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_anniversary_object(&self) -> Result<Option<CalendarObject>, Error> {
|
pub fn get_anniversary_object(&self) -> Result<Option<CalendarObject>, Error> {
|
||||||
Ok(
|
todo!();
|
||||||
if let Some((anniversary, contains_year)) = self.get_anniversary() {
|
|
||||||
let Some(fullname) = self.get_full_name() else {
|
|
||||||
return Ok(None);
|
|
||||||
};
|
|
||||||
let anniversary = anniversary.date();
|
|
||||||
let year = contains_year.then_some(anniversary.year());
|
|
||||||
let anniversary_start = anniversary.format(LOCAL_DATE);
|
|
||||||
let anniversary_end = anniversary
|
|
||||||
.succ_opt()
|
|
||||||
.unwrap_or(anniversary)
|
|
||||||
.format(LOCAL_DATE);
|
|
||||||
let uid = format!("{}-anniversary", self.get_id());
|
|
||||||
|
|
||||||
let year_suffix = year.map(|year| format!(" ({year})")).unwrap_or_default();
|
|
||||||
Some(CalendarObject::from_ics(
|
|
||||||
format!(
|
|
||||||
r"BEGIN:VCALENDAR
|
|
||||||
VERSION:2.0
|
|
||||||
CALSCALE:GREGORIAN
|
|
||||||
PRODID:-//github.com/lennart-k/rustical birthday calendar//EN
|
|
||||||
BEGIN:VEVENT
|
|
||||||
DTSTART;VALUE=DATE:{anniversary_start}
|
|
||||||
DTEND;VALUE=DATE:{anniversary_end}
|
|
||||||
UID:{uid}
|
|
||||||
RRULE:FREQ=YEARLY
|
|
||||||
SUMMARY:💍 {fullname}{year_suffix}
|
|
||||||
TRANSP:TRANSPARENT
|
|
||||||
BEGIN:VALARM
|
|
||||||
TRIGGER;VALUE=DURATION:-PT0M
|
|
||||||
ACTION:DISPLAY
|
|
||||||
DESCRIPTION:💍 {fullname}{year_suffix}
|
|
||||||
END:VALARM
|
|
||||||
END:VEVENT
|
|
||||||
END:VCALENDAR",
|
|
||||||
),
|
|
||||||
None,
|
|
||||||
)?)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_birthday_object(&self) -> Result<Option<CalendarObject>, Error> {
|
pub fn get_birthday_object(&self) -> Result<Option<CalendarObject>, Error> {
|
||||||
Ok(
|
todo!();
|
||||||
if let Some((birthday, contains_year)) = self.get_birthday() {
|
|
||||||
let Some(fullname) = self.get_full_name() else {
|
|
||||||
return Ok(None);
|
|
||||||
};
|
|
||||||
let birthday = birthday.date();
|
|
||||||
let year = contains_year.then_some(birthday.year());
|
|
||||||
let birthday_start = birthday.format(LOCAL_DATE);
|
|
||||||
let birthday_end = birthday.succ_opt().unwrap_or(birthday).format(LOCAL_DATE);
|
|
||||||
let uid = format!("{}-birthday", self.get_id());
|
|
||||||
|
|
||||||
let year_suffix = year.map(|year| format!(" ({year})")).unwrap_or_default();
|
|
||||||
Some(CalendarObject::from_ics(
|
|
||||||
format!(
|
|
||||||
r"BEGIN:VCALENDAR
|
|
||||||
VERSION:2.0
|
|
||||||
CALSCALE:GREGORIAN
|
|
||||||
PRODID:-//github.com/lennart-k/rustical birthday calendar//EN
|
|
||||||
BEGIN:VEVENT
|
|
||||||
DTSTART;VALUE=DATE:{birthday_start}
|
|
||||||
DTEND;VALUE=DATE:{birthday_end}
|
|
||||||
UID:{uid}
|
|
||||||
RRULE:FREQ=YEARLY
|
|
||||||
SUMMARY:🎂 {fullname}{year_suffix}
|
|
||||||
TRANSP:TRANSPARENT
|
|
||||||
BEGIN:VALARM
|
|
||||||
TRIGGER;VALUE=DURATION:-PT0M
|
|
||||||
ACTION:DISPLAY
|
|
||||||
DESCRIPTION:🎂 {fullname}{year_suffix}
|
|
||||||
END:VALARM
|
|
||||||
END:VEVENT
|
|
||||||
END:VCALENDAR",
|
|
||||||
),
|
|
||||||
None,
|
|
||||||
)?)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get significant dates associated with this address object
|
/// Get significant dates associated with this address object
|
||||||
|
|||||||
120
crates/ical/src/calendar_object.rs
Normal file
120
crates/ical/src/calendar_object.rs
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
use crate::Error;
|
||||||
|
use derive_more::Display;
|
||||||
|
use ical::component::CalendarInnerData;
|
||||||
|
use ical::component::IcalCalendarObject;
|
||||||
|
use ical::generator::Emitter;
|
||||||
|
use ical::parser::ComponentParser;
|
||||||
|
use serde::Deserialize;
|
||||||
|
use serde::Serialize;
|
||||||
|
use sha2::{Digest, Sha256};
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Display)]
|
||||||
|
// specified in https://datatracker.ietf.org/doc/html/rfc5545#section-3.6
|
||||||
|
pub enum CalendarObjectType {
|
||||||
|
#[serde(rename = "VEVENT")]
|
||||||
|
Event = 0,
|
||||||
|
#[serde(rename = "VTODO")]
|
||||||
|
Todo = 1,
|
||||||
|
#[serde(rename = "VJOURNAL")]
|
||||||
|
Journal = 2,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<&IcalCalendarObject> for CalendarObjectType {
|
||||||
|
fn from(value: &IcalCalendarObject) -> Self {
|
||||||
|
match value.get_inner() {
|
||||||
|
CalendarInnerData::Event(_, _) => Self::Event,
|
||||||
|
CalendarInnerData::Todo(_, _) => Self::Todo,
|
||||||
|
CalendarInnerData::Journal(_, _) => Self::Journal,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CalendarObjectType {
|
||||||
|
#[must_use]
|
||||||
|
pub const fn as_str(&self) -> &'static str {
|
||||||
|
match self {
|
||||||
|
Self::Event => "VEVENT",
|
||||||
|
Self::Todo => "VTODO",
|
||||||
|
Self::Journal => "VJOURNAL",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl rustical_xml::ValueSerialize for CalendarObjectType {
|
||||||
|
fn serialize(&self) -> String {
|
||||||
|
self.as_str().to_owned()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl rustical_xml::ValueDeserialize for CalendarObjectType {
|
||||||
|
fn deserialize(val: &str) -> std::result::Result<Self, rustical_xml::XmlError> {
|
||||||
|
match <String as rustical_xml::ValueDeserialize>::deserialize(val)?.as_str() {
|
||||||
|
"VEVENT" => Ok(Self::Event),
|
||||||
|
"VTODO" => Ok(Self::Todo),
|
||||||
|
"VJOURNAL" => Ok(Self::Journal),
|
||||||
|
_ => Err(rustical_xml::XmlError::InvalidValue(
|
||||||
|
rustical_xml::ParseValueError::Other(format!(
|
||||||
|
"Invalid value '{val}', must be VEVENT, VTODO, or VJOURNAL"
|
||||||
|
)),
|
||||||
|
)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct CalendarObject {
|
||||||
|
inner: IcalCalendarObject,
|
||||||
|
ics: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CalendarObject {
|
||||||
|
pub fn from_ics(ics: String) -> Result<Self, Error> {
|
||||||
|
let parser: ComponentParser<_, IcalCalendarObject> = ComponentParser::new(ics.as_bytes());
|
||||||
|
let inner = parser.expect_one()?;
|
||||||
|
|
||||||
|
Ok(Self { inner, ics })
|
||||||
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
|
pub const fn get_inner(&self) -> &IcalCalendarObject {
|
||||||
|
&self.inner
|
||||||
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
|
pub fn get_uid(&self) -> &str {
|
||||||
|
self.inner.get_uid()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
|
pub fn get_etag(&self) -> String {
|
||||||
|
let mut hasher = Sha256::new();
|
||||||
|
hasher.update(self.get_uid());
|
||||||
|
hasher.update(self.get_ics());
|
||||||
|
format!("\"{:x}\"", hasher.finalize())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
|
pub fn get_ics(&self) -> &str {
|
||||||
|
&self.ics
|
||||||
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
|
pub fn get_object_type(&self) -> CalendarObjectType {
|
||||||
|
(&self.inner).into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<CalendarObject> for IcalCalendarObject {
|
||||||
|
fn from(value: CalendarObject) -> Self {
|
||||||
|
value.inner
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<IcalCalendarObject> for CalendarObject {
|
||||||
|
fn from(value: IcalCalendarObject) -> Self {
|
||||||
|
Self {
|
||||||
|
ics: value.generate(),
|
||||||
|
inner: value,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
use axum::{http::StatusCode, response::IntoResponse};
|
use axum::{http::StatusCode, response::IntoResponse};
|
||||||
|
|
||||||
use crate::CalDateTimeError;
|
|
||||||
|
|
||||||
#[derive(Debug, thiserror::Error, PartialEq, Eq)]
|
#[derive(Debug, thiserror::Error, PartialEq, Eq)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
#[error("Invalid ics/vcf input: {0}")]
|
#[error("Invalid ics/vcf input: {0}")]
|
||||||
@@ -15,12 +13,6 @@ pub enum Error {
|
|||||||
|
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
ParserError(#[from] ical::parser::ParserError),
|
ParserError(#[from] ical::parser::ParserError),
|
||||||
|
|
||||||
#[error(transparent)]
|
|
||||||
CalDateTimeError(#[from] CalDateTimeError),
|
|
||||||
|
|
||||||
#[error(transparent)]
|
|
||||||
RRuleError(#[from] rrule::RRuleError),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Error {
|
impl Error {
|
||||||
@@ -30,7 +22,7 @@ impl Error {
|
|||||||
Self::InvalidData(_) | Self::MissingCalendar | Self::MissingContact => {
|
Self::InvalidData(_) | Self::MissingCalendar | Self::MissingContact => {
|
||||||
StatusCode::BAD_REQUEST
|
StatusCode::BAD_REQUEST
|
||||||
}
|
}
|
||||||
_ => StatusCode::INTERNAL_SERVER_ERROR,
|
Self::ParserError(_) => StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,385 +0,0 @@
|
|||||||
use crate::CalDateTime;
|
|
||||||
use crate::Error;
|
|
||||||
use chrono::{DateTime, Duration, Utc};
|
|
||||||
use ical::parser::ComponentMut;
|
|
||||||
use ical::{generator::IcalEvent, parser::Component, property::Property};
|
|
||||||
use rrule::{RRule, RRuleSet};
|
|
||||||
use std::{collections::HashMap, str::FromStr};
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default)]
|
|
||||||
pub struct EventObject {
|
|
||||||
pub event: IcalEvent,
|
|
||||||
// If a timezone is None that means that in the VCALENDAR object there's a timezone defined
|
|
||||||
// with that name but its not from the Olson DB
|
|
||||||
pub timezones: HashMap<String, Option<chrono_tz::Tz>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl EventObject {
|
|
||||||
#[must_use]
|
|
||||||
pub fn get_uid(&self) -> &str {
|
|
||||||
self.event.get_uid()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_dtstart(&self) -> Result<Option<CalDateTime>, Error> {
|
|
||||||
if let Some(dtstart) = self.event.get_dtstart() {
|
|
||||||
Ok(Some(CalDateTime::parse_prop(dtstart, &self.timezones)?))
|
|
||||||
} else {
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_dtend(&self) -> Result<Option<CalDateTime>, Error> {
|
|
||||||
if let Some(dtend) = self.event.get_dtend() {
|
|
||||||
Ok(Some(CalDateTime::parse_prop(dtend, &self.timezones)?))
|
|
||||||
} else {
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_last_occurence(&self) -> Result<Option<CalDateTime>, Error> {
|
|
||||||
if self.event.get_rrule().is_some() {
|
|
||||||
// TODO: understand recurrence rules
|
|
||||||
return Ok(None);
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(dtend) = self.get_dtend()? {
|
|
||||||
return Ok(Some(dtend));
|
|
||||||
}
|
|
||||||
|
|
||||||
let duration = self.event.get_duration().unwrap_or(Duration::days(1));
|
|
||||||
|
|
||||||
let first_occurence = self.get_dtstart()?;
|
|
||||||
Ok(first_occurence.map(|first_occurence| first_occurence + duration))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn recurrence_ruleset(&self) -> Result<Option<rrule::RRuleSet>, Error> {
|
|
||||||
let dtstart: DateTime<rrule::Tz> = if let Some(dtstart) = self.get_dtstart()? {
|
|
||||||
if let Some(dtend) = self.get_dtend()? {
|
|
||||||
// DTSTART and DTEND MUST have the same timezone
|
|
||||||
assert_eq!(dtstart.timezone(), dtend.timezone());
|
|
||||||
}
|
|
||||||
|
|
||||||
dtstart
|
|
||||||
.as_datetime()
|
|
||||||
.with_timezone(&dtstart.timezone().into())
|
|
||||||
} else {
|
|
||||||
return Ok(None);
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut rrule_set = RRuleSet::new(dtstart);
|
|
||||||
// TODO: Make nice, this is just a bodge to get correct behaviour
|
|
||||||
let mut empty = true;
|
|
||||||
|
|
||||||
for prop in &self.event.properties {
|
|
||||||
rrule_set = match prop.name.as_str() {
|
|
||||||
"RRULE" => {
|
|
||||||
let rrule = RRule::from_str(prop.value.as_ref().ok_or_else(|| {
|
|
||||||
Error::RRuleError(rrule::ParseError::MissingDateGenerationRules.into())
|
|
||||||
})?)?
|
|
||||||
.validate(dtstart)
|
|
||||||
.unwrap();
|
|
||||||
empty = false;
|
|
||||||
rrule_set.rrule(rrule)
|
|
||||||
}
|
|
||||||
"RDATE" => {
|
|
||||||
let rdate = CalDateTime::parse_prop(prop, &self.timezones)?.into();
|
|
||||||
empty = false;
|
|
||||||
rrule_set.rdate(rdate)
|
|
||||||
}
|
|
||||||
"EXDATE" => {
|
|
||||||
let exdate = CalDateTime::parse_prop(prop, &self.timezones)?.into();
|
|
||||||
empty = false;
|
|
||||||
rrule_set.exdate(exdate)
|
|
||||||
}
|
|
||||||
_ => rrule_set,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if empty {
|
|
||||||
return Ok(None);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(Some(rrule_set))
|
|
||||||
}
|
|
||||||
|
|
||||||
// The returned calendar components MUST NOT use recurrence
|
|
||||||
// properties (i.e., EXDATE, EXRULE, RDATE, and RRULE) and MUST NOT
|
|
||||||
// have reference to or include VTIMEZONE components. Date and local
|
|
||||||
// time with reference to time zone information MUST be converted
|
|
||||||
// into date with UTC time.
|
|
||||||
pub fn expand_recurrence(
|
|
||||||
&self,
|
|
||||||
start: Option<DateTime<Utc>>,
|
|
||||||
end: Option<DateTime<Utc>>,
|
|
||||||
overrides: &[Self],
|
|
||||||
) -> Result<Vec<IcalEvent>, Error> {
|
|
||||||
let mut events = vec![];
|
|
||||||
let dtstart = self.get_dtstart()?.expect("We must have a DTSTART here");
|
|
||||||
let computed_duration = self
|
|
||||||
.get_dtend()?
|
|
||||||
.map(|dtend| dtend.as_datetime().into_owned() - dtstart.as_datetime().as_ref());
|
|
||||||
|
|
||||||
let Some(mut rrule_set) = self.recurrence_ruleset()? else {
|
|
||||||
// If ruleset empty simply return main event AND all overrides
|
|
||||||
return Ok(std::iter::once(self.clone())
|
|
||||||
.chain(overrides.iter().cloned())
|
|
||||||
.map(|event| event.event)
|
|
||||||
.collect());
|
|
||||||
};
|
|
||||||
if let Some(start) = start {
|
|
||||||
rrule_set = rrule_set.after(start.with_timezone(&rrule::Tz::UTC));
|
|
||||||
}
|
|
||||||
if let Some(end) = end {
|
|
||||||
rrule_set = rrule_set.before(end.with_timezone(&rrule::Tz::UTC));
|
|
||||||
}
|
|
||||||
let dates = rrule_set.all(2048).dates;
|
|
||||||
'recurrence: for date in dates {
|
|
||||||
let date = CalDateTime::from(date.to_utc());
|
|
||||||
let recurrence_id = if dtstart.is_date() {
|
|
||||||
date.format_date()
|
|
||||||
} else {
|
|
||||||
date.format()
|
|
||||||
};
|
|
||||||
|
|
||||||
for ev_override in overrides {
|
|
||||||
if let Some(override_id) = &ev_override
|
|
||||||
.event
|
|
||||||
.get_recurrence_id()
|
|
||||||
.as_ref()
|
|
||||||
.expect("overrides have a recurrence id")
|
|
||||||
.value
|
|
||||||
&& override_id == &recurrence_id
|
|
||||||
{
|
|
||||||
// We have an override for this occurence
|
|
||||||
//
|
|
||||||
events.push(ev_override.event.clone());
|
|
||||||
continue 'recurrence;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut ev = self.event.clone().mutable();
|
|
||||||
ev.remove_property("RRULE");
|
|
||||||
ev.remove_property("RDATE");
|
|
||||||
ev.remove_property("EXDATE");
|
|
||||||
ev.remove_property("EXRULE");
|
|
||||||
let dtstart_prop = ev
|
|
||||||
.get_property("DTSTART")
|
|
||||||
.expect("We must have a DTSTART here")
|
|
||||||
.clone();
|
|
||||||
ev.remove_property("DTSTART");
|
|
||||||
ev.remove_property("DTEND");
|
|
||||||
|
|
||||||
ev.set_property(Property {
|
|
||||||
name: "RECURRENCE-ID".to_string(),
|
|
||||||
value: Some(recurrence_id.clone()),
|
|
||||||
params: vec![],
|
|
||||||
});
|
|
||||||
ev.set_property(Property {
|
|
||||||
name: "DTSTART".to_string(),
|
|
||||||
value: Some(recurrence_id),
|
|
||||||
params: vec![],
|
|
||||||
});
|
|
||||||
if let Some(duration) = computed_duration {
|
|
||||||
let dtend = date + duration;
|
|
||||||
let dtendformat = if dtstart.is_date() {
|
|
||||||
dtend.format_date()
|
|
||||||
} else {
|
|
||||||
dtend.format()
|
|
||||||
};
|
|
||||||
ev.set_property(Property {
|
|
||||||
name: "DTEND".to_string(),
|
|
||||||
value: Some(dtendformat),
|
|
||||||
params: dtstart_prop.params,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
events.push(ev.verify()?);
|
|
||||||
}
|
|
||||||
Ok(events)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use crate::{CalDateTime, CalendarObject};
|
|
||||||
use chrono::{DateTime, Utc};
|
|
||||||
use ical::generator::Emitter;
|
|
||||||
use rstest::rstest;
|
|
||||||
|
|
||||||
const ICS_1: &str = r"BEGIN:VCALENDAR
|
|
||||||
CALSCALE:GREGORIAN
|
|
||||||
VERSION:2.0
|
|
||||||
BEGIN:VTIMEZONE
|
|
||||||
TZID:Europe/Berlin
|
|
||||||
X-LIC-LOCATION:Europe/Berlin
|
|
||||||
END:VTIMEZONE
|
|
||||||
|
|
||||||
BEGIN:VEVENT
|
|
||||||
UID:318ec6503573d9576818daf93dac07317058d95c
|
|
||||||
DTSTAMP:20250502T132758Z
|
|
||||||
DTSTART;TZID=Europe/Berlin:20250506T090000
|
|
||||||
DTEND;TZID=Europe/Berlin:20250506T092500
|
|
||||||
SEQUENCE:2
|
|
||||||
SUMMARY:weekly stuff
|
|
||||||
TRANSP:OPAQUE
|
|
||||||
RRULE:FREQ=WEEKLY;COUNT=4;INTERVAL=2;BYDAY=TU,TH,SU
|
|
||||||
END:VEVENT
|
|
||||||
END:VCALENDAR";
|
|
||||||
|
|
||||||
const EXPANDED_1: &[&str] = &[
|
|
||||||
"BEGIN:VEVENT\r
|
|
||||||
UID:318ec6503573d9576818daf93dac07317058d95c\r
|
|
||||||
DTSTAMP:20250502T132758Z\r
|
|
||||||
SEQUENCE:2\r
|
|
||||||
SUMMARY:weekly stuff\r
|
|
||||||
TRANSP:OPAQUE\r
|
|
||||||
RECURRENCE-ID:20250506T070000Z\r
|
|
||||||
DTSTART:20250506T070000Z\r
|
|
||||||
DTEND:20250506T072500Z\r
|
|
||||||
END:VEVENT\r\n",
|
|
||||||
"BEGIN:VEVENT\r
|
|
||||||
UID:318ec6503573d9576818daf93dac07317058d95c\r
|
|
||||||
DTSTAMP:20250502T132758Z\r
|
|
||||||
SEQUENCE:2\r
|
|
||||||
SUMMARY:weekly stuff\r
|
|
||||||
TRANSP:OPAQUE\r
|
|
||||||
RECURRENCE-ID:20250508T070000Z\r
|
|
||||||
DTSTART:20250508T070000Z\r
|
|
||||||
DTEND:20250508T072500Z\r
|
|
||||||
END:VEVENT\r\n",
|
|
||||||
"BEGIN:VEVENT\r
|
|
||||||
UID:318ec6503573d9576818daf93dac07317058d95c\r
|
|
||||||
DTSTAMP:20250502T132758Z\r
|
|
||||||
SEQUENCE:2\r
|
|
||||||
SUMMARY:weekly stuff\r
|
|
||||||
TRANSP:OPAQUE\r
|
|
||||||
RECURRENCE-ID:20250511T090000\r
|
|
||||||
DTSTART:20250511T070000Z\r
|
|
||||||
DTEND:20250511T072500Z\r
|
|
||||||
END:VEVENT\r\n",
|
|
||||||
"BEGIN:VEVENT\r
|
|
||||||
UID:318ec6503573d9576818daf93dac07317058d95c\r
|
|
||||||
DTSTAMP:20250502T132758Z\r
|
|
||||||
SEQUENCE:2\r
|
|
||||||
SUMMARY:weekly stuff\r
|
|
||||||
TRANSP:OPAQUE\r
|
|
||||||
RECURRENCE-ID:20250520T090000\r
|
|
||||||
DTSTA:20250520T070000Z\r
|
|
||||||
DTEND:20250520T072500Z\r
|
|
||||||
END:VEVENT\r\n",
|
|
||||||
];
|
|
||||||
|
|
||||||
const ICS_2: &str = r"BEGIN:VCALENDAR
|
|
||||||
CALSCALE:GREGORIAN
|
|
||||||
VERSION:2.0
|
|
||||||
BEGIN:VTIMEZONE
|
|
||||||
TZID:US/Eastern
|
|
||||||
END:VTIMEZONE
|
|
||||||
BEGIN:VEVENT
|
|
||||||
DTSTAMP:20060206T001121Z
|
|
||||||
DTSTART;TZID=US/Eastern:20060102T120000
|
|
||||||
DURATION:PT1H
|
|
||||||
RRULE:FREQ=DAILY;COUNT=5
|
|
||||||
SUMMARY:Event #2
|
|
||||||
UID:abcd2
|
|
||||||
END:VEVENT
|
|
||||||
BEGIN:VEVENT
|
|
||||||
DTSTAMP:20060206T001121Z
|
|
||||||
DTSTART;TZID=US/Eastern:20060104T140000
|
|
||||||
DURATION:PT1H
|
|
||||||
RECURRENCE-ID;TZID=US/Eastern:20060104T120000
|
|
||||||
SUMMARY:Event #2 bis
|
|
||||||
UID:abcd2
|
|
||||||
END:VEVENT
|
|
||||||
END:VCALENDAR
|
|
||||||
";
|
|
||||||
|
|
||||||
const EXPANDED_2: &[&str] = &[
|
|
||||||
"BEGIN:VEVENT\r
|
|
||||||
DTSTAMP:20060206T001121Z\r
|
|
||||||
DURATION:PT1H\r
|
|
||||||
SUMMARY:Event #2\r
|
|
||||||
UID:abcd2\r
|
|
||||||
RECURRENCE-ID:20060103T170000\r
|
|
||||||
DTSTART:20060103T170000\r
|
|
||||||
END:VEVENT\r\n",
|
|
||||||
"BEGIN:VEVENT\r
|
|
||||||
DTSTAMP:20060206T001121Z\r
|
|
||||||
DURATION:PT1H\r
|
|
||||||
SUMMARY:Event #2 bis\r
|
|
||||||
UID:abcd2\r
|
|
||||||
RECURRENCE-ID:20060104T170000\r
|
|
||||||
DTSTART:20060104T190000\r
|
|
||||||
END:VEVENT\r
|
|
||||||
END:VCALENDAR\r\n",
|
|
||||||
];
|
|
||||||
|
|
||||||
const ICS_3: &str = r"BEGIN:VCALENDAR
|
|
||||||
CALSCALE:GREGORIAN
|
|
||||||
VERSION:2.0
|
|
||||||
BEGIN:VTIMEZONE
|
|
||||||
TZID:US/Eastern
|
|
||||||
END:VTIMEZONE
|
|
||||||
BEGIN:VEVENT
|
|
||||||
ATTENDEE;PARTSTAT=ACCEPTED;ROLE=CHAIR:mailto:cyrus@example.com
|
|
||||||
ATTENDEE;PARTSTAT=NEEDS-ACTION:mailto:lisa@example.com
|
|
||||||
DTSTAMP:20060206T001220Z
|
|
||||||
DTSTART;TZID=US/Eastern:20060104T100000
|
|
||||||
DURATION:PT1H
|
|
||||||
LAST-MODIFIED:20060206T001330Z
|
|
||||||
ORGANIZER:mailto:cyrus@example.com
|
|
||||||
SEQUENCE:1
|
|
||||||
STATUS:TENTATIVE
|
|
||||||
SUMMARY:Event #3
|
|
||||||
UID:abcd3
|
|
||||||
END:VEVENT
|
|
||||||
END:VCALENDAR
|
|
||||||
";
|
|
||||||
|
|
||||||
const EXPANDED_3: &[&str] = &["BEGIN:VEVENT
|
|
||||||
ATTENDEE;PARTSTAT=ACCEPTED;ROLE=CHAIR:mailto:cyrus@example.com
|
|
||||||
ATTENDEE;PARTSTAT=NEEDS-ACTION:mailto:lisa@example.com
|
|
||||||
DTSTAMP:20060206T001220Z
|
|
||||||
DTSTART:20060104T150000
|
|
||||||
DURATION:PT1H
|
|
||||||
LAST-MODIFIED:20060206T001330Z
|
|
||||||
ORGANIZER:mailto:cyrus@example.com
|
|
||||||
SEQUENCE:1
|
|
||||||
STATUS:TENTATIVE
|
|
||||||
SUMMARY:Event #3
|
|
||||||
UID:abcd3
|
|
||||||
X-ABC-GUID:E1CX5Dr-0007ym-Hz@example.com
|
|
||||||
END:VEVENT"];
|
|
||||||
|
|
||||||
#[rstest]
|
|
||||||
#[case(ICS_1, EXPANDED_1, None, None)]
|
|
||||||
// from https://datatracker.ietf.org/doc/html/rfc4791#section-7.8.3
|
|
||||||
#[case(ICS_2, EXPANDED_2,
|
|
||||||
Some(CalDateTime::parse("20060103T000000Z", Some(chrono_tz::US::Eastern)).unwrap().utc()),
|
|
||||||
Some(CalDateTime::parse("20060105T000000Z", Some(chrono_tz::US::Eastern)).unwrap().utc())
|
|
||||||
)]
|
|
||||||
#[case(ICS_3, EXPANDED_3,
|
|
||||||
Some(CalDateTime::parse("20060103T000000Z", Some(chrono_tz::US::Eastern)).unwrap().utc()),
|
|
||||||
Some(CalDateTime::parse("20060105T000000Z", Some(chrono_tz::US::Eastern)).unwrap().utc())
|
|
||||||
)]
|
|
||||||
fn test_expand_recurrence(
|
|
||||||
#[case] ics: &'static str,
|
|
||||||
#[case] expanded: &[&str],
|
|
||||||
#[case] from: Option<DateTime<Utc>>,
|
|
||||||
#[case] to: Option<DateTime<Utc>>,
|
|
||||||
) {
|
|
||||||
let event = CalendarObject::from_ics(ics.to_string(), None).unwrap();
|
|
||||||
let crate::CalendarObjectComponent::Event(event, overrides) = event.get_data() else {
|
|
||||||
panic!()
|
|
||||||
};
|
|
||||||
|
|
||||||
let events: Vec<String> = event
|
|
||||||
.expand_recurrence(from, to, overrides)
|
|
||||||
.unwrap()
|
|
||||||
.into_iter()
|
|
||||||
.map(|event| Emitter::generate(&event))
|
|
||||||
.collect();
|
|
||||||
assert_eq!(events.len(), expanded.len());
|
|
||||||
for (output, reference) in events.iter().zip(expanded) {
|
|
||||||
similar_asserts::assert_eq!(output, reference);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
mod event;
|
|
||||||
mod object;
|
|
||||||
|
|
||||||
pub use event::*;
|
|
||||||
pub use object::*;
|
|
||||||
@@ -1,366 +0,0 @@
|
|||||||
use super::EventObject;
|
|
||||||
use crate::CalDateTime;
|
|
||||||
use crate::Error;
|
|
||||||
use chrono::DateTime;
|
|
||||||
use chrono::Utc;
|
|
||||||
use derive_more::Display;
|
|
||||||
use ical::generator::{Emitter, IcalCalendar};
|
|
||||||
use ical::parser::ical::component::IcalJournal;
|
|
||||||
use ical::parser::ical::component::IcalTimeZone;
|
|
||||||
use ical::parser::ical::component::IcalTodo;
|
|
||||||
use ical::property::Property;
|
|
||||||
use serde::Deserialize;
|
|
||||||
use serde::Serialize;
|
|
||||||
use sha2::{Digest, Sha256};
|
|
||||||
use std::{collections::HashMap, io::BufReader};
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Display)]
|
|
||||||
// specified in https://datatracker.ietf.org/doc/html/rfc5545#section-3.6
|
|
||||||
pub enum CalendarObjectType {
|
|
||||||
#[serde(rename = "VEVENT")]
|
|
||||||
Event = 0,
|
|
||||||
#[serde(rename = "VTODO")]
|
|
||||||
Todo = 1,
|
|
||||||
#[serde(rename = "VJOURNAL")]
|
|
||||||
Journal = 2,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CalendarObjectType {
|
|
||||||
#[must_use]
|
|
||||||
pub const fn as_str(&self) -> &'static str {
|
|
||||||
match self {
|
|
||||||
Self::Event => "VEVENT",
|
|
||||||
Self::Todo => "VTODO",
|
|
||||||
Self::Journal => "VJOURNAL",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl rustical_xml::ValueSerialize for CalendarObjectType {
|
|
||||||
fn serialize(&self) -> String {
|
|
||||||
self.as_str().to_owned()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl rustical_xml::ValueDeserialize for CalendarObjectType {
|
|
||||||
fn deserialize(val: &str) -> std::result::Result<Self, rustical_xml::XmlError> {
|
|
||||||
match <String as rustical_xml::ValueDeserialize>::deserialize(val)?.as_str() {
|
|
||||||
"VEVENT" => Ok(Self::Event),
|
|
||||||
"VTODO" => Ok(Self::Todo),
|
|
||||||
"VJOURNAL" => Ok(Self::Journal),
|
|
||||||
_ => Err(rustical_xml::XmlError::InvalidValue(
|
|
||||||
rustical_xml::ParseValueError::Other(format!(
|
|
||||||
"Invalid value '{val}', must be VEVENT, VTODO, or VJOURNAL"
|
|
||||||
)),
|
|
||||||
)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub enum CalendarObjectComponent {
|
|
||||||
Event(EventObject, Vec<EventObject>),
|
|
||||||
Todo(IcalTodo, Vec<IcalTodo>),
|
|
||||||
Journal(IcalJournal, Vec<IcalJournal>),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CalendarObjectComponent {
|
|
||||||
#[must_use]
|
|
||||||
pub fn get_uid(&self) -> &str {
|
|
||||||
match &self {
|
|
||||||
// We've made sure before that the first component exists and all components share the
|
|
||||||
// same UID
|
|
||||||
Self::Todo(todo, _) => todo.get_uid(),
|
|
||||||
Self::Event(event, _) => event.event.get_uid(),
|
|
||||||
Self::Journal(journal, _) => journal.get_uid(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<&CalendarObjectComponent> for CalendarObjectType {
|
|
||||||
fn from(value: &CalendarObjectComponent) -> Self {
|
|
||||||
match value {
|
|
||||||
CalendarObjectComponent::Event(..) => Self::Event,
|
|
||||||
CalendarObjectComponent::Todo(..) => Self::Todo,
|
|
||||||
CalendarObjectComponent::Journal(..) => Self::Journal,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CalendarObjectComponent {
|
|
||||||
fn from_events(mut events: Vec<EventObject>) -> Result<Self, Error> {
|
|
||||||
// A calendar object does not necessarily have to contain a main VOBJECT
|
|
||||||
if events.is_empty() {
|
|
||||||
return Err(Error::MissingCalendar);
|
|
||||||
}
|
|
||||||
#[allow(clippy::option_if_let_else)]
|
|
||||||
let main_event = if let Some(main) = events
|
|
||||||
.extract_if(.., |event| event.event.get_recurrence_id().is_none())
|
|
||||||
.next()
|
|
||||||
{
|
|
||||||
main
|
|
||||||
} else {
|
|
||||||
events.remove(0)
|
|
||||||
};
|
|
||||||
let overrides = events;
|
|
||||||
for event in &overrides {
|
|
||||||
if event.get_uid() != main_event.get_uid() {
|
|
||||||
return Err(Error::InvalidData(
|
|
||||||
"Calendar object contains multiple UIDs".to_owned(),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
if event.event.get_recurrence_id().is_none() {
|
|
||||||
return Err(Error::InvalidData(
|
|
||||||
"Calendar object can only contain one main component".to_owned(),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(Self::Event(main_event, overrides))
|
|
||||||
}
|
|
||||||
fn from_todos(mut todos: Vec<IcalTodo>) -> Result<Self, Error> {
|
|
||||||
// A calendar object does not necessarily have to contain a main VOBJECT
|
|
||||||
if todos.is_empty() {
|
|
||||||
return Err(Error::MissingCalendar);
|
|
||||||
}
|
|
||||||
#[allow(clippy::option_if_let_else)]
|
|
||||||
let main_todo = if let Some(main) = todos
|
|
||||||
.extract_if(.., |todo| todo.get_recurrence_id().is_none())
|
|
||||||
.next()
|
|
||||||
{
|
|
||||||
main
|
|
||||||
} else {
|
|
||||||
todos.remove(0)
|
|
||||||
};
|
|
||||||
let overrides = todos;
|
|
||||||
for todo in &overrides {
|
|
||||||
if todo.get_uid() != main_todo.get_uid() {
|
|
||||||
return Err(Error::InvalidData(
|
|
||||||
"Calendar object contains multiple UIDs".to_owned(),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
if todo.get_recurrence_id().is_none() {
|
|
||||||
return Err(Error::InvalidData(
|
|
||||||
"Calendar object can only contain one main component".to_owned(),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(Self::Todo(main_todo, overrides))
|
|
||||||
}
|
|
||||||
fn from_journals(mut journals: Vec<IcalJournal>) -> Result<Self, Error> {
|
|
||||||
// A calendar object does not necessarily have to contain a main VOBJECT
|
|
||||||
if journals.is_empty() {
|
|
||||||
return Err(Error::MissingCalendar);
|
|
||||||
}
|
|
||||||
#[allow(clippy::option_if_let_else)]
|
|
||||||
let main_journal = if let Some(main) = journals
|
|
||||||
.extract_if(.., |journal| journal.get_recurrence_id().is_none())
|
|
||||||
.next()
|
|
||||||
{
|
|
||||||
main
|
|
||||||
} else {
|
|
||||||
journals.remove(0)
|
|
||||||
};
|
|
||||||
let overrides = journals;
|
|
||||||
for journal in &overrides {
|
|
||||||
if journal.get_uid() != main_journal.get_uid() {
|
|
||||||
return Err(Error::InvalidData(
|
|
||||||
"Calendar object contains multiple UIDs".to_owned(),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
if journal.get_recurrence_id().is_none() {
|
|
||||||
return Err(Error::InvalidData(
|
|
||||||
"Calendar object can only contain one main component".to_owned(),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(Self::Journal(main_journal, overrides))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_first_occurence(&self) -> Result<Option<CalDateTime>, Error> {
|
|
||||||
match &self {
|
|
||||||
Self::Event(main_event, overrides) => Ok(overrides
|
|
||||||
.iter()
|
|
||||||
.chain(std::iter::once(main_event))
|
|
||||||
.map(super::event::EventObject::get_dtstart)
|
|
||||||
.collect::<Result<Vec<_>, _>>()?
|
|
||||||
.into_iter()
|
|
||||||
.flatten()
|
|
||||||
.min()),
|
|
||||||
_ => Ok(None),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_last_occurence(&self) -> Result<Option<CalDateTime>, Error> {
|
|
||||||
match &self {
|
|
||||||
Self::Event(main_event, overrides) => Ok(overrides
|
|
||||||
.iter()
|
|
||||||
.chain(std::iter::once(main_event))
|
|
||||||
.map(super::event::EventObject::get_last_occurence)
|
|
||||||
.collect::<Result<Vec<_>, _>>()?
|
|
||||||
.into_iter()
|
|
||||||
.flatten()
|
|
||||||
.max()),
|
|
||||||
_ => Ok(None),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub struct CalendarObject {
|
|
||||||
data: CalendarObjectComponent,
|
|
||||||
properties: Vec<Property>,
|
|
||||||
id: String,
|
|
||||||
ics: String,
|
|
||||||
vtimezones: HashMap<String, IcalTimeZone>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CalendarObject {
|
|
||||||
pub fn from_ics(ics: String, id: Option<String>) -> Result<Self, Error> {
|
|
||||||
let mut parser = ical::IcalParser::new(BufReader::new(ics.as_bytes()));
|
|
||||||
let cal = parser.next().ok_or(Error::MissingCalendar)??;
|
|
||||||
if parser.next().is_some() {
|
|
||||||
return Err(Error::InvalidData(
|
|
||||||
"multiple calendars, only one allowed".to_owned(),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
if u8::from(!cal.events.is_empty())
|
|
||||||
+ u8::from(!cal.todos.is_empty())
|
|
||||||
+ u8::from(!cal.journals.is_empty())
|
|
||||||
+ u8::from(!cal.free_busys.is_empty())
|
|
||||||
!= 1
|
|
||||||
{
|
|
||||||
// https://datatracker.ietf.org/doc/html/rfc4791#section-4.1
|
|
||||||
return Err(Error::InvalidData(
|
|
||||||
"iCalendar object must have exactly one component type".to_owned(),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
let timezones: HashMap<String, Option<chrono_tz::Tz>> = cal
|
|
||||||
.timezones
|
|
||||||
.clone()
|
|
||||||
.into_iter()
|
|
||||||
.map(|timezone| (timezone.get_tzid().to_owned(), (&timezone).try_into().ok()))
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
let vtimezones = cal
|
|
||||||
.timezones
|
|
||||||
.clone()
|
|
||||||
.into_iter()
|
|
||||||
.map(|timezone| (timezone.get_tzid().to_owned(), timezone))
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
let data = if !cal.events.is_empty() {
|
|
||||||
CalendarObjectComponent::from_events(
|
|
||||||
cal.events
|
|
||||||
.into_iter()
|
|
||||||
.map(|event| EventObject {
|
|
||||||
event,
|
|
||||||
timezones: timezones.clone(),
|
|
||||||
})
|
|
||||||
.collect(),
|
|
||||||
)?
|
|
||||||
} else if !cal.todos.is_empty() {
|
|
||||||
CalendarObjectComponent::from_todos(cal.todos)?
|
|
||||||
} else if !cal.journals.is_empty() {
|
|
||||||
CalendarObjectComponent::from_journals(cal.journals)?
|
|
||||||
} else {
|
|
||||||
return Err(Error::InvalidData(
|
|
||||||
"iCalendar component type not supported :(".to_owned(),
|
|
||||||
));
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(Self {
|
|
||||||
id: id.unwrap_or_else(|| data.get_uid().to_owned()),
|
|
||||||
data,
|
|
||||||
properties: cal.properties,
|
|
||||||
ics,
|
|
||||||
vtimezones,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub const fn get_vtimezones(&self) -> &HashMap<String, IcalTimeZone> {
|
|
||||||
&self.vtimezones
|
|
||||||
}
|
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub const fn get_data(&self) -> &CalendarObjectComponent {
|
|
||||||
&self.data
|
|
||||||
}
|
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub fn get_uid(&self) -> &str {
|
|
||||||
self.data.get_uid()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub fn get_id(&self) -> &str {
|
|
||||||
&self.id
|
|
||||||
}
|
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub fn get_etag(&self) -> String {
|
|
||||||
let mut hasher = Sha256::new();
|
|
||||||
hasher.update(self.get_uid());
|
|
||||||
hasher.update(self.get_ics());
|
|
||||||
format!("\"{:x}\"", hasher.finalize())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub fn get_ics(&self) -> &str {
|
|
||||||
&self.ics
|
|
||||||
}
|
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub fn get_component_name(&self) -> &str {
|
|
||||||
self.get_object_type().as_str()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub fn get_object_type(&self) -> CalendarObjectType {
|
|
||||||
(&self.data).into()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_first_occurence(&self) -> Result<Option<CalDateTime>, Error> {
|
|
||||||
self.data.get_first_occurence()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_last_occurence(&self) -> Result<Option<CalDateTime>, Error> {
|
|
||||||
self.data.get_last_occurence()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn expand_recurrence(
|
|
||||||
&self,
|
|
||||||
start: Option<DateTime<Utc>>,
|
|
||||||
end: Option<DateTime<Utc>>,
|
|
||||||
) -> Result<String, Error> {
|
|
||||||
// Only events can be expanded
|
|
||||||
match &self.data {
|
|
||||||
CalendarObjectComponent::Event(main_event, overrides) => {
|
|
||||||
let cal = IcalCalendar {
|
|
||||||
properties: self.properties.clone(),
|
|
||||||
events: main_event.expand_recurrence(start, end, overrides)?,
|
|
||||||
..Default::default()
|
|
||||||
};
|
|
||||||
Ok(cal.generate())
|
|
||||||
}
|
|
||||||
_ => Ok(self.get_ics().to_string()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub fn get_property(&self, name: &str) -> Option<&Property> {
|
|
||||||
self.properties
|
|
||||||
.iter()
|
|
||||||
.find(|property| property.name == name)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub fn get_named_properties(&self, name: &str) -> Vec<&Property> {
|
|
||||||
self.properties
|
|
||||||
.iter()
|
|
||||||
.filter(|property| property.name == name)
|
|
||||||
.collect()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +1,10 @@
|
|||||||
#![warn(clippy::all, clippy::pedantic, clippy::nursery)]
|
#![warn(clippy::all, clippy::pedantic, clippy::nursery)]
|
||||||
#![allow(clippy::missing_errors_doc, clippy::missing_panics_doc)]
|
#![allow(clippy::missing_errors_doc, clippy::missing_panics_doc)]
|
||||||
mod timestamp;
|
mod timestamp;
|
||||||
mod timezone;
|
|
||||||
pub use timestamp::*;
|
pub use timestamp::*;
|
||||||
pub use timezone::*;
|
|
||||||
|
|
||||||
mod icalendar;
|
mod calendar_object;
|
||||||
pub use icalendar::*;
|
pub use calendar_object::*;
|
||||||
|
|
||||||
mod error;
|
mod error;
|
||||||
pub use error::Error;
|
pub use error::Error;
|
||||||
|
|||||||
@@ -1,35 +1,8 @@
|
|||||||
use super::timezone::ICalTimezone;
|
use chrono::{DateTime, NaiveDateTime, Utc};
|
||||||
use chrono::{DateTime, Datelike, Duration, Local, NaiveDate, NaiveDateTime, NaiveTime, Utc};
|
|
||||||
use chrono_tz::Tz;
|
|
||||||
use derive_more::derive::Deref;
|
use derive_more::derive::Deref;
|
||||||
use ical::property::Property;
|
|
||||||
use rustical_xml::{ValueDeserialize, ValueSerialize};
|
use rustical_xml::{ValueDeserialize, ValueSerialize};
|
||||||
use std::{borrow::Cow, collections::HashMap, ops::Add, sync::LazyLock};
|
|
||||||
|
|
||||||
static RE_VCARD_DATE_MM_DD: LazyLock<regex::Regex> =
|
|
||||||
LazyLock::new(|| regex::Regex::new(r"^--(?<m>\d{2})(?<d>\d{2})$").unwrap());
|
|
||||||
|
|
||||||
const LOCAL_DATE_TIME: &str = "%Y%m%dT%H%M%S";
|
|
||||||
const UTC_DATE_TIME: &str = "%Y%m%dT%H%M%SZ";
|
const UTC_DATE_TIME: &str = "%Y%m%dT%H%M%SZ";
|
||||||
pub const LOCAL_DATE: &str = "%Y%m%d";
|
|
||||||
|
|
||||||
#[derive(Debug, thiserror::Error, PartialEq, Eq)]
|
|
||||||
pub enum CalDateTimeError {
|
|
||||||
#[error(
|
|
||||||
"Timezone has X-LIC-LOCATION property to specify a timezone from the Olson database, however its value {0} is invalid"
|
|
||||||
)]
|
|
||||||
InvalidOlson(String),
|
|
||||||
#[error("TZID {0} does not refer to a valid timezone")]
|
|
||||||
InvalidTZID(String),
|
|
||||||
#[error("Timestamp doesn't exist because of gap in local time")]
|
|
||||||
LocalTimeGap,
|
|
||||||
#[error("Datetime string {0} has an invalid format")]
|
|
||||||
InvalidDatetimeFormat(String),
|
|
||||||
#[error("Could not parse datetime {0}")]
|
|
||||||
ParseError(String),
|
|
||||||
#[error("Duration string {0} has an invalid format")]
|
|
||||||
InvalidDurationFormat(String),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deref, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Deref, PartialEq, Eq, Hash)]
|
||||||
pub struct UtcDateTime(pub DateTime<Utc>);
|
pub struct UtcDateTime(pub DateTime<Utc>);
|
||||||
@@ -54,375 +27,3 @@ impl ValueSerialize for UtcDateTime {
|
|||||||
format!("{}", self.0.format(UTC_DATE_TIME))
|
format!("{}", self.0.format(UTC_DATE_TIME))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
||||||
pub enum CalDateTime {
|
|
||||||
// Form 1, example: 19980118T230000 -> Local
|
|
||||||
// Form 2, example: 19980119T070000Z -> UTC
|
|
||||||
// Form 3, example: TZID=America/New_York:19980119T020000 -> Olson
|
|
||||||
// https://en.wikipedia.org/wiki/Tz_database
|
|
||||||
DateTime(DateTime<ICalTimezone>),
|
|
||||||
Date(NaiveDate, ICalTimezone),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<CalDateTime> for DateTime<rrule::Tz> {
|
|
||||||
fn from(value: CalDateTime) -> Self {
|
|
||||||
value
|
|
||||||
.as_datetime()
|
|
||||||
.into_owned()
|
|
||||||
.with_timezone(&value.timezone().into())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<DateTime<rrule::Tz>> for CalDateTime {
|
|
||||||
fn from(value: DateTime<rrule::Tz>) -> Self {
|
|
||||||
Self::DateTime(value.with_timezone(&value.timezone().into()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PartialOrd for CalDateTime {
|
|
||||||
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
|
|
||||||
Some(self.cmp(other))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Ord for CalDateTime {
|
|
||||||
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
|
|
||||||
match (&self, &other) {
|
|
||||||
(Self::DateTime(a), Self::DateTime(b)) => a.cmp(b),
|
|
||||||
(Self::DateTime(a), Self::Date(..)) => a.cmp(&other.as_datetime()),
|
|
||||||
(Self::Date(..), Self::DateTime(b)) => self.as_datetime().as_ref().cmp(b),
|
|
||||||
(Self::Date(..), Self::Date(..)) => self.as_datetime().cmp(&other.as_datetime()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<DateTime<Local>> for CalDateTime {
|
|
||||||
fn from(value: DateTime<Local>) -> Self {
|
|
||||||
Self::DateTime(value.with_timezone(&ICalTimezone::Local))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<DateTime<Utc>> for CalDateTime {
|
|
||||||
fn from(value: DateTime<Utc>) -> Self {
|
|
||||||
Self::DateTime(value.with_timezone(&ICalTimezone::Olson(chrono_tz::UTC)))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Add<Duration> for CalDateTime {
|
|
||||||
type Output = Self;
|
|
||||||
|
|
||||||
fn add(self, duration: Duration) -> Self::Output {
|
|
||||||
match self {
|
|
||||||
Self::DateTime(datetime) => Self::DateTime(datetime + duration),
|
|
||||||
Self::Date(date, tz) => Self::DateTime(
|
|
||||||
date.and_time(NaiveTime::default())
|
|
||||||
.and_local_timezone(tz)
|
|
||||||
.earliest()
|
|
||||||
.expect("Local timezone has constant offset")
|
|
||||||
+ duration,
|
|
||||||
),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CalDateTime {
|
|
||||||
pub fn parse_prop(
|
|
||||||
prop: &Property,
|
|
||||||
timezones: &HashMap<String, Option<chrono_tz::Tz>>,
|
|
||||||
) -> Result<Self, CalDateTimeError> {
|
|
||||||
let prop_value = prop
|
|
||||||
.value
|
|
||||||
.as_ref()
|
|
||||||
.ok_or_else(|| CalDateTimeError::InvalidDatetimeFormat("empty property".into()))?;
|
|
||||||
|
|
||||||
let timezone = if let Some(tzid) = prop.get_param("TZID") {
|
|
||||||
if let Some(timezone) = timezones.get(tzid) {
|
|
||||||
timezone.to_owned()
|
|
||||||
} else {
|
|
||||||
// TZID refers to timezone that does not exist
|
|
||||||
return Err(CalDateTimeError::InvalidTZID(tzid.to_string()));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// No explicit timezone specified.
|
|
||||||
// This is valid and will be localtime or UTC depending on the value
|
|
||||||
// We will stick to this default as documented in https://github.com/lennart-k/rustical/issues/102
|
|
||||||
None
|
|
||||||
};
|
|
||||||
|
|
||||||
Self::parse(prop_value, timezone)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub fn format(&self) -> String {
|
|
||||||
match self {
|
|
||||||
Self::DateTime(datetime) => match datetime.timezone() {
|
|
||||||
ICalTimezone::Olson(chrono_tz::UTC) => datetime.format(UTC_DATE_TIME).to_string(),
|
|
||||||
_ => datetime.format(LOCAL_DATE_TIME).to_string(),
|
|
||||||
},
|
|
||||||
Self::Date(date, _) => date.format(LOCAL_DATE).to_string(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub fn format_date(&self) -> String {
|
|
||||||
match self {
|
|
||||||
Self::DateTime(datetime) => datetime.format(LOCAL_DATE).to_string(),
|
|
||||||
Self::Date(date, _) => date.format(LOCAL_DATE).to_string(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub fn date(&self) -> NaiveDate {
|
|
||||||
match self {
|
|
||||||
Self::DateTime(datetime) => datetime.date_naive(),
|
|
||||||
Self::Date(date, _) => date.to_owned(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub const fn is_date(&self) -> bool {
|
|
||||||
matches!(&self, Self::Date(_, _))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub fn as_datetime(&self) -> Cow<'_, DateTime<ICalTimezone>> {
|
|
||||||
match self {
|
|
||||||
Self::DateTime(datetime) => Cow::Borrowed(datetime),
|
|
||||||
Self::Date(date, tz) => Cow::Owned(
|
|
||||||
date.and_time(NaiveTime::default())
|
|
||||||
.and_local_timezone(tz.to_owned())
|
|
||||||
.earliest()
|
|
||||||
.expect("Midnight always exists"),
|
|
||||||
),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub fn with_timezone(&self, tz: &ICalTimezone) -> Self {
|
|
||||||
match self {
|
|
||||||
Self::DateTime(datetime) => Self::DateTime(datetime.with_timezone(tz)),
|
|
||||||
Self::Date(date, _) => Self::Date(date.to_owned(), tz.to_owned()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn parse(value: &str, timezone: Option<Tz>) -> Result<Self, CalDateTimeError> {
|
|
||||||
if let Ok(datetime) = NaiveDateTime::parse_from_str(value, LOCAL_DATE_TIME) {
|
|
||||||
if let Some(timezone) = timezone {
|
|
||||||
return Ok(Self::DateTime(
|
|
||||||
datetime
|
|
||||||
.and_local_timezone(timezone.into())
|
|
||||||
.earliest()
|
|
||||||
.ok_or(CalDateTimeError::LocalTimeGap)?,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
return Ok(Self::DateTime(
|
|
||||||
datetime
|
|
||||||
.and_local_timezone(ICalTimezone::Local)
|
|
||||||
.earliest()
|
|
||||||
.ok_or(CalDateTimeError::LocalTimeGap)?,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Ok(datetime) = NaiveDateTime::parse_from_str(value, UTC_DATE_TIME) {
|
|
||||||
return Ok(datetime.and_utc().into());
|
|
||||||
}
|
|
||||||
let timezone = timezone.map_or(ICalTimezone::Local, ICalTimezone::Olson);
|
|
||||||
if let Ok(date) = NaiveDate::parse_from_str(value, LOCAL_DATE) {
|
|
||||||
return Ok(Self::Date(date, timezone));
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Ok(date) = NaiveDate::parse_from_str(value, "%Y-%m-%d") {
|
|
||||||
return Ok(Self::Date(date, timezone));
|
|
||||||
}
|
|
||||||
if let Ok(date) = NaiveDate::parse_from_str(value, "%Y%m%d") {
|
|
||||||
return Ok(Self::Date(date, timezone));
|
|
||||||
}
|
|
||||||
|
|
||||||
Err(CalDateTimeError::InvalidDatetimeFormat(value.to_string()))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Also returns whether the date contains a year
|
|
||||||
pub fn parse_vcard(value: &str) -> Result<(Self, bool), CalDateTimeError> {
|
|
||||||
if let Ok(datetime) = Self::parse(value, None) {
|
|
||||||
return Ok((datetime, true));
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(captures) = RE_VCARD_DATE_MM_DD.captures(value) {
|
|
||||||
// Because 1972 is a leap year
|
|
||||||
let year = 1972;
|
|
||||||
// Cannot fail because of the regex
|
|
||||||
let month = captures.name("m").unwrap().as_str().parse().ok().unwrap();
|
|
||||||
let day = captures.name("d").unwrap().as_str().parse().ok().unwrap();
|
|
||||||
|
|
||||||
return Ok((
|
|
||||||
Self::Date(
|
|
||||||
NaiveDate::from_ymd_opt(year, month, day)
|
|
||||||
.ok_or_else(|| CalDateTimeError::ParseError(value.to_string()))?,
|
|
||||||
ICalTimezone::Local,
|
|
||||||
),
|
|
||||||
false,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
Err(CalDateTimeError::InvalidDatetimeFormat(value.to_string()))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub fn utc(&self) -> DateTime<Utc> {
|
|
||||||
self.as_datetime().to_utc()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub fn timezone(&self) -> ICalTimezone {
|
|
||||||
match &self {
|
|
||||||
Self::DateTime(datetime) => datetime.timezone(),
|
|
||||||
Self::Date(_, tz) => tz.to_owned(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<CalDateTime> for DateTime<Utc> {
|
|
||||||
fn from(value: CalDateTime) -> Self {
|
|
||||||
value.utc()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Datelike for CalDateTime {
|
|
||||||
fn year(&self) -> i32 {
|
|
||||||
match &self {
|
|
||||||
Self::DateTime(datetime) => datetime.year(),
|
|
||||||
Self::Date(date, _) => date.year(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fn month(&self) -> u32 {
|
|
||||||
match &self {
|
|
||||||
Self::DateTime(datetime) => datetime.month(),
|
|
||||||
Self::Date(date, _) => date.month(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn month0(&self) -> u32 {
|
|
||||||
match &self {
|
|
||||||
Self::DateTime(datetime) => datetime.month0(),
|
|
||||||
Self::Date(date, _) => date.month0(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fn day(&self) -> u32 {
|
|
||||||
match &self {
|
|
||||||
Self::DateTime(datetime) => datetime.day(),
|
|
||||||
Self::Date(date, _) => date.day(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fn day0(&self) -> u32 {
|
|
||||||
match &self {
|
|
||||||
Self::DateTime(datetime) => datetime.day0(),
|
|
||||||
Self::Date(date, _) => date.day0(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fn ordinal(&self) -> u32 {
|
|
||||||
match &self {
|
|
||||||
Self::DateTime(datetime) => datetime.ordinal(),
|
|
||||||
Self::Date(date, _) => date.ordinal(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fn ordinal0(&self) -> u32 {
|
|
||||||
match &self {
|
|
||||||
Self::DateTime(datetime) => datetime.ordinal0(),
|
|
||||||
Self::Date(date, _) => date.ordinal0(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fn weekday(&self) -> chrono::Weekday {
|
|
||||||
match &self {
|
|
||||||
Self::DateTime(datetime) => datetime.weekday(),
|
|
||||||
Self::Date(date, _) => date.weekday(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fn iso_week(&self) -> chrono::IsoWeek {
|
|
||||||
match &self {
|
|
||||||
Self::DateTime(datetime) => datetime.iso_week(),
|
|
||||||
Self::Date(date, _) => date.iso_week(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fn with_year(&self, year: i32) -> Option<Self> {
|
|
||||||
match &self {
|
|
||||||
Self::DateTime(datetime) => Some(Self::DateTime(datetime.with_year(year)?)),
|
|
||||||
Self::Date(date, tz) => Some(Self::Date(date.with_year(year)?, tz.to_owned())),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fn with_month(&self, month: u32) -> Option<Self> {
|
|
||||||
match &self {
|
|
||||||
Self::DateTime(datetime) => Some(Self::DateTime(datetime.with_month(month)?)),
|
|
||||||
Self::Date(date, tz) => Some(Self::Date(date.with_month(month)?, tz.to_owned())),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fn with_month0(&self, month0: u32) -> Option<Self> {
|
|
||||||
match &self {
|
|
||||||
Self::DateTime(datetime) => Some(Self::DateTime(datetime.with_month0(month0)?)),
|
|
||||||
Self::Date(date, tz) => Some(Self::Date(date.with_month0(month0)?, tz.to_owned())),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fn with_day(&self, day: u32) -> Option<Self> {
|
|
||||||
match &self {
|
|
||||||
Self::DateTime(datetime) => Some(Self::DateTime(datetime.with_day(day)?)),
|
|
||||||
Self::Date(date, tz) => Some(Self::Date(date.with_day(day)?, tz.to_owned())),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fn with_day0(&self, day0: u32) -> Option<Self> {
|
|
||||||
match &self {
|
|
||||||
Self::DateTime(datetime) => Some(Self::DateTime(datetime.with_day0(day0)?)),
|
|
||||||
Self::Date(date, tz) => Some(Self::Date(date.with_day0(day0)?, tz.to_owned())),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fn with_ordinal(&self, ordinal: u32) -> Option<Self> {
|
|
||||||
match &self {
|
|
||||||
Self::DateTime(datetime) => Some(Self::DateTime(datetime.with_ordinal(ordinal)?)),
|
|
||||||
Self::Date(date, tz) => Some(Self::Date(date.with_ordinal(ordinal)?, tz.to_owned())),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fn with_ordinal0(&self, ordinal0: u32) -> Option<Self> {
|
|
||||||
match &self {
|
|
||||||
Self::DateTime(datetime) => Some(Self::DateTime(datetime.with_ordinal0(ordinal0)?)),
|
|
||||||
Self::Date(date, tz) => Some(Self::Date(date.with_ordinal0(ordinal0)?, tz.to_owned())),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use crate::CalDateTime;
|
|
||||||
use chrono::NaiveDate;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_vcard_date() {
|
|
||||||
assert_eq!(
|
|
||||||
CalDateTime::parse_vcard("19850412").unwrap(),
|
|
||||||
(
|
|
||||||
CalDateTime::Date(
|
|
||||||
NaiveDate::from_ymd_opt(1985, 4, 12).unwrap(),
|
|
||||||
crate::ICalTimezone::Local
|
|
||||||
),
|
|
||||||
true
|
|
||||||
)
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
CalDateTime::parse_vcard("1985-04-12").unwrap(),
|
|
||||||
(
|
|
||||||
CalDateTime::Date(
|
|
||||||
NaiveDate::from_ymd_opt(1985, 4, 12).unwrap(),
|
|
||||||
crate::ICalTimezone::Local
|
|
||||||
),
|
|
||||||
true
|
|
||||||
)
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
CalDateTime::parse_vcard("--0412").unwrap(),
|
|
||||||
(
|
|
||||||
CalDateTime::Date(
|
|
||||||
NaiveDate::from_ymd_opt(1972, 4, 12).unwrap(),
|
|
||||||
crate::ICalTimezone::Local
|
|
||||||
),
|
|
||||||
false
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,92 +0,0 @@
|
|||||||
use chrono::{Local, NaiveDate, NaiveDateTime, TimeZone};
|
|
||||||
use chrono_tz::Tz;
|
|
||||||
use derive_more::{Display, From};
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, From, PartialEq, Eq)]
|
|
||||||
pub enum ICalTimezone {
|
|
||||||
Local,
|
|
||||||
Olson(Tz),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<ICalTimezone> for rrule::Tz {
|
|
||||||
fn from(value: ICalTimezone) -> Self {
|
|
||||||
match value {
|
|
||||||
ICalTimezone::Local => Self::LOCAL,
|
|
||||||
ICalTimezone::Olson(tz) => Self::Tz(tz),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<rrule::Tz> for ICalTimezone {
|
|
||||||
fn from(value: rrule::Tz) -> Self {
|
|
||||||
match value {
|
|
||||||
rrule::Tz::Local(_) => Self::Local,
|
|
||||||
rrule::Tz::Tz(tz) => Self::Olson(tz),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Display)]
|
|
||||||
pub enum CalTimezoneOffset {
|
|
||||||
Local(chrono::FixedOffset),
|
|
||||||
Olson(chrono_tz::TzOffset),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl chrono::Offset for CalTimezoneOffset {
|
|
||||||
fn fix(&self) -> chrono::FixedOffset {
|
|
||||||
match self {
|
|
||||||
Self::Local(local) => local.fix(),
|
|
||||||
Self::Olson(olson) => olson.fix(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TimeZone for ICalTimezone {
|
|
||||||
type Offset = CalTimezoneOffset;
|
|
||||||
|
|
||||||
fn from_offset(offset: &Self::Offset) -> Self {
|
|
||||||
match offset {
|
|
||||||
CalTimezoneOffset::Local(_) => Self::Local,
|
|
||||||
CalTimezoneOffset::Olson(offset) => Self::Olson(Tz::from_offset(offset)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn offset_from_local_date(&self, local: &NaiveDate) -> chrono::MappedLocalTime<Self::Offset> {
|
|
||||||
match self {
|
|
||||||
Self::Local => Local
|
|
||||||
.offset_from_local_date(local)
|
|
||||||
.map(CalTimezoneOffset::Local),
|
|
||||||
Self::Olson(tz) => tz
|
|
||||||
.offset_from_local_date(local)
|
|
||||||
.map(CalTimezoneOffset::Olson),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn offset_from_local_datetime(
|
|
||||||
&self,
|
|
||||||
local: &NaiveDateTime,
|
|
||||||
) -> chrono::MappedLocalTime<Self::Offset> {
|
|
||||||
match self {
|
|
||||||
Self::Local => Local
|
|
||||||
.offset_from_local_datetime(local)
|
|
||||||
.map(CalTimezoneOffset::Local),
|
|
||||||
Self::Olson(tz) => tz
|
|
||||||
.offset_from_local_datetime(local)
|
|
||||||
.map(CalTimezoneOffset::Olson),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn offset_from_utc_datetime(&self, utc: &NaiveDateTime) -> Self::Offset {
|
|
||||||
match self {
|
|
||||||
Self::Local => CalTimezoneOffset::Local(Local.offset_from_utc_datetime(utc)),
|
|
||||||
Self::Olson(tz) => CalTimezoneOffset::Olson(tz.offset_from_utc_datetime(utc)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn offset_from_utc_date(&self, utc: &NaiveDate) -> Self::Offset {
|
|
||||||
match self {
|
|
||||||
Self::Local => CalTimezoneOffset::Local(Local.offset_from_utc_date(utc)),
|
|
||||||
Self::Olson(tz) => CalTimezoneOffset::Olson(tz.offset_from_utc_date(utc)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -25,6 +25,6 @@ END:VCALENDAR
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_calendar_object() {
|
fn parse_calendar_object() {
|
||||||
let object = CalendarObject::from_ics(MULTI_VEVENT.to_string(), None).unwrap();
|
let object = CalendarObject::from_ics(MULTI_VEVENT.to_string()).unwrap();
|
||||||
object.expand_recurrence(None, None).unwrap();
|
object.get_inner().expand_recurrence(None, None);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ pub trait AddressbookStore: Send + Sync + 'static {
|
|||||||
|
|
||||||
async fn update_addressbook(
|
async fn update_addressbook(
|
||||||
&self,
|
&self,
|
||||||
principal: String,
|
principal: &str,
|
||||||
id: String,
|
id: &str,
|
||||||
addressbook: Addressbook,
|
addressbook: Addressbook,
|
||||||
) -> Result<(), Error>;
|
) -> Result<(), Error>;
|
||||||
async fn insert_addressbook(&self, addressbook: Addressbook) -> Result<(), Error>;
|
async fn insert_addressbook(&self, addressbook: Addressbook) -> Result<(), Error>;
|
||||||
@@ -33,7 +33,7 @@ pub trait AddressbookStore: Send + Sync + 'static {
|
|||||||
principal: &str,
|
principal: &str,
|
||||||
addressbook_id: &str,
|
addressbook_id: &str,
|
||||||
synctoken: i64,
|
synctoken: i64,
|
||||||
) -> Result<(Vec<AddressObject>, Vec<String>, i64), Error>;
|
) -> Result<(Vec<(String, AddressObject)>, Vec<String>, i64), Error>;
|
||||||
|
|
||||||
async fn addressbook_metadata(
|
async fn addressbook_metadata(
|
||||||
&self,
|
&self,
|
||||||
@@ -45,7 +45,7 @@ pub trait AddressbookStore: Send + Sync + 'static {
|
|||||||
&self,
|
&self,
|
||||||
principal: &str,
|
principal: &str,
|
||||||
addressbook_id: &str,
|
addressbook_id: &str,
|
||||||
) -> Result<Vec<AddressObject>, Error>;
|
) -> Result<Vec<(String, AddressObject)>, Error>;
|
||||||
async fn get_object(
|
async fn get_object(
|
||||||
&self,
|
&self,
|
||||||
principal: &str,
|
principal: &str,
|
||||||
@@ -55,8 +55,9 @@ pub trait AddressbookStore: Send + Sync + 'static {
|
|||||||
) -> Result<AddressObject, Error>;
|
) -> Result<AddressObject, Error>;
|
||||||
async fn put_object(
|
async fn put_object(
|
||||||
&self,
|
&self,
|
||||||
principal: String,
|
principal: &str,
|
||||||
addressbook_id: String,
|
addressbook_id: &str,
|
||||||
|
object_id: &str,
|
||||||
object: AddressObject,
|
object: AddressObject,
|
||||||
overwrite: bool,
|
overwrite: bool,
|
||||||
) -> Result<(), Error>;
|
) -> Result<(), Error>;
|
||||||
@@ -77,7 +78,7 @@ pub trait AddressbookStore: Send + Sync + 'static {
|
|||||||
async fn import_addressbook(
|
async fn import_addressbook(
|
||||||
&self,
|
&self,
|
||||||
addressbook: Addressbook,
|
addressbook: Addressbook,
|
||||||
objects: Vec<AddressObject>,
|
objects: Vec<(String, AddressObject)>,
|
||||||
merge_existing: bool,
|
merge_existing: bool,
|
||||||
) -> Result<(), Error>;
|
) -> Result<(), Error>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ pub trait CalendarStore: Send + Sync + 'static {
|
|||||||
|
|
||||||
async fn update_calendar(
|
async fn update_calendar(
|
||||||
&self,
|
&self,
|
||||||
principal: String,
|
principal: &str,
|
||||||
id: String,
|
id: &str,
|
||||||
calendar: Calendar,
|
calendar: Calendar,
|
||||||
) -> Result<(), Error>;
|
) -> Result<(), Error>;
|
||||||
async fn insert_calendar(&self, calendar: Calendar) -> Result<(), Error>;
|
async fn insert_calendar(&self, calendar: Calendar) -> Result<(), Error>;
|
||||||
@@ -46,7 +46,7 @@ pub trait CalendarStore: Send + Sync + 'static {
|
|||||||
principal: &str,
|
principal: &str,
|
||||||
cal_id: &str,
|
cal_id: &str,
|
||||||
synctoken: i64,
|
synctoken: i64,
|
||||||
) -> Result<(Vec<CalendarObject>, Vec<String>, i64), Error>;
|
) -> Result<(Vec<(String, CalendarObject)>, Vec<String>, i64), Error>;
|
||||||
|
|
||||||
/// Since the <calendar-query> rules are rather complex this function
|
/// Since the <calendar-query> rules are rather complex this function
|
||||||
/// is only meant to do some prefiltering
|
/// is only meant to do some prefiltering
|
||||||
@@ -55,7 +55,7 @@ pub trait CalendarStore: Send + Sync + 'static {
|
|||||||
principal: &str,
|
principal: &str,
|
||||||
cal_id: &str,
|
cal_id: &str,
|
||||||
_query: CalendarQuery,
|
_query: CalendarQuery,
|
||||||
) -> Result<Vec<CalendarObject>, Error> {
|
) -> Result<Vec<(String, CalendarObject)>, Error> {
|
||||||
self.get_objects(principal, cal_id).await
|
self.get_objects(principal, cal_id).await
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,7 +69,7 @@ pub trait CalendarStore: Send + Sync + 'static {
|
|||||||
&self,
|
&self,
|
||||||
principal: &str,
|
principal: &str,
|
||||||
cal_id: &str,
|
cal_id: &str,
|
||||||
) -> Result<Vec<CalendarObject>, Error>;
|
) -> Result<Vec<(String, CalendarObject)>, Error>;
|
||||||
async fn get_object(
|
async fn get_object(
|
||||||
&self,
|
&self,
|
||||||
principal: &str,
|
principal: &str,
|
||||||
@@ -79,20 +79,26 @@ pub trait CalendarStore: Send + Sync + 'static {
|
|||||||
) -> Result<CalendarObject, Error>;
|
) -> Result<CalendarObject, Error>;
|
||||||
async fn put_objects(
|
async fn put_objects(
|
||||||
&self,
|
&self,
|
||||||
principal: String,
|
principal: &str,
|
||||||
cal_id: String,
|
cal_id: &str,
|
||||||
objects: Vec<CalendarObject>,
|
objects: Vec<(String, CalendarObject)>,
|
||||||
overwrite: bool,
|
overwrite: bool,
|
||||||
) -> Result<(), Error>;
|
) -> Result<(), Error>;
|
||||||
async fn put_object(
|
async fn put_object(
|
||||||
&self,
|
&self,
|
||||||
principal: String,
|
principal: &str,
|
||||||
cal_id: String,
|
cal_id: &str,
|
||||||
|
object_id: &str,
|
||||||
object: CalendarObject,
|
object: CalendarObject,
|
||||||
overwrite: bool,
|
overwrite: bool,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
self.put_objects(principal, cal_id, vec![object], overwrite)
|
self.put_objects(
|
||||||
.await
|
principal,
|
||||||
|
cal_id,
|
||||||
|
vec![(object_id.to_owned(), object)],
|
||||||
|
overwrite,
|
||||||
|
)
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
async fn delete_object(
|
async fn delete_object(
|
||||||
&self,
|
&self,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use crate::CalendarStore;
|
use crate::{Calendar, CalendarStore, calendar_store::CalendarQuery};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
|
use rustical_ical::CalendarObject;
|
||||||
use std::{collections::HashMap, sync::Arc};
|
use std::{collections::HashMap, sync::Arc};
|
||||||
|
|
||||||
pub trait PrefixedCalendarStore: CalendarStore {
|
pub trait PrefixedCalendarStore: CalendarStore {
|
||||||
@@ -51,11 +52,11 @@ impl CalendarStore for CombinedCalendarStore {
|
|||||||
|
|
||||||
async fn update_calendar(
|
async fn update_calendar(
|
||||||
&self,
|
&self,
|
||||||
principal: String,
|
principal: &str,
|
||||||
id: String,
|
id: &str,
|
||||||
calendar: crate::Calendar,
|
calendar: Calendar,
|
||||||
) -> Result<(), crate::Error> {
|
) -> Result<(), crate::Error> {
|
||||||
self.store_for_id(&id)
|
self.store_for_id(id)
|
||||||
.update_calendar(principal, id, calendar)
|
.update_calendar(principal, id, calendar)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
@@ -88,7 +89,7 @@ impl CalendarStore for CombinedCalendarStore {
|
|||||||
principal: &str,
|
principal: &str,
|
||||||
cal_id: &str,
|
cal_id: &str,
|
||||||
synctoken: i64,
|
synctoken: i64,
|
||||||
) -> Result<(Vec<rustical_ical::CalendarObject>, Vec<String>, i64), crate::Error> {
|
) -> Result<(Vec<(String, CalendarObject)>, Vec<String>, i64), crate::Error> {
|
||||||
self.store_for_id(cal_id)
|
self.store_for_id(cal_id)
|
||||||
.sync_changes(principal, cal_id, synctoken)
|
.sync_changes(principal, cal_id, synctoken)
|
||||||
.await
|
.await
|
||||||
@@ -97,7 +98,7 @@ impl CalendarStore for CombinedCalendarStore {
|
|||||||
async fn import_calendar(
|
async fn import_calendar(
|
||||||
&self,
|
&self,
|
||||||
calendar: crate::Calendar,
|
calendar: crate::Calendar,
|
||||||
objects: Vec<rustical_ical::CalendarObject>,
|
objects: Vec<CalendarObject>,
|
||||||
merge_existing: bool,
|
merge_existing: bool,
|
||||||
) -> Result<(), crate::Error> {
|
) -> Result<(), crate::Error> {
|
||||||
self.store_for_id(&calendar.id)
|
self.store_for_id(&calendar.id)
|
||||||
@@ -109,8 +110,8 @@ impl CalendarStore for CombinedCalendarStore {
|
|||||||
&self,
|
&self,
|
||||||
principal: &str,
|
principal: &str,
|
||||||
cal_id: &str,
|
cal_id: &str,
|
||||||
query: crate::calendar_store::CalendarQuery,
|
query: CalendarQuery,
|
||||||
) -> Result<Vec<rustical_ical::CalendarObject>, crate::Error> {
|
) -> Result<Vec<(String, CalendarObject)>, crate::Error> {
|
||||||
self.store_for_id(cal_id)
|
self.store_for_id(cal_id)
|
||||||
.calendar_query(principal, cal_id, query)
|
.calendar_query(principal, cal_id, query)
|
||||||
.await
|
.await
|
||||||
@@ -141,7 +142,7 @@ impl CalendarStore for CombinedCalendarStore {
|
|||||||
&self,
|
&self,
|
||||||
principal: &str,
|
principal: &str,
|
||||||
cal_id: &str,
|
cal_id: &str,
|
||||||
) -> Result<Vec<rustical_ical::CalendarObject>, crate::Error> {
|
) -> Result<Vec<(String, CalendarObject)>, crate::Error> {
|
||||||
self.store_for_id(cal_id)
|
self.store_for_id(cal_id)
|
||||||
.get_objects(principal, cal_id)
|
.get_objects(principal, cal_id)
|
||||||
.await
|
.await
|
||||||
@@ -149,12 +150,12 @@ impl CalendarStore for CombinedCalendarStore {
|
|||||||
|
|
||||||
async fn put_objects(
|
async fn put_objects(
|
||||||
&self,
|
&self,
|
||||||
principal: String,
|
principal: &str,
|
||||||
cal_id: String,
|
cal_id: &str,
|
||||||
objects: Vec<rustical_ical::CalendarObject>,
|
objects: Vec<(String, CalendarObject)>,
|
||||||
overwrite: bool,
|
overwrite: bool,
|
||||||
) -> Result<(), crate::Error> {
|
) -> Result<(), crate::Error> {
|
||||||
self.store_for_id(&cal_id)
|
self.store_for_id(cal_id)
|
||||||
.put_objects(principal, cal_id, objects, overwrite)
|
.put_objects(principal, cal_id, objects, overwrite)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ rstest.workspace = true
|
|||||||
criterion.workspace = true
|
criterion.workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
ical.workspace = true
|
||||||
tokio.workspace = true
|
tokio.workspace = true
|
||||||
rustical_store.workspace = true
|
rustical_store.workspace = true
|
||||||
async-trait.workspace = true
|
async-trait.workspace = true
|
||||||
|
|||||||
@@ -34,16 +34,19 @@ fn benchmark(c: &mut Criterion) {
|
|||||||
cal_store
|
cal_store
|
||||||
});
|
});
|
||||||
|
|
||||||
let object = CalendarObject::from_ics(include_str!("ical_event.ics").to_owned(), None).unwrap();
|
let row = (
|
||||||
|
"asd".to_owned(),
|
||||||
|
CalendarObject::from_ics(include_str!("ical_event.ics").to_owned()).unwrap(),
|
||||||
|
);
|
||||||
|
|
||||||
let batch_size = 1000;
|
let batch_size = 1000;
|
||||||
let objects: Vec<_> = std::iter::repeat_n(object.clone(), batch_size).collect();
|
let objects: Vec<_> = std::iter::repeat_n(row.clone(), batch_size).collect();
|
||||||
|
|
||||||
c.bench_function("put_batch", |b| {
|
c.bench_function("put_batch", |b| {
|
||||||
b.to_async(&runtime).iter(async || {
|
b.to_async(&runtime).iter(async || {
|
||||||
// yeet
|
// yeet
|
||||||
cal_store
|
cal_store
|
||||||
.put_objects("user".to_owned(), "okwow".to_owned(), objects.clone(), true)
|
.put_objects("user", "okwow", objects.clone(), true)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
});
|
});
|
||||||
@@ -54,7 +57,7 @@ fn benchmark(c: &mut Criterion) {
|
|||||||
// yeet
|
// yeet
|
||||||
for _ in 0..1000 {
|
for _ in 0..1000 {
|
||||||
cal_store
|
cal_store
|
||||||
.put_object("user".to_owned(), "okwow".to_owned(), object.clone(), true)
|
.put_object("user", "okwow", &row.0, row.1.clone(), true)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
use crate::addressbook_store::SqliteAddressbookStore;
|
use crate::addressbook_store::SqliteAddressbookStore;
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use chrono::NaiveDateTime;
|
use chrono::NaiveDateTime;
|
||||||
use rustical_ical::{AddressObject, CalendarObject, CalendarObjectType};
|
use rustical_ical::{CalendarObject, CalendarObjectType};
|
||||||
use rustical_store::{
|
use rustical_store::{
|
||||||
Addressbook, AddressbookStore, Calendar, CalendarMetadata, CalendarStore, CollectionMetadata,
|
Addressbook, AddressbookStore, Calendar, CalendarMetadata, CalendarStore, CollectionMetadata,
|
||||||
Error, PrefixedCalendarStore,
|
Error, PrefixedCalendarStore,
|
||||||
};
|
};
|
||||||
use sha2::{Digest, Sha256};
|
use sha2::{Digest, Sha256};
|
||||||
use sqlx::{Executor, Sqlite};
|
use sqlx::{Executor, Sqlite};
|
||||||
use std::collections::HashMap;
|
|
||||||
use tracing::instrument;
|
use tracing::instrument;
|
||||||
|
|
||||||
pub const BIRTHDAYS_PREFIX: &str = "_birthdays_";
|
pub const BIRTHDAYS_PREFIX: &str = "_birthdays_";
|
||||||
@@ -269,10 +268,11 @@ impl CalendarStore for SqliteAddressbookStore {
|
|||||||
#[instrument]
|
#[instrument]
|
||||||
async fn update_calendar(
|
async fn update_calendar(
|
||||||
&self,
|
&self,
|
||||||
principal: String,
|
principal: &str,
|
||||||
id: String,
|
id: &str,
|
||||||
mut calendar: Calendar,
|
mut calendar: Calendar,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
|
assert_eq!(principal, calendar.principal);
|
||||||
assert_eq!(id, calendar.id);
|
assert_eq!(id, calendar.id);
|
||||||
calendar.id = calendar
|
calendar.id = calendar
|
||||||
.id
|
.id
|
||||||
@@ -324,19 +324,20 @@ impl CalendarStore for SqliteAddressbookStore {
|
|||||||
principal: &str,
|
principal: &str,
|
||||||
cal_id: &str,
|
cal_id: &str,
|
||||||
synctoken: i64,
|
synctoken: i64,
|
||||||
) -> Result<(Vec<CalendarObject>, Vec<String>, i64), Error> {
|
) -> Result<(Vec<(String, CalendarObject)>, Vec<String>, i64), Error> {
|
||||||
let cal_id = cal_id
|
let cal_id = cal_id
|
||||||
.strip_prefix(BIRTHDAYS_PREFIX)
|
.strip_prefix(BIRTHDAYS_PREFIX)
|
||||||
.ok_or(Error::NotFound)?;
|
.ok_or(Error::NotFound)?;
|
||||||
let (objects, deleted_objects, new_synctoken) =
|
let (objects, deleted_objects, new_synctoken) =
|
||||||
AddressbookStore::sync_changes(self, principal, cal_id, synctoken).await?;
|
AddressbookStore::sync_changes(self, principal, cal_id, synctoken).await?;
|
||||||
let objects: Result<Vec<Option<CalendarObject>>, rustical_ical::Error> = objects
|
todo!();
|
||||||
.iter()
|
// let objects: Result<Vec<Option<CalendarObject>>, rustical_ical::Error> = objects
|
||||||
.map(AddressObject::get_birthday_object)
|
// .iter()
|
||||||
.collect();
|
// .map(AddressObject::get_birthday_object)
|
||||||
let objects = objects?.into_iter().flatten().collect();
|
// .collect();
|
||||||
|
// let objects = objects?.into_iter().flatten().collect();
|
||||||
Ok((objects, deleted_objects, new_synctoken))
|
//
|
||||||
|
// Ok((objects, deleted_objects, new_synctoken))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument]
|
#[instrument]
|
||||||
@@ -356,22 +357,23 @@ impl CalendarStore for SqliteAddressbookStore {
|
|||||||
&self,
|
&self,
|
||||||
principal: &str,
|
principal: &str,
|
||||||
cal_id: &str,
|
cal_id: &str,
|
||||||
) -> Result<Vec<CalendarObject>, Error> {
|
) -> Result<Vec<(String, CalendarObject)>, Error> {
|
||||||
let cal_id = cal_id
|
todo!()
|
||||||
.strip_prefix(BIRTHDAYS_PREFIX)
|
// let cal_id = cal_id
|
||||||
.ok_or(Error::NotFound)?;
|
// .strip_prefix(BIRTHDAYS_PREFIX)
|
||||||
let objects: Result<Vec<HashMap<&'static str, CalendarObject>>, rustical_ical::Error> =
|
// .ok_or(Error::NotFound)?;
|
||||||
AddressbookStore::get_objects(self, principal, cal_id)
|
// let objects: Result<Vec<HashMap<&'static str, CalendarObject>>, rustical_ical::Error> =
|
||||||
.await?
|
// AddressbookStore::get_objects(self, principal, cal_id)
|
||||||
.iter()
|
// .await?
|
||||||
.map(AddressObject::get_significant_dates)
|
// .iter()
|
||||||
.collect();
|
// .map(AddressObject::get_significant_dates)
|
||||||
let objects = objects?
|
// .collect();
|
||||||
.into_iter()
|
// let objects = objects?
|
||||||
.flat_map(HashMap::into_values)
|
// .into_iter()
|
||||||
.collect();
|
// .flat_map(HashMap::into_values)
|
||||||
|
// .collect();
|
||||||
Ok(objects)
|
//
|
||||||
|
// Ok(objects)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument]
|
#[instrument]
|
||||||
@@ -396,9 +398,9 @@ impl CalendarStore for SqliteAddressbookStore {
|
|||||||
#[instrument]
|
#[instrument]
|
||||||
async fn put_objects(
|
async fn put_objects(
|
||||||
&self,
|
&self,
|
||||||
_principal: String,
|
_principal: &str,
|
||||||
_cal_id: String,
|
_cal_id: &str,
|
||||||
_objects: Vec<CalendarObject>,
|
_objects: Vec<(String, CalendarObject)>,
|
||||||
_overwrite: bool,
|
_overwrite: bool,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
Err(Error::ReadOnly)
|
Err(Error::ReadOnly)
|
||||||
|
|||||||
@@ -19,11 +19,11 @@ struct AddressObjectRow {
|
|||||||
vcf: String,
|
vcf: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<AddressObjectRow> for AddressObject {
|
impl TryFrom<AddressObjectRow> for (String, AddressObject) {
|
||||||
type Error = rustical_store::Error;
|
type Error = rustical_store::Error;
|
||||||
|
|
||||||
fn try_from(value: AddressObjectRow) -> Result<Self, Self::Error> {
|
fn try_from(value: AddressObjectRow) -> Result<Self, Self::Error> {
|
||||||
Ok(Self::from_vcf(value.id, value.vcf)?)
|
Ok((value.id, AddressObject::from_vcf(value.vcf)?))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -290,7 +290,7 @@ impl SqliteAddressbookStore {
|
|||||||
principal: &str,
|
principal: &str,
|
||||||
addressbook_id: &str,
|
addressbook_id: &str,
|
||||||
synctoken: i64,
|
synctoken: i64,
|
||||||
) -> Result<(Vec<AddressObject>, Vec<String>, i64), rustical_store::Error> {
|
) -> Result<(Vec<(String, AddressObject)>, Vec<String>, i64), rustical_store::Error> {
|
||||||
struct Row {
|
struct Row {
|
||||||
object_id: String,
|
object_id: String,
|
||||||
synctoken: i64,
|
synctoken: i64,
|
||||||
@@ -318,7 +318,7 @@ impl SqliteAddressbookStore {
|
|||||||
for Row { object_id, .. } in changes {
|
for Row { object_id, .. } in changes {
|
||||||
match Self::_get_object(&mut *conn, principal, addressbook_id, &object_id, false).await
|
match Self::_get_object(&mut *conn, principal, addressbook_id, &object_id, false).await
|
||||||
{
|
{
|
||||||
Ok(object) => objects.push(object),
|
Ok(object) => objects.push((object_id, object)),
|
||||||
Err(rustical_store::Error::NotFound) => deleted_objects.push(object_id),
|
Err(rustical_store::Error::NotFound) => deleted_objects.push(object_id),
|
||||||
Err(err) => return Err(err),
|
Err(err) => return Err(err),
|
||||||
}
|
}
|
||||||
@@ -353,7 +353,7 @@ impl SqliteAddressbookStore {
|
|||||||
executor: E,
|
executor: E,
|
||||||
principal: &str,
|
principal: &str,
|
||||||
addressbook_id: &str,
|
addressbook_id: &str,
|
||||||
) -> Result<Vec<AddressObject>, rustical_store::Error> {
|
) -> Result<Vec<(String, AddressObject)>, rustical_store::Error> {
|
||||||
sqlx::query_as!(
|
sqlx::query_as!(
|
||||||
AddressObjectRow,
|
AddressObjectRow,
|
||||||
"SELECT id, vcf FROM addressobjects WHERE principal = ? AND addressbook_id = ? AND deleted_at IS NULL",
|
"SELECT id, vcf FROM addressobjects WHERE principal = ? AND addressbook_id = ? AND deleted_at IS NULL",
|
||||||
@@ -374,7 +374,7 @@ impl SqliteAddressbookStore {
|
|||||||
object_id: &str,
|
object_id: &str,
|
||||||
show_deleted: bool,
|
show_deleted: bool,
|
||||||
) -> Result<AddressObject, rustical_store::Error> {
|
) -> Result<AddressObject, rustical_store::Error> {
|
||||||
sqlx::query_as!(
|
let (id, object) = sqlx::query_as!(
|
||||||
AddressObjectRow,
|
AddressObjectRow,
|
||||||
"SELECT id, vcf FROM addressobjects WHERE (principal, addressbook_id, id) = (?, ?, ?) AND ((deleted_at IS NULL) OR ?)",
|
"SELECT id, vcf FROM addressobjects WHERE (principal, addressbook_id, id) = (?, ?, ?) AND ((deleted_at IS NULL) OR ?)",
|
||||||
principal,
|
principal,
|
||||||
@@ -385,17 +385,20 @@ impl SqliteAddressbookStore {
|
|||||||
.fetch_one(executor)
|
.fetch_one(executor)
|
||||||
.await
|
.await
|
||||||
.map_err(crate::Error::from)?
|
.map_err(crate::Error::from)?
|
||||||
.try_into()
|
.try_into()?;
|
||||||
|
assert_eq!(id, object_id);
|
||||||
|
Ok(object)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn _put_object<'e, E: Executor<'e, Database = Sqlite>>(
|
async fn _put_object<'e, E: Executor<'e, Database = Sqlite>>(
|
||||||
executor: E,
|
executor: E,
|
||||||
principal: &str,
|
principal: &str,
|
||||||
addressbook_id: &str,
|
addressbook_id: &str,
|
||||||
|
object_id: &str,
|
||||||
object: &AddressObject,
|
object: &AddressObject,
|
||||||
overwrite: bool,
|
overwrite: bool,
|
||||||
) -> Result<(), rustical_store::Error> {
|
) -> Result<(), rustical_store::Error> {
|
||||||
let (object_id, vcf) = (object.get_id(), object.get_vcf());
|
let vcf = object.get_vcf();
|
||||||
|
|
||||||
(if overwrite {
|
(if overwrite {
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
@@ -500,10 +503,12 @@ impl AddressbookStore for SqliteAddressbookStore {
|
|||||||
#[instrument]
|
#[instrument]
|
||||||
async fn update_addressbook(
|
async fn update_addressbook(
|
||||||
&self,
|
&self,
|
||||||
principal: String,
|
principal: &str,
|
||||||
id: String,
|
id: &str,
|
||||||
addressbook: Addressbook,
|
addressbook: Addressbook,
|
||||||
) -> Result<(), rustical_store::Error> {
|
) -> Result<(), rustical_store::Error> {
|
||||||
|
assert_eq!(principal, &addressbook.principal);
|
||||||
|
assert_eq!(id, &addressbook.id);
|
||||||
Self::_update_addressbook(&self.db, &principal, &id, &addressbook).await
|
Self::_update_addressbook(&self.db, &principal, &id, &addressbook).await
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -569,7 +574,7 @@ impl AddressbookStore for SqliteAddressbookStore {
|
|||||||
principal: &str,
|
principal: &str,
|
||||||
addressbook_id: &str,
|
addressbook_id: &str,
|
||||||
synctoken: i64,
|
synctoken: i64,
|
||||||
) -> Result<(Vec<AddressObject>, Vec<String>, i64), rustical_store::Error> {
|
) -> Result<(Vec<(String, AddressObject)>, Vec<String>, i64), rustical_store::Error> {
|
||||||
Self::_sync_changes(&self.db, principal, addressbook_id, synctoken).await
|
Self::_sync_changes(&self.db, principal, addressbook_id, synctoken).await
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -601,7 +606,7 @@ impl AddressbookStore for SqliteAddressbookStore {
|
|||||||
&self,
|
&self,
|
||||||
principal: &str,
|
principal: &str,
|
||||||
addressbook_id: &str,
|
addressbook_id: &str,
|
||||||
) -> Result<Vec<AddressObject>, rustical_store::Error> {
|
) -> Result<Vec<(String, AddressObject)>, rustical_store::Error> {
|
||||||
Self::_get_objects(&self.db, principal, addressbook_id).await
|
Self::_get_objects(&self.db, principal, addressbook_id).await
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -619,8 +624,9 @@ impl AddressbookStore for SqliteAddressbookStore {
|
|||||||
#[instrument]
|
#[instrument]
|
||||||
async fn put_object(
|
async fn put_object(
|
||||||
&self,
|
&self,
|
||||||
principal: String,
|
principal: &str,
|
||||||
addressbook_id: String,
|
addressbook_id: &str,
|
||||||
|
object_id: &str,
|
||||||
object: AddressObject,
|
object: AddressObject,
|
||||||
overwrite: bool,
|
overwrite: bool,
|
||||||
) -> Result<(), rustical_store::Error> {
|
) -> Result<(), rustical_store::Error> {
|
||||||
@@ -630,9 +636,15 @@ impl AddressbookStore for SqliteAddressbookStore {
|
|||||||
.await
|
.await
|
||||||
.map_err(crate::Error::from)?;
|
.map_err(crate::Error::from)?;
|
||||||
|
|
||||||
let object_id = object.get_id().to_owned();
|
Self::_put_object(
|
||||||
|
&mut *tx,
|
||||||
Self::_put_object(&mut *tx, &principal, &addressbook_id, &object, overwrite).await?;
|
principal,
|
||||||
|
addressbook_id,
|
||||||
|
object_id,
|
||||||
|
&object,
|
||||||
|
overwrite,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
let sync_token = Self::log_object_operation(
|
let sync_token = Self::log_object_operation(
|
||||||
&mut tx,
|
&mut tx,
|
||||||
@@ -648,7 +660,7 @@ impl AddressbookStore for SqliteAddressbookStore {
|
|||||||
|
|
||||||
self.send_push_notification(
|
self.send_push_notification(
|
||||||
CollectionOperationInfo::Content { sync_token },
|
CollectionOperationInfo::Content { sync_token },
|
||||||
self.get_addressbook(&principal, &addressbook_id, false)
|
self.get_addressbook(principal, addressbook_id, false)
|
||||||
.await?
|
.await?
|
||||||
.push_topic,
|
.push_topic,
|
||||||
);
|
);
|
||||||
@@ -733,7 +745,7 @@ impl AddressbookStore for SqliteAddressbookStore {
|
|||||||
async fn import_addressbook(
|
async fn import_addressbook(
|
||||||
&self,
|
&self,
|
||||||
addressbook: Addressbook,
|
addressbook: Addressbook,
|
||||||
objects: Vec<AddressObject>,
|
objects: Vec<(String, AddressObject)>,
|
||||||
merge_existing: bool,
|
merge_existing: bool,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let mut tx = self
|
let mut tx = self
|
||||||
@@ -758,11 +770,12 @@ impl AddressbookStore for SqliteAddressbookStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut sync_token = None;
|
let mut sync_token = None;
|
||||||
for object in objects {
|
for (object_id, object) in objects {
|
||||||
Self::_put_object(
|
Self::_put_object(
|
||||||
&mut *tx,
|
&mut *tx,
|
||||||
&addressbook.principal,
|
&addressbook.principal,
|
||||||
&addressbook.id,
|
&addressbook.id,
|
||||||
|
&object_id,
|
||||||
&object,
|
&object,
|
||||||
false,
|
false,
|
||||||
)
|
)
|
||||||
@@ -773,7 +786,7 @@ impl AddressbookStore for SqliteAddressbookStore {
|
|||||||
&mut tx,
|
&mut tx,
|
||||||
&addressbook.principal,
|
&addressbook.principal,
|
||||||
&addressbook.id,
|
&addressbook.id,
|
||||||
object.get_id(),
|
&object_id,
|
||||||
ChangeOperation::Add,
|
ChangeOperation::Add,
|
||||||
)
|
)
|
||||||
.await?,
|
.await?,
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ use crate::BEGIN_IMMEDIATE;
|
|||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use chrono::TimeDelta;
|
use chrono::TimeDelta;
|
||||||
use derive_more::derive::Constructor;
|
use derive_more::derive::Constructor;
|
||||||
use rustical_ical::{CalDateTime, CalendarObject, CalendarObjectType};
|
use ical::types::CalDateTime;
|
||||||
|
use rustical_ical::{CalendarObject, CalendarObjectType};
|
||||||
use rustical_store::calendar_store::CalendarQuery;
|
use rustical_store::calendar_store::CalendarQuery;
|
||||||
use rustical_store::synctoken::format_synctoken;
|
use rustical_store::synctoken::format_synctoken;
|
||||||
use rustical_store::{Calendar, CalendarMetadata, CalendarStore, CollectionMetadata, Error};
|
use rustical_store::{Calendar, CalendarMetadata, CalendarStore, CollectionMetadata, Error};
|
||||||
@@ -20,11 +21,11 @@ struct CalendarObjectRow {
|
|||||||
uid: String,
|
uid: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<CalendarObjectRow> for CalendarObject {
|
impl TryFrom<CalendarObjectRow> for (String, CalendarObject) {
|
||||||
type Error = rustical_store::Error;
|
type Error = rustical_store::Error;
|
||||||
|
|
||||||
fn try_from(value: CalendarObjectRow) -> Result<Self, Self::Error> {
|
fn try_from(value: CalendarObjectRow) -> Result<Self, Self::Error> {
|
||||||
let object = Self::from_ics(value.ics, Some(value.id))?;
|
let object = CalendarObject::from_ics(value.ics)?;
|
||||||
if object.get_uid() != value.uid {
|
if object.get_uid() != value.uid {
|
||||||
return Err(rustical_store::Error::IcalError(
|
return Err(rustical_store::Error::IcalError(
|
||||||
rustical_ical::Error::InvalidData(format!(
|
rustical_ical::Error::InvalidData(format!(
|
||||||
@@ -34,7 +35,7 @@ impl TryFrom<CalendarObjectRow> for CalendarObject {
|
|||||||
)),
|
)),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
Ok(object)
|
Ok((value.id, object))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -279,8 +280,8 @@ impl SqliteCalendarStore {
|
|||||||
|
|
||||||
async fn _update_calendar<'e, E: Executor<'e, Database = Sqlite>>(
|
async fn _update_calendar<'e, E: Executor<'e, Database = Sqlite>>(
|
||||||
executor: E,
|
executor: E,
|
||||||
principal: String,
|
principal: &str,
|
||||||
id: String,
|
id: &str,
|
||||||
calendar: Calendar,
|
calendar: Calendar,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let comp_event = calendar.components.contains(&CalendarObjectType::Event);
|
let comp_event = calendar.components.contains(&CalendarObjectType::Event);
|
||||||
@@ -378,7 +379,7 @@ impl SqliteCalendarStore {
|
|||||||
executor: E,
|
executor: E,
|
||||||
principal: &str,
|
principal: &str,
|
||||||
cal_id: &str,
|
cal_id: &str,
|
||||||
) -> Result<Vec<CalendarObject>, Error> {
|
) -> Result<Vec<(String, CalendarObject)>, Error> {
|
||||||
sqlx::query_as!(
|
sqlx::query_as!(
|
||||||
CalendarObjectRow,
|
CalendarObjectRow,
|
||||||
"SELECT id, uid, ics FROM calendarobjects WHERE principal = ? AND cal_id = ? AND deleted_at IS NULL",
|
"SELECT id, uid, ics FROM calendarobjects WHERE principal = ? AND cal_id = ? AND deleted_at IS NULL",
|
||||||
@@ -397,7 +398,7 @@ impl SqliteCalendarStore {
|
|||||||
principal: &str,
|
principal: &str,
|
||||||
cal_id: &str,
|
cal_id: &str,
|
||||||
query: CalendarQuery,
|
query: CalendarQuery,
|
||||||
) -> Result<Vec<CalendarObject>, Error> {
|
) -> Result<Vec<(String, CalendarObject)>, Error> {
|
||||||
// We extend our query interval by one day in each direction since we really don't want to
|
// We extend our query interval by one day in each direction since we really don't want to
|
||||||
// miss any objects because of timezone differences
|
// miss any objects because of timezone differences
|
||||||
// I've previously tried NaiveDate::MIN,MAX, but it seems like sqlite cannot handle these
|
// I've previously tried NaiveDate::MIN,MAX, but it seems like sqlite cannot handle these
|
||||||
@@ -433,7 +434,7 @@ impl SqliteCalendarStore {
|
|||||||
object_id: &str,
|
object_id: &str,
|
||||||
show_deleted: bool,
|
show_deleted: bool,
|
||||||
) -> Result<CalendarObject, Error> {
|
) -> Result<CalendarObject, Error> {
|
||||||
sqlx::query_as!(
|
let (row_id, object) = sqlx::query_as!(
|
||||||
CalendarObjectRow,
|
CalendarObjectRow,
|
||||||
"SELECT id, uid, ics FROM calendarobjects WHERE (principal, cal_id, id) = (?, ?, ?) AND ((deleted_at IS NULL) OR ?)",
|
"SELECT id, uid, ics FROM calendarobjects WHERE (principal, cal_id, id) = (?, ?, ?) AND ((deleted_at IS NULL) OR ?)",
|
||||||
principal,
|
principal,
|
||||||
@@ -444,7 +445,9 @@ impl SqliteCalendarStore {
|
|||||||
.fetch_one(executor)
|
.fetch_one(executor)
|
||||||
.await
|
.await
|
||||||
.map_err(crate::Error::from)?
|
.map_err(crate::Error::from)?
|
||||||
.try_into()
|
.try_into()?;
|
||||||
|
assert_eq!(object_id, row_id);
|
||||||
|
Ok(object)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument]
|
#[instrument]
|
||||||
@@ -452,23 +455,24 @@ impl SqliteCalendarStore {
|
|||||||
executor: E,
|
executor: E,
|
||||||
principal: &str,
|
principal: &str,
|
||||||
cal_id: &str,
|
cal_id: &str,
|
||||||
|
object_id: &str,
|
||||||
object: &CalendarObject,
|
object: &CalendarObject,
|
||||||
overwrite: bool,
|
overwrite: bool,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let (object_id, uid, ics) = (object.get_id(), object.get_uid(), object.get_ics());
|
let (uid, ics) = (object.get_uid(), object.get_ics());
|
||||||
|
|
||||||
let first_occurence = object
|
let first_occurence = object
|
||||||
|
.get_inner()
|
||||||
|
.get_inner()
|
||||||
.get_first_occurence()
|
.get_first_occurence()
|
||||||
.ok()
|
|
||||||
.flatten()
|
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(CalDateTime::date);
|
.map(CalDateTime::date_floor);
|
||||||
let last_occurence = object
|
let last_occurence = object
|
||||||
|
.get_inner()
|
||||||
|
.get_inner()
|
||||||
.get_last_occurence()
|
.get_last_occurence()
|
||||||
.ok()
|
|
||||||
.flatten()
|
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(CalDateTime::date);
|
.map(CalDateTime::date_ceil);
|
||||||
let etag = object.get_etag();
|
let etag = object.get_etag();
|
||||||
let object_type = object.get_object_type() as u8;
|
let object_type = object.get_object_type() as u8;
|
||||||
|
|
||||||
@@ -560,7 +564,7 @@ impl SqliteCalendarStore {
|
|||||||
principal: &str,
|
principal: &str,
|
||||||
cal_id: &str,
|
cal_id: &str,
|
||||||
synctoken: i64,
|
synctoken: i64,
|
||||||
) -> Result<(Vec<CalendarObject>, Vec<String>, i64), Error> {
|
) -> Result<(Vec<(String, CalendarObject)>, Vec<String>, i64), Error> {
|
||||||
struct Row {
|
struct Row {
|
||||||
object_id: String,
|
object_id: String,
|
||||||
synctoken: i64,
|
synctoken: i64,
|
||||||
@@ -587,7 +591,7 @@ impl SqliteCalendarStore {
|
|||||||
|
|
||||||
for Row { object_id, .. } in changes {
|
for Row { object_id, .. } in changes {
|
||||||
match Self::_get_object(&mut *conn, principal, cal_id, &object_id, false).await {
|
match Self::_get_object(&mut *conn, principal, cal_id, &object_id, false).await {
|
||||||
Ok(object) => objects.push(object),
|
Ok(object) => objects.push((object_id, object)),
|
||||||
Err(rustical_store::Error::NotFound) => deleted_objects.push(object_id),
|
Err(rustical_store::Error::NotFound) => deleted_objects.push(object_id),
|
||||||
Err(err) => return Err(err),
|
Err(err) => return Err(err),
|
||||||
}
|
}
|
||||||
@@ -627,8 +631,8 @@ impl CalendarStore for SqliteCalendarStore {
|
|||||||
#[instrument]
|
#[instrument]
|
||||||
async fn update_calendar(
|
async fn update_calendar(
|
||||||
&self,
|
&self,
|
||||||
principal: String,
|
principal: &str,
|
||||||
id: String,
|
id: &str,
|
||||||
calendar: Calendar,
|
calendar: Calendar,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
Self::_update_calendar(&self.db, principal, id, calendar).await
|
Self::_update_calendar(&self.db, principal, id, calendar).await
|
||||||
@@ -696,14 +700,23 @@ impl CalendarStore for SqliteCalendarStore {
|
|||||||
|
|
||||||
let mut sync_token = None;
|
let mut sync_token = None;
|
||||||
for object in objects {
|
for object in objects {
|
||||||
Self::_put_object(&mut *tx, &calendar.principal, &calendar.id, &object, false).await?;
|
let object_id = object.get_uid();
|
||||||
|
Self::_put_object(
|
||||||
|
&mut *tx,
|
||||||
|
&calendar.principal,
|
||||||
|
&calendar.id,
|
||||||
|
object_id,
|
||||||
|
&object,
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
sync_token = Some(
|
sync_token = Some(
|
||||||
Self::log_object_operation(
|
Self::log_object_operation(
|
||||||
&mut tx,
|
&mut tx,
|
||||||
&calendar.principal,
|
&calendar.principal,
|
||||||
&calendar.id,
|
&calendar.id,
|
||||||
object.get_id(),
|
object_id,
|
||||||
ChangeOperation::Add,
|
ChangeOperation::Add,
|
||||||
)
|
)
|
||||||
.await?,
|
.await?,
|
||||||
@@ -729,7 +742,7 @@ impl CalendarStore for SqliteCalendarStore {
|
|||||||
principal: &str,
|
principal: &str,
|
||||||
cal_id: &str,
|
cal_id: &str,
|
||||||
query: CalendarQuery,
|
query: CalendarQuery,
|
||||||
) -> Result<Vec<CalendarObject>, Error> {
|
) -> Result<Vec<(String, CalendarObject)>, Error> {
|
||||||
Self::_calendar_query(&self.db, principal, cal_id, query).await
|
Self::_calendar_query(&self.db, principal, cal_id, query).await
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -760,7 +773,7 @@ impl CalendarStore for SqliteCalendarStore {
|
|||||||
&self,
|
&self,
|
||||||
principal: &str,
|
principal: &str,
|
||||||
cal_id: &str,
|
cal_id: &str,
|
||||||
) -> Result<Vec<CalendarObject>, Error> {
|
) -> Result<Vec<(String, CalendarObject)>, Error> {
|
||||||
Self::_get_objects(&self.db, principal, cal_id).await
|
Self::_get_objects(&self.db, principal, cal_id).await
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -778,9 +791,9 @@ impl CalendarStore for SqliteCalendarStore {
|
|||||||
#[instrument]
|
#[instrument]
|
||||||
async fn put_objects(
|
async fn put_objects(
|
||||||
&self,
|
&self,
|
||||||
principal: String,
|
principal: &str,
|
||||||
cal_id: String,
|
cal_id: &str,
|
||||||
objects: Vec<CalendarObject>,
|
objects: Vec<(String, CalendarObject)>,
|
||||||
overwrite: bool,
|
overwrite: bool,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let mut tx = self
|
let mut tx = self
|
||||||
@@ -796,18 +809,21 @@ impl CalendarStore for SqliteCalendarStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut sync_token = None;
|
let mut sync_token = None;
|
||||||
for object in objects {
|
for (object_id, object) in objects {
|
||||||
sync_token = Some(
|
sync_token = Some(
|
||||||
Self::log_object_operation(
|
Self::log_object_operation(
|
||||||
&mut tx,
|
&mut tx,
|
||||||
&principal,
|
&principal,
|
||||||
&cal_id,
|
&cal_id,
|
||||||
object.get_id(),
|
&object_id,
|
||||||
ChangeOperation::Add,
|
ChangeOperation::Add,
|
||||||
)
|
)
|
||||||
.await?,
|
.await?,
|
||||||
);
|
);
|
||||||
Self::_put_object(&mut *tx, &principal, &cal_id, &object, overwrite).await?;
|
Self::_put_object(
|
||||||
|
&mut *tx, &principal, &cal_id, &object_id, &object, overwrite,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
tx.commit().await.map_err(crate::Error::from)?;
|
tx.commit().await.map_err(crate::Error::from)?;
|
||||||
@@ -885,7 +901,7 @@ impl CalendarStore for SqliteCalendarStore {
|
|||||||
principal: &str,
|
principal: &str,
|
||||||
cal_id: &str,
|
cal_id: &str,
|
||||||
synctoken: i64,
|
synctoken: i64,
|
||||||
) -> Result<(Vec<CalendarObject>, Vec<String>, i64), Error> {
|
) -> Result<(Vec<(String, CalendarObject)>, Vec<String>, i64), Error> {
|
||||||
Self::_sync_changes(&self.db, principal, cal_id, synctoken).await
|
Self::_sync_changes(&self.db, principal, cal_id, synctoken).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ use tower::ServiceExt;
|
|||||||
|
|
||||||
mod calendar;
|
mod calendar;
|
||||||
mod calendar_import;
|
mod calendar_import;
|
||||||
mod calendar_report;
|
// mod calendar_report;
|
||||||
|
|
||||||
#[rstest]
|
#[rstest]
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
|||||||
@@ -4,9 +4,10 @@ expression: body
|
|||||||
---
|
---
|
||||||
BEGIN:VCALENDAR
|
BEGIN:VCALENDAR
|
||||||
VERSION:2.0
|
VERSION:2.0
|
||||||
|
PRODID:RustiCal Export
|
||||||
CALSCALE:GREGORIAN
|
CALSCALE:GREGORIAN
|
||||||
PRODID:RustiCal
|
|
||||||
X-WR-CALNAME:Calendar
|
X-WR-CALNAME:Calendar
|
||||||
X-WR-CALDESC:Description
|
X-WR-CALDESC:Description
|
||||||
|
X-WR-CALCOLOR:#00FF00
|
||||||
X-WR-TIMEZONE:US/Eastern
|
X-WR-TIMEZONE:US/Eastern
|
||||||
END:VCALENDAR
|
END:VCALENDAR
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ expression: body
|
|||||||
---
|
---
|
||||||
BEGIN:VCALENDAR
|
BEGIN:VCALENDAR
|
||||||
VERSION:2.0
|
VERSION:2.0
|
||||||
|
PRODID:RustiCal Export
|
||||||
CALSCALE:GREGORIAN
|
CALSCALE:GREGORIAN
|
||||||
PRODID:RustiCal
|
|
||||||
BEGIN:VEVENT
|
BEGIN:VEVENT
|
||||||
UID:[UID]
|
UID:[UID]
|
||||||
SUMMARY:One-off Meeting
|
SUMMARY:One-off Meeting
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ expression: body
|
|||||||
---
|
---
|
||||||
BEGIN:VCALENDAR
|
BEGIN:VCALENDAR
|
||||||
VERSION:2.0
|
VERSION:2.0
|
||||||
|
PRODID:RustiCal Export
|
||||||
CALSCALE:GREGORIAN
|
CALSCALE:GREGORIAN
|
||||||
PRODID:RustiCal
|
|
||||||
BEGIN:VTIMEZONE
|
BEGIN:VTIMEZONE
|
||||||
LAST-MODIFIED:20040110T032845Z
|
LAST-MODIFIED:20040110T032845Z
|
||||||
TZID:US/Eastern
|
TZID:US/Eastern
|
||||||
@@ -29,7 +29,7 @@ DTSTAMP:20060206T001102Z
|
|||||||
DTSTART;TZID=US/Eastern:20060102T100000
|
DTSTART;TZID=US/Eastern:20060102T100000
|
||||||
DURATION:PT1H
|
DURATION:PT1H
|
||||||
SUMMARY:Event #1
|
SUMMARY:Event #1
|
||||||
Description:Go Steelers!
|
DESCRIPTION:Go Steelers!
|
||||||
UID:[UID]
|
UID:[UID]
|
||||||
END:VEVENT
|
END:VEVENT
|
||||||
BEGIN:VEVENT
|
BEGIN:VEVENT
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ expression: body
|
|||||||
<href>/carddav/principal/user/contacts/newcard.vcf</href>
|
<href>/carddav/principal/user/contacts/newcard.vcf</href>
|
||||||
<propstat>
|
<propstat>
|
||||||
<prop>
|
<prop>
|
||||||
<getetag>"24835b6c11816c864f9edadd4c7c296234c643892afcbbc5fbf5c9b7ac935cf8"</getetag>
|
<getetag>"ea0bf4a2ce7ef84606a4cf9235776dbc11b3e7ce351ddf35f27cbc0088acca7e"</getetag>
|
||||||
<CARD:address-data>BEGIN:VCARD
|
<CARD:address-data>BEGIN:VCARD
|
||||||
VERSION:3.0
|
VERSION:3.0
|
||||||
FN:Cyrus Daboo
|
FN:Cyrus Daboo
|
||||||
|
|||||||
Reference in New Issue
Block a user