From 177491808446e80dd383619b502f24687ea7826e Mon Sep 17 00:00:00 2001 From: John Coffey Date: Thu, 12 Nov 2026 09:13:47 -0700 Subject: [PATCH] estimate: size CalDAV and CardDAV items too The item PROPFIND the dry run already does now asks for getcontentlength as well, which the parser already reads, so --estimate can size calendar events and contact cards at no extra request -- rounding out real sizes to mail, calendars and contacts. A server that omits the length leaves those items unsized; WebDAV files stay on the dry-run fallback, where the file count is reported differently. --- README.md | 5 +++-- src/cli.rs | 20 ++++++++++++------- src/dav/xml.rs | 8 ++++++++ src/main.rs | 2 +- src/sync/import_dav/coordinator.rs | 32 +++++++++++++++++++++++------- 5 files changed, 50 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 997fbaf..492425a 100644 --- a/README.md +++ b/README.md @@ -38,8 +38,9 @@ later `import` into the same archive adds what arrived since. Every command takes `--dry-run` and then only reports the plan. An `import` also takes `--estimate`, which connects to the source and reports how much is new to fetch — counts, bytes and a rough time — before committing, and writes -nothing. It reports sizes for `imap` and `maildir`; other sources fall back to -a plain dry-run. `inspect` reads an archive and changes nothing. +nothing. It reports sizes for `imap`, `maildir`, `caldav` and `carddav`; other +sources fall back to a plain dry-run. `inspect` reads an archive and changes +nothing. The archive is also a backup. Import on a schedule, keep the file, and restore it later with `export`. An archive remembers which account filled it diff --git a/src/cli.rs b/src/cli.rs index 33c8cfd..1a4f4e9 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -156,8 +156,9 @@ struct GlobalArgs { help = "Preview an import: counts, sizes and a rough time, before any writes", long_help = "Preview an import before committing: for each type, how much is new since \ the archive was last filled, how many bytes that is, and a rough time.\n \ - Available for imap and maildir today; other sources fall back to --dry-run with a \ - note. It implies --dry-run, so it never writes. On an export it is just --dry-run." + Available for imap, maildir, caldav and carddav today; other sources fall back to \ + --dry-run with a note. It implies --dry-run, so it never writes. On an export it is \ + just --dry-run." )] estimate: bool, @@ -918,14 +919,19 @@ impl Action { } /// Whether this import can give the size-and-time estimate: the source - /// enumerates messages in its dry run and can size them cheaply. The + /// enumerates its items in its dry run and can size them cheaply. The /// others fall back to a plain dry run with a note; adding them is /// per-source follow-up work. pub fn estimate_available(&self) -> bool { - matches!( - self, - Action::ImportImap(c, _) | Action::ImportMaildir(c, _) if c.estimate - ) + match self { + Action::ImportImap(c, _) | Action::ImportMaildir(c, _) => c.estimate, + // CalDAV and CardDAV size their items from the getcontentlength + // the enumeration PROPFIND already returns. WebDAV files go + // through the same command but report differently, so they stay + // on the fallback for now. + Action::ImportDav(c, cfg) => c.estimate && !matches!(cfg.kind, DavKindArg::Webdav), + _ => false, + } } } diff --git a/src/dav/xml.rs b/src/dav/xml.rs index d3fe210..0c57652 100644 --- a/src/dav/xml.rs +++ b/src/dav/xml.rs @@ -122,6 +122,7 @@ pub fn propfind_dav_items() -> String { \ \ \ + \ \ \ ", @@ -305,4 +306,11 @@ mod tests { assert!(body.contains("")); assert!(body.contains("")); } + + #[test] + fn dav_items_request_a_content_length_so_estimate_can_size_them() { + let body = propfind_dav_items(); + assert!(body.contains("")); + assert!(body.contains("")); + } } diff --git a/src/main.rs b/src/main.rs index 65debcb..bffdb9f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -35,7 +35,7 @@ fn run() -> i32 { if action.estimate_requested() && !do_estimate { eprintln!( "note: --estimate isn't available for this source yet; running --dry-run instead \ - (its plan is below). Estimates work for imap and maildir today." + (its plan is below). Estimates work for imap, maildir, caldav and carddav today." ); } let mut quiet_report = false; diff --git a/src/sync/import_dav/coordinator.rs b/src/sync/import_dav/coordinator.rs index ad2e67a..fa02e4e 100644 --- a/src/sync/import_dav/coordinator.rs +++ b/src/sync/import_dav/coordinator.rs @@ -173,7 +173,15 @@ fn run_into( ); } } - let result = run_dry_diff(&conn, &client, &discovery, &config, logger, summary); + let result = run_dry_diff( + &conn, + &client, + &discovery, + &config, + common.estimate, + logger, + summary, + ); summary.retries_observed = client.retries_observed(); summary.retry_after_sleeps = client.retry_after_sleeps(); return result; @@ -340,6 +348,7 @@ fn run_dry_diff( client: &DavClient, discovery: &Discovery, config: &DavImportConfig, + want_sizes: bool, logger: Logger, summary: &mut Summary, ) -> Result<(), Error> { @@ -387,12 +396,21 @@ fn run_dry_diff( .map_err(super::per_collection_failure) { Ok(ms) => { - let new_count = ms - .responses - .iter() - .filter(|r| !r.props.is_collection) - .count(); - item_counts.created += new_count as u64; + let mut new_count = 0u64; + let mut bytes = 0u64; + for r in ms.responses.iter().filter(|r| !r.props.is_collection) { + new_count += 1; + // --estimate: getcontentlength comes back in the same + // PROPFIND, so sizing the items costs no extra request. + // A server that omits it leaves those items unsized. + if let Some(n) = r.props.content_length { + bytes += n; + } + } + item_counts.created += new_count; + if want_sizes { + item_counts.bytes += bytes; + } if logger.enabled(LEVEL_DEFAULT) { eprintln!(" {} items: {new_count}", coll.href.as_str()); } -- 2.54.0