Skip to content

Native iCloud apps for Windows and Linux, built in Rust. Notes, Reminders, Calendar, Contacts, Drive and Photos, offline and in sync with your iPhone.

Calendar: 'all events' from one occurrence — the series keeps its own dates, moved as far as the occurrence was, every occurrence changed; its repeat and alerts matched to the series, not the occurrence, so the series still repeats — verified live

Yashwanth Kamireddi457ddf60ff27
diff --git a/crates/quince-icloud/src/calendar.rs b/crates/quince-icloud/src/calendar.rs
index b89501c..a4d8fd8 100644
--- a/crates/quince-icloud/src/calendar.rs
+++ b/crates/quince-icloud/src/calendar.rs
@@ -319,6 +319,25 @@ fn minutes_of(m: &Value) -> Option<i64> {
pub enum Scope {
/// This one alone; the rest of the series as it was.
This,
+ /// The whole series: what changed here — and, if this occurrence was moved, the series
+ /// moved by as much — every occurrence, past and future.
+ All,
+}
+
+/// The series an occurrence's id belongs to — `<series>__<start>` — or the id itself.
+#[must_use]
+pub fn series_of(guid: &str) -> &str {
+ guid.split("__").next().unwrap_or(guid)
+}
+
+/// Whether an `Alarm` or `Recurrence` object Apple holds belongs to this event. Its `pGuid` is
+/// the series' id, not an occurrence's: matching it against an occurrence's id left the repeat
+/// out of an "all events" save, and Apple took the series as no longer repeating.
+fn belongs_to(object: &Value, event_guid: &str) -> bool {
+ object
+ .get("pGuid")
+ .and_then(Value::as_str)
+ .is_some_and(|p| p == event_guid || p == series_of(event_guid))
}
/// Whether `guid` names one occurrence of a repeating event rather than an event: Apple gives
@@ -442,6 +461,46 @@ impl<'a> CalendarClient<'a> {
// edited here came back a one-off with no alerts and no guests.
let detail = self.event_detail_body(event, &day).await?;
let existing = detail.as_ref().and_then(event_of);
+ // For the whole series from one of its occurrences, the series keeps its own dates —
+ // icloud.com sends the master's start and end — moved by however far this occurrence
+ // was moved here, so dragging Tuesday's 10:00 to 11:00 moves every one to 11:00.
+ let shifted;
+ let event = match (scope, existing.as_ref()) {
+ (Some(Scope::All), Some(found))
+ if occurrence && found.get("recurrenceMaster") != Some(&Value::Bool(true)) =>
+ {
+ let dates = dates_zone(event.all_day, event.timezone.as_deref());
+ let was = found
+ .get("startDate")
+ .map(|d| parse_apple_date(d, dates.as_deref()))
+ .transpose()?;
+ let master_start = found
+ .get("masterStartDate")
+ .map(|d| parse_apple_date(d, dates.as_deref()))
+ .transpose()?;
+ let master_end = found
+ .get("masterEndDate")
+ .map(|d| parse_apple_date(d, dates.as_deref()))
+ .transpose()?;
+ match (was, master_start, master_end) {
+ (Some(was), Some(ms), Some(me)) => {
+ let moved = event.starts_at - was;
+ let mut e = event.clone();
+ e.starts_at = ms + moved;
+ e.ends_at = me + moved + ((event.ends_at - event.starts_at) - (me - ms));
+ shifted = e;
+ &shifted
+ }
+ _ => {
+ return Err(Error::Refused(
+ "Apple did not say where this series begins, so nothing was changed."
+ .into(),
+ ))
+ }
+ }
+ }
+ _ => event,
+ };
let mut event_value = self.event_body(event, existing.as_ref());
let held: Vec<Value> = detail
.as_ref()
@@ -449,7 +508,7 @@ impl<'a> CalendarClient<'a> {
.and_then(Value::as_array)
.map(|all| {
all.iter()
- .filter(|a| a.get("pGuid").and_then(Value::as_str) == Some(event.guid.as_str()))
+ .filter(|a| belongs_to(a, &event.guid))
.cloned()
.collect()
})
@@ -485,7 +544,7 @@ impl<'a> CalendarClient<'a> {
.and_then(Value::as_array)
.map(|all| {
all.iter()
- .filter(|r| r.get("pGuid").and_then(Value::as_str) == Some(event.guid.as_str()))
+ .filter(|r| belongs_to(r, &event.guid))
.cloned()
.collect()
})
@@ -515,12 +574,19 @@ impl<'a> CalendarClient<'a> {
}
}
let mut path = format!("/ca/events/{}/{}", event.calendar_guid, event.guid);
- if let Some(Scope::This) = scope {
- // As icloud.com marks "only this event": an exception to the series that had one.
- body["Event"]["recurrenceException"] = Value::Bool(true);
- body["Event"]["hadRecurrence"] = Value::Bool(true);
- body["Event"]["changeRecurring"] = Value::from("this");
- path.push_str("/this");
+ match scope {
+ Some(Scope::This) => {
+ // As icloud.com marks "only this event": an exception to the series that had one.
+ body["Event"]["recurrenceException"] = Value::Bool(true);
+ body["Event"]["hadRecurrence"] = Value::Bool(true);
+ body["Event"]["changeRecurring"] = Value::from("this");
+ path.push_str("/this");
+ }
+ Some(Scope::All) if occurrence => {
+ body["Event"]["changeRecurring"] = Value::from("all");
+ path.push_str("/all");
+ }
+ _ => {}
}
let answer = self
.post(&path, &body, &day, &day, event_zone(event).as_deref(), None)
@@ -563,8 +629,10 @@ impl<'a> CalendarClient<'a> {
"ClientState": client_state(&event.calendar_guid, ctag),
});
let mut path = format!("/ca/events/{}/{}", event.calendar_guid, event.guid);
- if let Some(Scope::This) = scope {
- path.push_str("/this");
+ match scope {
+ Some(Scope::This) => path.push_str("/this"),
+ Some(Scope::All) if is_occurrence(&event.guid) => path.push_str("/all"),
+ _ => {}
}
match self
.post(
@@ -612,7 +680,7 @@ impl<'a> CalendarClient<'a> {
.and_then(Value::as_array)
.into_iter()
.flatten()
- .filter(|a| a.get("pGuid").and_then(Value::as_str) == Some(event.guid.as_str()))
+ .filter(|a| belongs_to(a, &event.guid))
.filter_map(|a| minutes_of(a.get("measurement")?))
.collect())
}
diff --git a/probe/examples/calendar_occurrence_detail.rs b/probe/examples/calendar_occurrence_detail.rs
new file mode 100644
index 0000000..1f90bde
--- /dev/null
+++ b/probe/examples/calendar_occurrence_detail.rs
@@ -0,0 +1,147 @@
+//! Live, throwaway event only: what eventdetail says of one occurrence of a series — its
+//! master dates in particular — then the series deleted.
+use anyhow::{anyhow, Result};
+use serde_json::Value;
+#[tokio::main]
+async fn main() -> Result<()> {
+ let dir = std::path::PathBuf::from(std::env::var("HOME")?).join(".local/share/quince-probe");
+ let mut client = quince_auth::Client::new(&dir)?;
+ if !client.resume().await? {
+ return Err(anyhow!("no session"));
+ }
+ let root = client
+ .session()
+ .service_url("calendar")
+ .ok_or_else(|| anyhow!("no calendar"))?;
+ let (http, p) = (client.http().clone(), client.service_params());
+ let cal = quince_icloud::calendar::CalendarClient::new(&http, &root, p.clone());
+ let snap = cal
+ .startup("2026-10-01", "2026-10-31", "Asia/Kolkata")
+ .await?;
+ let home = snap
+ .calendars
+ .iter()
+ .find(|c| c.writable)
+ .ok_or_else(|| anyhow!("no writable calendar"))?;
+ let event = quince_core::calendar::Event {
+ guid: uuid::Uuid::new_v4().to_string().to_uppercase(),
+ calendar_guid: home.guid.clone(),
+ title: "Quince detail test".into(),
+ starts_at: 1_793_000_000,
+ ends_at: 1_793_003_600,
+ timezone: Some("Asia/Kolkata".into()),
+ ..Default::default()
+ };
+ let rule = quince_icloud::calendar::EventRepeat {
+ freq: "weekly".into(),
+ interval: 1,
+ count: Some(3),
+ };
+ cal.put_event_full(&event, None, None, Some(Some(&rule)), None)
+ .await?;
+ let occ = format!("{}__20261102T073300Z", event.guid);
+ let mut q = p.clone();
+ for (k, v) in [
+ ("clientVersion", "5.1"),
+ ("lang", "en-us"),
+ ("usertz", "Asia/Kolkata"),
+ ("startDate", "2026-11-02"),
+ ("endDate", "2026-11-02"),
+ ] {
+ q.push((k.into(), v.into()));
+ }
+ let d: Value = http
+ .get(format!(
+ "{}/ca/eventdetail/{}/{}",
+ root.trim_end_matches('/'),
+ home.guid,
+ occ
+ ))
+ .query(&q)
+ .send()
+ .await?
+ .json()
+ .await?;
+ let e = &d["Event"][0];
+ for k in [
+ "guid",
+ "startDate",
+ "endDate",
+ "masterStartDate",
+ "masterEndDate",
+ "recurrenceMaster",
+ "recurrence",
+ "etag",
+ ] {
+ println!("{k} = {}", e[k]);
+ }
+ use quince_icloud::calendar::Scope;
+ // All events, from the second occurrence: a new title, an hour later.
+ let mut second = event.clone();
+ second.guid = occ.clone();
+ second.starts_at += 7 * 86_400 + 3600;
+ second.ends_at += 7 * 86_400 + 3600;
+ second.title = "Quince detail test, all renamed".into();
+ cal.put_event_full(&second, None, None, None, Some(Scope::All))
+ .await?;
+ let mut q2 = p.clone();
+ for (k, v) in [
+ ("clientVersion", "5.1"),
+ ("requestID", "4"),
+ ("lang", "en-us"),
+ ("usertz", "Asia/Kolkata"),
+ ("startDate", "2026-10-26"),
+ ("endDate", "2026-11-25"),
+ ] {
+ q2.push((k.into(), v.into()));
+ }
+ let all: Value = http
+ .get(format!("{}/ca/events", root.trim_end_matches('/')))
+ .query(&q2)
+ .send()
+ .await?
+ .json()
+ .await?;
+ for e in all["Event"].as_array().into_iter().flatten().filter(|e| {
+ e["title"]
+ .as_str()
+ .is_some_and(|t| t.starts_with("Quince detail test"))
+ }) {
+ println!(" {} {} {}", e["guid"], e["title"], e["startDate"]);
+ }
+ // Delete all, from an occurrence.
+ let mut first = second.clone();
+ first.guid = format!("{}__20261026T083300Z", event.guid);
+ first.starts_at = event.starts_at + 3600;
+ first.ends_at = event.ends_at + 3600;
+ match cal
+ .delete_event_scoped(&second, None, Some(Scope::All))
+ .await
+ {
+ Ok(()) => println!("delete all from an occurrence: accepted"),
+ Err(e) => println!("delete all from an occurrence: refused — {e}"),
+ }
+ let left: Value = http
+ .get(format!("{}/ca/events", root.trim_end_matches('/')))
+ .query(&q2)
+ .send()
+ .await?
+ .json()
+ .await?;
+ let n = left["Event"]
+ .as_array()
+ .into_iter()
+ .flatten()
+ .filter(|e| {
+ e["title"]
+ .as_str()
+ .is_some_and(|t| t.starts_with("Quince detail test"))
+ })
+ .count();
+ println!("left after delete all: {n}");
+ if n > 0 {
+ cal.delete_event(&event, None).await?;
+ println!("cleaned up by series id");
+ }
+ Ok(())
+}