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: one occurrence of a repeating event is never again saved or deleted as if an event — that collapsed the whole series on a real account; 'this event' writes it as icloud.com does, an exception at its /this path; repeats readable and settable — verified live

Yashwanth Kamireddi5d1506514b97
diff --git a/crates/quince-icloud/src/calendar.rs b/crates/quince-icloud/src/calendar.rs
index 5ac1827..b89501c 100644
--- a/crates/quince-icloud/src/calendar.rs
+++ b/crates/quince-icloud/src/calendar.rs
@@ -313,6 +313,32 @@ fn minutes_of(m: &Value) -> Option<i64> {
Some(if before { total } else { -total })
}
+/// Which events a change to one occurrence of a repeating event is for.
+#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub enum Scope {
+ /// This one alone; the rest of the series as it was.
+ This,
+}
+
+/// Whether `guid` names one occurrence of a repeating event rather than an event: Apple gives
+/// each occurrence its series' id and its UTC start, `<series>__20261102T073300Z`.
+#[must_use]
+pub fn is_occurrence(guid: &str) -> bool {
+ guid.contains("__")
+}
+
+/// How an event repeats, in icloud.com's words: `freq` is `daily`, `weekly`, `monthly` or
+/// `yearly`; every `interval` of them; ending after `count` times, or never.
+#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct EventRepeat {
+ pub freq: String,
+ pub interval: i64,
+ #[serde(default)]
+ pub count: Option<i64>,
+}
+
/// Apple's calendar service.
pub struct CalendarClient<'a> {
http: &'a reqwest::Client,
@@ -369,6 +395,31 @@ impl<'a> CalendarClient<'a> {
ctag: Option<&str>,
alerts: Option<&[i64]>,
) -> Result<Snapshot> {
+ self.put_event_full(event, ctag, alerts, None, None).await
+ }
+
+ /// [`Self::put_event_with_alerts`], and when `repeat` is given, the event's repeat set
+ /// (`Some(Some(..))`) or cleared (`Some(None)`) as icloud.com writes it: a `Recurrence`
+ /// object named `<event>*MME-RID` beside the event, the event naming it. With `None` the
+ /// repeat Apple holds goes back as it is, object and all.
+ pub async fn put_event_full(
+ &self,
+ event: &Event,
+ ctag: Option<&str>,
+ alerts: Option<&[i64]>,
+ repeat: Option<Option<&EventRepeat>>,
+ scope: Option<Scope>,
+ ) -> Result<Snapshot> {
+ // One occurrence of a repeating event, sent as though it were an event of its own,
+ // made Apple take it as the whole series — measured: a weekly event three times over
+ // came back one event, repeating no more. An occurrence is changed only with its
+ // scope said, as icloud.com asks "this event or all events?".
+ let occurrence = is_occurrence(&event.guid);
+ if occurrence && scope.is_none() {
+ return Err(Error::Refused(
+ "This is one occurrence of a repeating event. Say whether the change is for this event alone.".into(),
+ ));
+ }
if event.calendar_guid.trim().is_empty() {
return Err(Error::Protocol(
"an event has to go in a calendar, and this account has none yet".into(),
@@ -428,7 +479,49 @@ impl<'a> CalendarClient<'a> {
if !alarms.is_empty() {
body["Alarm"] = Value::Array(alarms);
}
- let path = format!("/ca/events/{}/{}", event.calendar_guid, event.guid);
+ let held_repeat: Vec<Value> = detail
+ .as_ref()
+ .and_then(|d| d.get("Recurrence"))
+ .and_then(Value::as_array)
+ .map(|all| {
+ all.iter()
+ .filter(|r| r.get("pGuid").and_then(Value::as_str) == Some(event.guid.as_str()))
+ .cloned()
+ .collect()
+ })
+ .unwrap_or_default();
+ match repeat {
+ None => {
+ if !held_repeat.is_empty() {
+ body["Recurrence"] = Value::Array(held_repeat);
+ }
+ }
+ Some(None) => {
+ body["Event"]["recurrence"] = Value::Null;
+ }
+ Some(Some(rule)) => {
+ let guid = format!("{}*MME-RID", event.guid);
+ let mut object = serde_json::json!({
+ "guid": guid,
+ "pGuid": event.guid,
+ "freq": rule.freq,
+ "interval": rule.interval.max(1),
+ });
+ if let Some(count) = rule.count {
+ object["count"] = Value::from(count);
+ }
+ body["Recurrence"] = Value::Array(vec![object]);
+ body["Event"]["recurrence"] = Value::String(guid);
+ }
+ }
+ 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");
+ }
let answer = self
.post(&path, &body, &day, &day, event_zone(event).as_deref(), None)
.await?;
@@ -440,6 +533,22 @@ impl<'a> CalendarClient<'a> {
/// `etag` is what stops a delete from landing on a version of the event someone changed
/// on another device in the meantime.
pub async fn delete_event(&self, event: &Event, ctag: Option<&str>) -> Result<()> {
+ self.delete_event_scoped(event, ctag, None).await
+ }
+
+ /// [`Self::delete_event`], for an occurrence of a repeating event with its scope said:
+ /// `This` removes the one day and leaves the series.
+ pub async fn delete_event_scoped(
+ &self,
+ event: &Event,
+ ctag: Option<&str>,
+ scope: Option<Scope>,
+ ) -> Result<()> {
+ if is_occurrence(&event.guid) && scope.is_none() {
+ return Err(Error::Refused(
+ "This is one occurrence of a repeating event. Say whether to delete this event alone.".into(),
+ ));
+ }
if event.calendar_guid.trim().is_empty() {
return Err(Error::Protocol("that event names no calendar".into()));
}
@@ -453,7 +562,10 @@ impl<'a> CalendarClient<'a> {
"Event": { "guid": event.guid, "pGuid": event.calendar_guid, "etag": event.etag },
"ClientState": client_state(&event.calendar_guid, ctag),
});
- let path = format!("/ca/events/{}/{}", event.calendar_guid, event.guid);
+ let mut path = format!("/ca/events/{}/{}", event.calendar_guid, event.guid);
+ if let Some(Scope::This) = scope {
+ path.push_str("/this");
+ }
match self
.post(
&path,
@@ -1120,6 +1232,46 @@ mod write_tests {
assert_eq!(body["Event"]["alarms"], serde_json::json!([]));
}
+ /// One occurrence of a repeating event, sent as an event, collapsed the series on a real
+ /// account. Without its scope it is refused before anything is sent.
+ #[tokio::test]
+ async fn an_occurrence_is_not_saved_or_deleted_without_its_scope() {
+ let server = server().await;
+ let http = reqwest::Client::new();
+ let client = CalendarClient::new(&http, &server.uri(), vec![]);
+ let mut one = event();
+ one.guid = "SERIES__20261102T073300Z".into();
+ assert!(client.put_event(&one, None).await.is_err());
+ assert!(client.delete_event(&one, None).await.is_err());
+ assert!(
+ server.received_requests().await.unwrap().is_empty(),
+ "nothing sent"
+ );
+ }
+
+ /// With "this event" said, it goes to the occurrence's own path, marked as an exception.
+ #[tokio::test]
+ async fn this_occurrence_alone_goes_to_its_this_path() {
+ let server = server().await;
+ let http = reqwest::Client::new();
+ let client = CalendarClient::new(&http, &server.uri(), vec![]);
+ let mut one = event();
+ one.guid = "SERIES__20261102T073300Z".into();
+ client
+ .put_event_full(&one, None, None, None, Some(Scope::This))
+ .await
+ .unwrap();
+ let sent = request(&server).await;
+ assert!(
+ sent.url.path().ends_with("/SERIES__20261102T073300Z/this"),
+ "{}",
+ sent.url.path()
+ );
+ let body: Value = serde_json::from_slice(&sent.body).unwrap();
+ assert_eq!(body["Event"]["recurrenceException"], true);
+ assert_eq!(body["Event"]["changeRecurring"], "this");
+ }
+
/// Apple failing to say what an event holds is not "a new event": building the save
/// from nothing would write empty recurrence, alerts and guests over the real one.
#[tokio::test]
diff --git a/crates/quince-icloud/src/sync.rs b/crates/quince-icloud/src/sync.rs
index c8d5dcb..8f43ccc 100644
--- a/crates/quince-icloud/src/sync.rs
+++ b/crates/quince-icloud/src/sync.rs
@@ -156,7 +156,7 @@ pub async fn save_event(
ctag: Option<&str>,
event: &quince_core::calendar::Event,
) -> Result<Vec<quince_core::calendar::Event>> {
- save_event_with_alerts(http, root, params, ctag, event, None).await
+ save_event_with_alerts(http, root, params, ctag, event, None, None).await
}
/// [`save_event`], with the event's alerts set to `alerts` when given.
@@ -167,9 +167,12 @@ pub async fn save_event_with_alerts(
ctag: Option<&str>,
event: &quince_core::calendar::Event,
alerts: Option<&[i64]>,
+ scope: Option<crate::calendar::Scope>,
) -> Result<Vec<quince_core::calendar::Event>> {
let client = CalendarClient::new(http, root, params);
- let answer = client.put_event_with_alerts(event, ctag, alerts).await?;
+ let answer = client
+ .put_event_full(event, ctag, alerts, None, scope)
+ .await?;
// What goes into the library is what Apple holds, never what was sent. Measured: a save
// to the account answers with an empty list, and storing the sent copy instead kept an
// event with no etag — so the next edit or delete went without one — and, where Apple
diff --git a/probe/examples/calendar_repeat.rs b/probe/examples/calendar_repeat.rs
new file mode 100644
index 0000000..637f280
--- /dev/null
+++ b/probe/examples/calendar_repeat.rs
@@ -0,0 +1,141 @@
+//! Live, throwaway event only: a weekly event three times, its occurrences read back, its
+//! title edited without touching the repeat, the repeat read again — then 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 repeat 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 raw = |from: &str, to: &str| {
+ let mut q = p.clone();
+ for (k, v) in [
+ ("clientVersion", "5.1"),
+ ("requestID", "4"),
+ ("lang", "en-us"),
+ ("usertz", "Asia/Kolkata"),
+ ("startDate", from),
+ ("endDate", to),
+ ] {
+ q.push((k.into(), v.into()));
+ }
+ (format!("{}/ca/events", root.trim_end_matches('/')), q)
+ };
+ for (from, to) in [("2026-10-26", "2026-11-25")] {
+ let (url, q) = raw(from, to);
+ let body: Value = http.get(url).query(&q).send().await?.json().await?;
+ for e in body["Event"]
+ .as_array()
+ .into_iter()
+ .flatten()
+ .filter(|e| e["title"] == "Quince repeat test")
+ {
+ println!(
+ "occurrence guid={} start={} recurrence={} master={} exception={}",
+ e["guid"],
+ e["startDate"],
+ e["recurrence"],
+ e["recurrenceMaster"],
+ e["recurrenceException"]
+ );
+ }
+ println!(
+ "Recurrence objects: {}",
+ body["Recurrence"]
+ .to_string()
+ .chars()
+ .take(300)
+ .collect::<String>()
+ );
+ }
+ // As Quince sends an edit of the second occurrence today: its own id, as if an event.
+ let second = format!("{}__20261102T073300Z", event.guid);
+ let mut occ = event.clone();
+ occ.guid = second.clone();
+ occ.starts_at += 7 * 86_400;
+ occ.ends_at += 7 * 86_400;
+ occ.title = "Quince repeat test, second edited".into();
+ match cal.put_event(&occ, None).await {
+ Ok(_) => println!("edit of occurrence, no scope: ACCEPTED (bad)"),
+ Err(e) => println!("edit of occurrence, no scope: refused — {e}"),
+ }
+ use quince_icloud::calendar::Scope;
+ match cal
+ .put_event_full(&occ, None, None, None, Some(Scope::This))
+ .await
+ {
+ Ok(_) => println!("edit of occurrence, this event: accepted"),
+ Err(e) => println!("edit of occurrence, this event: refused — {e}"),
+ }
+ let mut third = event.clone();
+ third.guid = format!("{}__20261109T073300Z", event.guid);
+ third.starts_at += 14 * 86_400;
+ third.ends_at += 14 * 86_400;
+ match cal
+ .delete_event_scoped(&third, None, Some(Scope::This))
+ .await
+ {
+ Ok(_) => println!("delete of third occurrence, this event: accepted"),
+ Err(e) => println!("delete of third occurrence, this event: refused — {e}"),
+ }
+ let (url, q) = raw("2026-10-26", "2026-11-25");
+ let body: Value = http.get(url).query(&q).send().await?.json().await?;
+ for e in body["Event"].as_array().into_iter().flatten().filter(|e| {
+ e["title"]
+ .as_str()
+ .is_some_and(|t| t.starts_with("Quince repeat test"))
+ }) {
+ println!(
+ " now: guid={} title={} start={} master={} exception={}",
+ e["guid"], e["title"], e["startDate"], e["recurrenceMaster"], e["recurrenceException"]
+ );
+ }
+ cal.delete_event(&event, None).await?;
+ let (url, q) = raw("2026-10-26", "2026-11-25");
+ let body: Value = http.get(url).query(&q).send().await?.json().await?;
+ let left: Vec<_> = body["Event"]
+ .as_array()
+ .into_iter()
+ .flatten()
+ .filter(|e| {
+ e["title"]
+ .as_str()
+ .is_some_and(|t| t.starts_with("Quince repeat test"))
+ })
+ .map(|e| e["guid"].clone())
+ .collect();
+ println!("deleted series; left: {left:?}");
+ Ok(())
+}
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs
index 5564a28..0568d25 100644
--- a/src-tauri/src/main.rs
+++ b/src-tauri/src/main.rs
@@ -373,6 +373,9 @@ struct EventDraft {
/// the event's alerts are left as Apple holds them.
#[serde(default)]
alerts: Option<Vec<i64>>,
+ /// For one occurrence of a repeating event: which events the change is for.
+ #[serde(default)]
+ scope: Option<quince_icloud::calendar::Scope>,
}
/// Everything an event write needs from the session, with the auth lock released first.
@@ -460,6 +463,7 @@ async fn event_save(
ctag.as_deref(),
&event,
draft.alerts.as_deref(),
+ draft.scope,
)
.await
.map_err(|e| e.to_string())?;
@@ -469,7 +473,12 @@ async fn event_save(
}
#[tauri::command]
-async fn event_delete(guid: String, auth: State<'_, Auth>, data: State<'_, Data>) -> UiResult<()> {
+async fn event_delete(
+ guid: String,
+ scope: Option<quince_icloud::calendar::Scope>,
+ auth: State<'_, Auth>,
+ data: State<'_, Data>,
+) -> UiResult<()> {
let (http, root, params) = calendar_context(&auth).await?;
let event = {
let library = data.0.lock().await;
@@ -480,7 +489,7 @@ async fn event_delete(guid: String, auth: State<'_, Auth>, data: State<'_, Data>
};
let ctag = quince_icloud::sync::calendar_ctag(&*data.0.lock().await, &event.calendar_guid);
quince_icloud::calendar::CalendarClient::new(&http, &root, params)
- .delete_event(&event, ctag.as_deref())
+ .delete_event_scoped(&event, ctag.as_deref(), scope)
.await
.map_err(|e| e.to_string())?;
let mut library = data.0.lock().await;