Compare commits

...

6 Commits

Author SHA1 Message Date
Lennart K
c763a682ed update .gitignore 2026-01-27 23:07:19 +01:00
Lennart K
8ab9c61b0f Move commands to lib.rs 2026-01-27 23:06:57 +01:00
Lennart
8b2bb1b0d6 docs: Mention NixOS package 2026-01-26 12:20:04 +01:00
Lennart
da72aa26cb update README.md 2026-01-24 22:53:51 +01:00
Lennart
b89ff1a2b5 version 0.12.3 2026-01-24 22:49:02 +01:00
Lennart
246a1aa738 Add truncation for automatically derived timezones 2026-01-24 22:48:08 +01:00
15 changed files with 234 additions and 186 deletions

2
.gitignore vendored
View File

@@ -3,7 +3,7 @@ crates/*/target
# For libraries ignore Cargo.lock
crates/*/Cargo.lock
db.sqlite3*
**/*.sqlite3*
config.toml
principals.toml

28
Cargo.lock generated
View File

@@ -567,9 +567,9 @@ checksum = "b35204fbdc0b3f4446b89fc1ac2cf84a8a68971995d0bf2e925ec7cd960f9cb3"
[[package]]
name = "caldata"
version = "0.13.1"
version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5549ae654c8e80ff922297ad06c49be64668cf947cb6ce45a2069985d21a2135"
checksum = "f36de4a8034d98c95e7fe874b828272d823cfbd68e9571fe7bf6c419e852cbe2"
dependencies = [
"chrono",
"chrono-tz",
@@ -3309,7 +3309,7 @@ dependencies = [
[[package]]
name = "rustical"
version = "0.12.2"
version = "0.12.3"
dependencies = [
"anyhow",
"argon2",
@@ -3356,7 +3356,7 @@ dependencies = [
[[package]]
name = "rustical_caldav"
version = "0.12.2"
version = "0.12.3"
dependencies = [
"async-std",
"async-trait",
@@ -3398,7 +3398,7 @@ dependencies = [
[[package]]
name = "rustical_carddav"
version = "0.12.2"
version = "0.12.3"
dependencies = [
"async-trait",
"axum",
@@ -3432,7 +3432,7 @@ dependencies = [
[[package]]
name = "rustical_dav"
version = "0.12.2"
version = "0.12.3"
dependencies = [
"async-trait",
"axum",
@@ -3458,7 +3458,7 @@ dependencies = [
[[package]]
name = "rustical_dav_push"
version = "0.12.2"
version = "0.12.3"
dependencies = [
"async-trait",
"axum",
@@ -3483,7 +3483,7 @@ dependencies = [
[[package]]
name = "rustical_frontend"
version = "0.12.2"
version = "0.12.3"
dependencies = [
"askama",
"askama_web",
@@ -3519,7 +3519,7 @@ dependencies = [
[[package]]
name = "rustical_ical"
version = "0.12.2"
version = "0.12.3"
dependencies = [
"axum",
"caldata",
@@ -3538,7 +3538,7 @@ dependencies = [
[[package]]
name = "rustical_oidc"
version = "0.12.2"
version = "0.12.3"
dependencies = [
"async-trait",
"axum",
@@ -3554,7 +3554,7 @@ dependencies = [
[[package]]
name = "rustical_store"
version = "0.12.2"
version = "0.12.3"
dependencies = [
"anyhow",
"async-trait",
@@ -3587,7 +3587,7 @@ dependencies = [
[[package]]
name = "rustical_store_sqlite"
version = "0.12.2"
version = "0.12.3"
dependencies = [
"async-trait",
"caldata",
@@ -3612,7 +3612,7 @@ dependencies = [
[[package]]
name = "rustical_xml"
version = "0.12.2"
version = "0.12.3"
dependencies = [
"quick-xml",
"thiserror 2.0.18",
@@ -5434,7 +5434,7 @@ checksum = "9edde0db4769d2dc68579893f2306b26c6ecfbe0ef499b013d731b7b9247e0b9"
[[package]]
name = "xml_derive"
version = "0.12.2"
version = "0.12.3"
dependencies = [
"darling 0.23.0",
"heck",

View File

@@ -2,7 +2,7 @@
members = ["crates/*"]
[workspace.package]
version = "0.12.2"
version = "0.12.3"
rust-version = "1.92"
edition = "2024"
description = "A CalDAV server"
@@ -35,6 +35,12 @@ opentelemetry = [
[profile.dev]
debug = 0
[lib]
doc = true
name = "rustical"
path = "src/lib.rs"
test = true
[workspace.dependencies]
rustical_dav = { path = "./crates/dav/", features = ["ical"] }
rustical_dav_push = { path = "./crates/dav_push/" }
@@ -107,7 +113,7 @@ strum = "0.27"
strum_macros = "0.27"
serde_json = { version = "1.0", features = ["raw_value"] }
sqlx-sqlite = { version = "0.8", features = ["bundled"] }
caldata = { version = "0.13.0", features = ["chrono-tz", "vtimezones-rs"] }
caldata = { version = "0.14.0", features = ["chrono-tz", "vtimezones-rs"] }
toml = "0.9"
tower = "0.5"
tower-http = { version = "0.6", features = [

View File

@@ -24,6 +24,7 @@ a CalDAV/CardDAV server
- Apple configuration profiles (skip copy-pasting passwords and instead generate the configuration in the frontend)
- **OpenID Connect** support (with option to disable password login)
- Group-based **sharing**
- Partial [RFC 7809](https://datatracker.ietf.org/doc/html/rfc7809) support. RustiCal will accept timezones by reference and handle omitted timezones in objects.
## Getting Started

View File

@@ -4,8 +4,8 @@ use axum::{
extract::{Path, State},
response::{IntoResponse, Response},
};
use caldata::IcalParser;
use caldata::component::{Component, ComponentMut};
use caldata::{IcalParser, parser::ParserOptions};
use http::StatusCode;
use rustical_dav::header::Overwrite;
use rustical_ical::CalendarObjectType;
@@ -50,7 +50,7 @@ pub async fn route_import<C: CalendarStore, S: SubscriptionStore>(
cal.remove_property("X-WR-CALDESC");
cal.remove_property("X-WR-CALCOLOR");
cal.remove_property("X-WR-TIMEZONE");
let cal = cal.build(None).unwrap();
let cal = cal.build(&ParserOptions::default(), None).unwrap();
// Make sure timezone is valid
if let Some(timezone_id) = timezone_id.as_ref() {

View File

@@ -7,7 +7,7 @@ use axum::{
use caldata::{
VcardParser,
component::{Component, ComponentMut},
parser::ContentLine,
parser::{ContentLine, ParserOptions},
};
use http::StatusCode;
use rustical_store::{Addressbook, AddressbookStore, SubscriptionStore, auth::Principal};
@@ -37,7 +37,7 @@ pub async fn route_import<AS: AddressbookStore, S: SubscriptionStore>(
value: Some(uuid::Uuid::new_v4().to_string()),
params: vec![].into(),
});
card = card_mut.build(None).unwrap();
card = card_mut.build(&ParserOptions::default(), None).unwrap();
}
// TODO: Make nicer
let uid = card.get_uid().unwrap();

View File

@@ -6,7 +6,7 @@ use caldata::{
IcalEventBuilder, VcardContact,
},
generator::Emitter,
parser::ContentLine,
parser::{ContentLine, ParserOptions},
property::{
Calscale, IcalCALSCALEProperty, IcalDTENDProperty, IcalDTSTAMPProperty,
IcalDTSTARTProperty, IcalPRODIDProperty, IcalRRULEProperty, IcalSUMMARYProperty,
@@ -136,7 +136,7 @@ impl AddressObject {
inner: Some(CalendarInnerDataBuilder::Event(vec![event])),
vtimezones: BTreeMap::default(),
}
.build(None)?
.build(&ParserOptions::default(), None)?
.into(),
))
}

View File

@@ -48,3 +48,26 @@ Since the app tokens are random they use the faster `pbkdf2` algorithm.
```sh
cargo install --locked --git https://github.com/lennart-k/rustical
```
## NixOS (community-maintained by [@PopeRigby](https://github.com/PopeRigby))
!!! warning
The NixOS package is not maintained by myself but since I appreciate [@PopeRigby](https://github.com/PopeRigby)'s work on it I want to mention it.
Since rustical's development is still quite active I **strongly** recommend installing from the `nixpkgs-unstable` branch.
In the `nixpkgs-unstable` you'll find a `rustical` package you can install.
There's also a service that has not been merged yet. If you know how to add modules from PRs in Nix
you can already install it <https://github.com/NixOS/nixpkgs/pull/424188>
and then setup rustical as a service:
```nix title="In your configuration.nix"
services.rustical = {
enable = true;
package = inputs.rustical.legacyPackages.${pkgs.stdenv.hostPlatform.system}.rustical;
settings = {
# Settings the same as in config.toml but in Nix syntax
# http.port = 3002;
};
};
```

View File

@@ -32,7 +32,8 @@ use tracing::field::display;
#[allow(
clippy::too_many_arguments,
clippy::too_many_lines,
clippy::cognitive_complexity
clippy::cognitive_complexity,
clippy::missing_panics_doc
)]
pub fn make_app<
AS: AddressbookStore + PrefixedCalendarStore,
@@ -109,9 +110,9 @@ pub fn make_app<
options(async || {
let mut resp = Response::builder().status(StatusCode::OK);
resp.headers_mut()
.unwrap()
.expect("this always works")
.insert("DAV", HeaderValue::from_static("1"));
resp.body(Body::empty()).unwrap()
resp.body(Body::empty()).expect("empty body always works")
}),
);

View File

@@ -7,6 +7,7 @@ pub struct HealthArgs {}
/// Healthcheck for running rustical instance
/// Currently just pings to see if it's reachable via HTTP
#[allow(clippy::missing_errors_doc, clippy::missing_panics_doc)]
pub async fn cmd_health(http_config: HttpConfig, _health_args: HealthArgs) -> anyhow::Result<()> {
let client = reqwest::ClientBuilder::new().build().unwrap();

View File

@@ -33,7 +33,8 @@ pub struct MembershipArgs {
command: MembershipCommand,
}
pub async fn handle_membership_command(
#[allow(clippy::missing_errors_doc, clippy::missing_panics_doc)]
pub async fn cmd_membership(
user_store: &impl AuthenticationProvider,
MembershipArgs { command }: MembershipArgs,
) -> anyhow::Result<()> {

View File

@@ -6,13 +6,17 @@ use clap::Parser;
use rustical_caldav::CalDavConfig;
use rustical_frontend::FrontendConfig;
pub mod health;
mod health;
pub mod membership;
pub mod principals;
mod principals;
pub use health::{HealthArgs, cmd_health};
pub use principals::{PrincipalsArgs, cmd_principals};
#[derive(Debug, Parser)]
pub struct GenConfigArgs {}
#[allow(clippy::missing_errors_doc, clippy::missing_panics_doc)]
pub fn cmd_gen_config(_args: GenConfigArgs) -> anyhow::Result<()> {
let config = Config {
http: HttpConfig::default(),

View File

@@ -1,5 +1,5 @@
use super::membership::{MembershipArgs, handle_membership_command};
use crate::{config::Config, get_data_stores};
use super::membership::MembershipArgs;
use crate::{config::Config, get_data_stores, membership::cmd_membership};
use clap::{Parser, Subcommand};
use figment::{
Figment,
@@ -58,6 +58,7 @@ enum Command {
Membership(MembershipArgs),
}
#[allow(clippy::missing_errors_doc, clippy::missing_panics_doc)]
pub async fn cmd_principals(args: PrincipalsArgs) -> anyhow::Result<()> {
let config: Config = Figment::new()
.merge(Toml::file(&args.config_file))
@@ -152,7 +153,7 @@ pub async fn cmd_principals(args: PrincipalsArgs) -> anyhow::Result<()> {
println!("Principal {id} updated");
}
Command::Membership(args) => {
handle_membership_command(principal_store.as_ref(), args).await?;
cmd_membership(principal_store.as_ref(), args).await?;
}
}
Ok(())

155
src/lib.rs Normal file
View File

@@ -0,0 +1,155 @@
#![warn(clippy::all, clippy::pedantic, clippy::nursery)]
use crate::config::Config;
use anyhow::Result;
use app::make_app;
use axum::ServiceExt;
use axum::extract::Request;
use clap::{Parser, Subcommand};
use config::{DataStoreConfig, SqliteDataStoreConfig};
use rustical_dav_push::DavPushController;
use rustical_store::auth::AuthenticationProvider;
use rustical_store::{
AddressbookStore, CalendarStore, CollectionOperation, PrefixedCalendarStore, SubscriptionStore,
};
use rustical_store_sqlite::addressbook_store::SqliteAddressbookStore;
use rustical_store_sqlite::calendar_store::SqliteCalendarStore;
use rustical_store_sqlite::principal_store::SqlitePrincipalStore;
use rustical_store_sqlite::{SqliteStore, create_db_pool};
use setup_tracing::setup_tracing;
use std::sync::Arc;
use tokio::sync::mpsc::Receiver;
use tower::Layer;
use tower_http::normalize_path::NormalizePathLayer;
use tracing::{info, warn};
pub mod app;
mod commands;
pub use commands::*;
pub mod config;
#[cfg(test)]
pub mod integration_tests;
mod setup_tracing;
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
pub struct Args {
#[arg(short, long, env, default_value = "/etc/rustical/config.toml")]
pub config_file: String,
#[arg(long, env, help = "Do no run database migrations (only for sql store)")]
pub no_migrations: bool,
#[command(subcommand)]
pub command: Option<Command>,
}
#[derive(Debug, Subcommand)]
pub enum Command {
GenConfig(commands::GenConfigArgs),
Principals(PrincipalsArgs),
#[command(
about = "Healthcheck for running instance (Used for HEALTHCHECK in Docker container)"
)]
Health(HealthArgs),
}
#[allow(clippy::missing_errors_doc)]
pub async fn get_data_stores(
migrate: bool,
config: &DataStoreConfig,
) -> Result<(
Arc<impl AddressbookStore + PrefixedCalendarStore>,
Arc<impl CalendarStore>,
Arc<impl SubscriptionStore>,
Arc<impl AuthenticationProvider>,
Receiver<CollectionOperation>,
)> {
Ok(match &config {
DataStoreConfig::Sqlite(SqliteDataStoreConfig {
db_url,
run_repairs,
skip_broken,
}) => {
let db = create_db_pool(db_url, migrate).await?;
// Channel to watch for changes (for DAV Push)
let (send, recv) = tokio::sync::mpsc::channel(1000);
let addressbook_store = Arc::new(SqliteAddressbookStore::new(
db.clone(),
send.clone(),
*skip_broken,
));
let cal_store = Arc::new(SqliteCalendarStore::new(db.clone(), send, *skip_broken));
if *run_repairs {
info!("Running repair tasks");
addressbook_store.repair_orphans().await?;
cal_store.repair_invalid_version_4_0().await?;
cal_store.repair_orphans().await?;
}
let subscription_store = Arc::new(SqliteStore::new(db.clone()));
let principal_store = Arc::new(SqlitePrincipalStore::new(db));
// Validate all calendar objects
for principal in principal_store.get_principals().await? {
cal_store.validate_objects(&principal.id).await?;
addressbook_store.validate_objects(&principal.id).await?;
}
(
addressbook_store,
cal_store,
subscription_store,
principal_store,
recv,
)
}
})
}
#[allow(clippy::missing_errors_doc, clippy::missing_panics_doc)]
pub async fn cmd_default(args: Args, config: Config) -> Result<()> {
setup_tracing(&config.tracing);
let (addr_store, cal_store, subscription_store, principal_store, update_recv) =
get_data_stores(!args.no_migrations, &config.data_store).await?;
let mut tasks = vec![];
if config.dav_push.enabled {
let dav_push_controller = DavPushController::new(
config.dav_push.allowed_push_servers,
subscription_store.clone(),
);
tasks.push(tokio::spawn(async move {
dav_push_controller.notifier(update_recv).await;
}));
}
let app = make_app(
addr_store.clone(),
cal_store.clone(),
subscription_store.clone(),
principal_store.clone(),
config.frontend.clone(),
config.oidc.clone(),
config.caldav,
&config.nextcloud_login,
config.dav_push.enabled,
config.http.session_cookie_samesite_strict,
config.http.payload_limit_mb,
);
let app = ServiceExt::<Request>::into_make_service(
NormalizePathLayer::trim_trailing_slash().layer(app),
);
let address = format!("{}:{}", config.http.host, config.http.port);
let listener = tokio::net::TcpListener::bind(&address).await?;
tasks.push(tokio::spawn(async move {
info!("RustiCal serving on http://{address}");
axum::serve(listener, app).await.unwrap();
}));
for task in tasks {
task.await?;
}
Ok(())
}

View File

@@ -1,112 +1,12 @@
#![warn(clippy::all, clippy::pedantic, clippy::nursery)]
use crate::commands::health::{HealthArgs, cmd_health};
use crate::config::Config;
use anyhow::Result;
use app::make_app;
use axum::ServiceExt;
use axum::extract::Request;
use clap::{Parser, Subcommand};
use commands::cmd_gen_config;
use commands::principals::{PrincipalsArgs, cmd_principals};
use config::{DataStoreConfig, SqliteDataStoreConfig};
use clap::Parser;
use figment::Figment;
use figment::providers::{Env, Format, Toml};
use rustical_dav_push::DavPushController;
use rustical_store::auth::AuthenticationProvider;
use rustical_store::{
AddressbookStore, CalendarStore, CollectionOperation, PrefixedCalendarStore, SubscriptionStore,
};
use rustical_store_sqlite::addressbook_store::SqliteAddressbookStore;
use rustical_store_sqlite::calendar_store::SqliteCalendarStore;
use rustical_store_sqlite::principal_store::SqlitePrincipalStore;
use rustical_store_sqlite::{SqliteStore, create_db_pool};
use setup_tracing::setup_tracing;
use std::sync::Arc;
use tokio::sync::mpsc::Receiver;
use tower::Layer;
use tower_http::normalize_path::NormalizePathLayer;
use tracing::{info, warn};
mod app;
mod commands;
mod config;
#[cfg(test)]
pub mod integration_tests;
mod setup_tracing;
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Args {
#[arg(short, long, env, default_value = "/etc/rustical/config.toml")]
config_file: String,
#[arg(long, env, help = "Do no run database migrations (only for sql store)")]
no_migrations: bool,
#[command(subcommand)]
command: Option<Command>,
}
#[derive(Debug, Subcommand)]
enum Command {
GenConfig(commands::GenConfigArgs),
Principals(PrincipalsArgs),
#[command(
about = "Healthcheck for running instance (Used for HEALTHCHECK in Docker container)"
)]
Health(HealthArgs),
}
async fn get_data_stores(
migrate: bool,
config: &DataStoreConfig,
) -> Result<(
Arc<impl AddressbookStore + PrefixedCalendarStore>,
Arc<impl CalendarStore>,
Arc<impl SubscriptionStore>,
Arc<impl AuthenticationProvider>,
Receiver<CollectionOperation>,
)> {
Ok(match &config {
DataStoreConfig::Sqlite(SqliteDataStoreConfig {
db_url,
run_repairs,
skip_broken,
}) => {
let db = create_db_pool(db_url, migrate).await?;
// Channel to watch for changes (for DAV Push)
let (send, recv) = tokio::sync::mpsc::channel(1000);
let addressbook_store = Arc::new(SqliteAddressbookStore::new(
db.clone(),
send.clone(),
*skip_broken,
));
let cal_store = Arc::new(SqliteCalendarStore::new(db.clone(), send, *skip_broken));
if *run_repairs {
info!("Running repair tasks");
addressbook_store.repair_orphans().await?;
cal_store.repair_invalid_version_4_0().await?;
cal_store.repair_orphans().await?;
}
let subscription_store = Arc::new(SqliteStore::new(db.clone()));
let principal_store = Arc::new(SqlitePrincipalStore::new(db));
// Validate all calendar objects
for principal in principal_store.get_principals().await? {
cal_store.validate_objects(&principal.id).await?;
addressbook_store.validate_objects(&principal.id).await?;
}
(
addressbook_store,
cal_store,
subscription_store,
principal_store,
recv,
)
}
})
}
use rustical::config::Config;
use rustical::{Args, Command};
use rustical::{cmd_default, cmd_gen_config, cmd_health, cmd_principals};
use tracing::warn;
#[tokio::main(flavor = "multi_thread")]
async fn main() -> Result<()> {
@@ -120,60 +20,15 @@ async fn main() -> Result<()> {
};
match args.command {
Some(Command::GenConfig(gen_config_args)) => cmd_gen_config(gen_config_args)?,
Some(Command::Principals(principals_args)) => cmd_principals(principals_args).await?,
Some(Command::GenConfig(gen_config_args)) => cmd_gen_config(gen_config_args),
Some(Command::Principals(principals_args)) => cmd_principals(principals_args).await,
Some(Command::Health(health_args)) => {
let config: Config = parse_config()?;
cmd_health(config.http, health_args).await?;
cmd_health(config.http, health_args).await
}
None => {
let config: Config = parse_config()?;
setup_tracing(&config.tracing);
let (addr_store, cal_store, subscription_store, principal_store, update_recv) =
get_data_stores(!args.no_migrations, &config.data_store).await?;
let mut tasks = vec![];
if config.dav_push.enabled {
let dav_push_controller = DavPushController::new(
config.dav_push.allowed_push_servers,
subscription_store.clone(),
);
tasks.push(tokio::spawn(async move {
dav_push_controller.notifier(update_recv).await;
}));
}
let app = make_app(
addr_store.clone(),
cal_store.clone(),
subscription_store.clone(),
principal_store.clone(),
config.frontend.clone(),
config.oidc.clone(),
config.caldav,
&config.nextcloud_login,
config.dav_push.enabled,
config.http.session_cookie_samesite_strict,
config.http.payload_limit_mb,
);
let app = ServiceExt::<Request>::into_make_service(
NormalizePathLayer::trim_trailing_slash().layer(app),
);
let address = format!("{}:{}", config.http.host, config.http.port);
let listener = tokio::net::TcpListener::bind(&address).await?;
tasks.push(tokio::spawn(async move {
info!("RustiCal serving on http://{address}");
axum::serve(listener, app).await.unwrap();
}));
for task in tasks {
task.await?;
}
cmd_default(args, config).await
}
}
Ok(())
}