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.

Notes folders verified live: create and rename read back as written; delete removes the folder record once its notes are in Recently Deleted, as icloud.com does — CloudKit has no Deleted field on folders

Yashwanth Kamireddi364e79bdc4b2
diff --git a/crates/quince-icloud/src/notes.rs b/crates/quince-icloud/src/notes.rs
index 966cdc8..47c9dcd 100644
--- a/crates/quince-icloud/src/notes.rs
+++ b/crates/quince-icloud/src/notes.rs
@@ -617,8 +617,10 @@ pub async fn create_folder_cloudkit(
}
let client = ZoneClient::new(http, ckdatabasews_root, CONTAINER, params);
let name = uuid::Uuid::new_v4().to_string();
+ // As every folder on a real account carries it, Apple's own two included.
let mut fields = serde_json::json!({
"TitleEncrypted": { "type": "ENCRYPTED_BYTES", "value": plain_title(title) },
+ "MinimumSupportedNotesVersion": { "type": "INT64", "value": 0 },
});
if let Some(parent) = parent {
fields["ParentFolder"] = client.reference_to(ZONE, parent);
@@ -665,11 +667,12 @@ pub async fn rename_folder_cloudkit(
Ok(())
}
-/// Delete a folder as icloud.com does, except for its last step: every note in it — and in
-/// every folder inside it — goes to Recently Deleted, then each folder is flagged `Deleted`,
-/// which Apple's clients read as gone. icloud.com then destroys the folder record too; that
-/// is left undone here, since nothing reads a flagged folder and a destroyed record is past
-/// recovery. Notes are moved first, so a failure part-way loses nothing.
+/// Delete a folder as icloud.com does: every note in it — and in every folder inside it —
+/// goes to Recently Deleted first, then the folder records go, deepest first. The folder
+/// itself has to be removed outright: measured on a real account, CloudKit refuses a
+/// `Deleted` flag on a folder ("Field Deleted not found in Folder"), and icloud.com's own
+/// delete ends the same way. Nothing a person wrote is in a folder record — its notes are
+/// all safe in Recently Deleted before it goes — and a failure part-way loses nothing.
pub async fn delete_folder_cloudkit(
http: &reqwest::Client,
ckdatabasews_root: &str,
@@ -711,22 +714,9 @@ pub async fn delete_folder_cloudkit(
}
let client = ZoneClient::new(http, ckdatabasews_root, CONTAINER, params);
for folder in doomed.iter().rev() {
- let Some(current) = client.lookup_record(ZONE, folder).await? else {
- continue;
- };
- let tag = current.get("recordChangeTag").and_then(Value::as_str);
- client
- .update_record(
- ZONE,
- folder,
- "Folder",
- tag,
- serde_json::json!({
- "Deleted": { "type": "INT64", "value": 1 },
- "DeletedDate": { "type": "TIMESTAMP", "value": now_millis() },
- }),
- )
- .await?;
+ if client.lookup_record(ZONE, folder).await?.is_some() {
+ client.delete_record(ZONE, folder).await?;
+ }
}
Ok(())
}
diff --git a/probe/examples/notes_folder_cleanup.rs b/probe/examples/notes_folder_cleanup.rs
new file mode 100644
index 0000000..f29f113
--- /dev/null
+++ b/probe/examples/notes_folder_cleanup.rs
@@ -0,0 +1,28 @@
+//! Live: remove a folder left by an earlier round trip, by record name.
+use anyhow::{anyhow, Result};
+#[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("ckdatabasews")
+ .ok_or_else(|| anyhow!("no ckdatabasews"))?;
+ let name = std::env::args()
+ .nth(1)
+ .ok_or_else(|| anyhow!("record name"))?;
+ quince_icloud::notes::delete_folder_cloudkit(
+ client.http(),
+ &root,
+ client.service_params(),
+ &[],
+ &[],
+ &name,
+ )
+ .await?;
+ println!("gone: {name}");
+ Ok(())
+}
diff --git a/probe/examples/notes_folder_roundtrip.rs b/probe/examples/notes_folder_roundtrip.rs
new file mode 100644
index 0000000..3d73ad8
--- /dev/null
+++ b/probe/examples/notes_folder_roundtrip.rs
@@ -0,0 +1,58 @@
+//! Live, on the probe account: make a folder, rename it, delete it — each read back from Apple.
+//! Leaves nothing behind.
+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("ckdatabasews")
+ .ok_or_else(|| anyhow!("no ckdatabasews"))?;
+ let http = client.http().clone();
+ let params = client.service_params();
+ let zc =
+ quince_icloud::cloudkit::ZoneClient::new(&http, &root, "com.apple.notes", params.clone());
+ let show = |r: &Option<Value>| {
+ r.as_ref()
+ .map(|r| r["fields"].to_string())
+ .unwrap_or("NONE".into())
+ };
+
+ let guid = quince_icloud::notes::create_folder_cloudkit(
+ &http,
+ &root,
+ params.clone(),
+ "Quince test",
+ None,
+ )
+ .await?;
+ println!(
+ "created {guid}: {}",
+ show(&zc.lookup_record("Notes", &guid).await?)
+ );
+ quince_icloud::notes::rename_folder_cloudkit(
+ &http,
+ &root,
+ params.clone(),
+ &guid,
+ "Quince test renamed",
+ )
+ .await?;
+ println!(
+ "renamed: {}",
+ show(&zc.lookup_record("Notes", &guid).await?)
+ );
+ quince_icloud::notes::delete_folder_cloudkit(&http, &root, params.clone(), &[], &[], &guid)
+ .await?;
+ println!(
+ "deleted: {}",
+ show(&zc.lookup_record("Notes", &guid).await?)
+ );
+ Ok(())
+}