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.

rustfmt

Yashwanth Kamireddi60d134f21090
diff --git a/crates/quince-icloud/src/notes.rs b/crates/quince-icloud/src/notes.rs
index 55a3ee0..f970040 100644
--- a/crates/quince-icloud/src/notes.rs
+++ b/crates/quince-icloud/src/notes.rs
@@ -329,14 +329,20 @@ pub fn apply_cloudkit(
// A table: its cells, kept beside the library's settings under its id, which is
// what the note's text names it by.
"Attachment" => {
- let Some(name) = field::record_name(record) else { continue };
+ let Some(name) = field::record_name(record) else {
+ continue;
+ };
let uti = record
.pointer("/fields/UTI/value")
.and_then(Value::as_str)
.unwrap_or_default();
if uti == crate::table::UTI {
let cells = (!removed)
- .then(|| record.pointer("/fields/MergeableDataEncrypted/value").and_then(Value::as_str))
+ .then(|| {
+ record
+ .pointer("/fields/MergeableDataEncrypted/value")
+ .and_then(Value::as_str)
+ })
.flatten()
.and_then(crate::table::cells_from_base64);
tables.push((name, cells));
@@ -361,7 +367,10 @@ pub fn apply_cloudkit(
}
for (name, cells) in &tables {
- let value = cells.as_ref().and_then(|c| serde_json::to_string(c).ok()).unwrap_or_default();
+ let value = cells
+ .as_ref()
+ .and_then(|c| serde_json::to_string(c).ok())
+ .unwrap_or_default();
library.set_state(&crate::table::state_key(name), &value)?;
}
// A note the owner deleted is still present as a Note record; only the per-user record
diff --git a/crates/quince-icloud/src/table.rs b/crates/quince-icloud/src/table.rs
index 645502a..7d6fa75 100644
--- a/crates/quince-icloud/src/table.rs
+++ b/crates/quince-icloud/src/table.rs
@@ -107,8 +107,13 @@ fn inflate(data: &[u8]) -> Option<Vec<u8>> {
use std::io::Read;
let mut out = Vec::new();
if data.starts_with(&[0x1f, 0x8b]) {
- flate2::read::GzDecoder::new(data).read_to_end(&mut out).ok()?;
- } else if flate2::read::ZlibDecoder::new(data).read_to_end(&mut out).is_ok() {
+ flate2::read::GzDecoder::new(data)
+ .read_to_end(&mut out)
+ .ok()?;
+ } else if flate2::read::ZlibDecoder::new(data)
+ .read_to_end(&mut out)
+ .is_ok()
+ {
} else {
return Some(data.to_vec());
}
@@ -152,7 +157,9 @@ impl<'a> Doc<'a> {
let mut out = HashMap::new();
for element in bytes(&fields(body)?, 1) {
let e = fields(element)?;
- let (Some(k), Some(v)) = (bytes(&e, 1).next(), bytes(&e, 2).next()) else { continue };
+ let (Some(k), Some(v)) = (bytes(&e, 1).next(), bytes(&e, 2).next()) else {
+ continue;
+ };
if let (Some(k), Some(v)) = (object_index(k), object_index(v)) {
out.insert(k, v);
}
@@ -165,7 +172,10 @@ impl<'a> Doc<'a> {
let mut out = HashMap::new();
for i in 0..self.objects.len() {
if let Some(entries) = self.custom(i) {
- if let Some(at) = entries.get("UUIDIndex").and_then(|id| int(&fields(id)?, 2).or_else(|| int(&fields(id)?, 1))) {
+ if let Some(at) = entries
+ .get("UUIDIndex")
+ .and_then(|id| int(&fields(id)?, 2).or_else(|| int(&fields(id)?, 1)))
+ {
if let Some(u) = usize::try_from(at).ok().and_then(|at| self.uuids.get(at)) {
out.insert(*u, i);
}
@@ -206,7 +216,11 @@ impl<'a> Doc<'a> {
self.object(i)
.filter(|(kind, _)| *kind == 10)
.and_then(|(_, body)| fields(body))
- .and_then(|fs| bytes(&fs, 2).next().map(|b| String::from_utf8_lossy(b).into_owned()))
+ .and_then(|fs| {
+ bytes(&fs, 2)
+ .next()
+ .map(|b| String::from_utf8_lossy(b).into_owned())
+ })
.unwrap_or_default()
}
}
@@ -216,7 +230,9 @@ impl<'a> Doc<'a> {
#[must_use]
pub fn cells_from_base64(value: &str) -> Option<Vec<Vec<String>>> {
use base64::Engine;
- let raw = base64::engine::general_purpose::STANDARD.decode(value.trim()).ok()?;
+ let raw = base64::engine::general_purpose::STANDARD
+ .decode(value.trim())
+ .ok()?;
cells(&inflate(&raw)?)
}
@@ -228,7 +244,9 @@ pub fn cells(document: &[u8]) -> Option<Vec<Vec<String>>> {
let data = fields(bytes(&version, 3).next()?)?;
let doc = Doc {
objects: bytes(&data, 3).collect(),
- keys: bytes(&data, 4).map(|k| String::from_utf8_lossy(k).into_owned()).collect(),
+ keys: bytes(&data, 4)
+ .map(|k| String::from_utf8_lossy(k).into_owned())
+ .collect(),
uuids: bytes(&data, 6).collect(),
};
let root = doc.custom(0)?;
diff --git a/crates/quince-icloud/tests/table.rs b/crates/quince-icloud/tests/table.rs
index bb89b13..34ee165 100644
--- a/crates/quince-icloud/tests/table.rs
+++ b/crates/quince-icloud/tests/table.rs
@@ -1,7 +1,17 @@
//! A table made on a phone and never typed in reads as the 2×2 of empty cells Notes shows.
#[test]
fn an_empty_table_reads_as_two_by_two() {
- let doc = std::fs::read(concat!(env!("CARGO_MANIFEST_DIR"), "/tests/data/table-empty-2x2.bin")).unwrap();
+ let doc = std::fs::read(concat!(
+ env!("CARGO_MANIFEST_DIR"),
+ "/tests/data/table-empty-2x2.bin"
+ ))
+ .unwrap();
let cells = quince_icloud::table::cells(&doc).expect("a table");
- assert_eq!(cells, vec![vec![String::new(), String::new()], vec![String::new(), String::new()]]);
+ assert_eq!(
+ cells,
+ vec![
+ vec![String::new(), String::new()],
+ vec![String::new(), String::new()]
+ ]
+ );
}
diff --git a/probe/examples/notes_table_chain.rs b/probe/examples/notes_table_chain.rs
index be78c29..9b26944 100644
--- a/probe/examples/notes_table_chain.rs
+++ b/probe/examples/notes_table_chain.rs
@@ -8,19 +8,58 @@ async fn main() -> Result<()> {
if !client.resume().await? {
return Err(anyhow!("no session"));
}
- let root = client.session().service_url("ckdatabasews").ok_or_else(|| anyhow!("no ck"))?;
+ let root = client
+ .session()
+ .service_url("ckdatabasews")
+ .ok_or_else(|| anyhow!("no ck"))?;
let (http, p) = (client.http().clone(), client.service_params());
let zc = quince_icloud::cloudkit::ZoneClient::new(&http, &root, "com.apple.notes", p.clone());
- let note = zc.lookup_record("Notes", "50a80840-1931-45d9-9774-7d7ab70d9022").await?.ok_or_else(|| anyhow!("no note"))?;
+ let note = zc
+ .lookup_record("Notes", "50a80840-1931-45d9-9774-7d7ab70d9022")
+ .await?
+ .ok_or_else(|| anyhow!("no note"))?;
println!("by {} / created {}", note["modified"], note["created"]);
- println!("text {:?} modified {}", quince_icloud::ckdocument::stored_text_from_base64(note["fields"]["TextDataEncrypted"]["value"].as_str().unwrap_or("")), note["fields"]["ModificationDate"]["value"]);
- let runs = quince_icloud::ckdocument::runs_from_base64(note["fields"]["TextDataEncrypted"]["value"].as_str().unwrap_or(""));
- let raw = base64::Engine::decode(&base64::engine::general_purpose::STANDARD, note["fields"]["TextDataEncrypted"]["value"].as_str().unwrap_or("").trim()).unwrap_or_default();
- for r in quince_icloud::ckdocument::debug_attribute_runs(&raw) { println!("{}", quince_icloud::ckdocument::debug_tree(&r, 6).join(" | ")); }
- println!("{} runs: {:?}", runs.len(), runs.iter().map(|r| (r.length, r.attachment.clone())).collect::<Vec<_>>());
+ println!(
+ "text {:?} modified {}",
+ quince_icloud::ckdocument::stored_text_from_base64(
+ note["fields"]["TextDataEncrypted"]["value"]
+ .as_str()
+ .unwrap_or("")
+ ),
+ note["fields"]["ModificationDate"]["value"]
+ );
+ let runs = quince_icloud::ckdocument::runs_from_base64(
+ note["fields"]["TextDataEncrypted"]["value"]
+ .as_str()
+ .unwrap_or(""),
+ );
+ let raw = base64::Engine::decode(
+ &base64::engine::general_purpose::STANDARD,
+ note["fields"]["TextDataEncrypted"]["value"]
+ .as_str()
+ .unwrap_or("")
+ .trim(),
+ )
+ .unwrap_or_default();
+ for r in quince_icloud::ckdocument::debug_attribute_runs(&raw) {
+ println!(
+ "{}",
+ quince_icloud::ckdocument::debug_tree(&r, 6).join(" | ")
+ );
+ }
+ println!(
+ "{} runs: {:?}",
+ runs.len(),
+ runs.iter()
+ .map(|r| (r.length, r.attachment.clone()))
+ .collect::<Vec<_>>()
+ );
for id in runs.iter().filter_map(|r| r.attachment.clone()) {
let rec = zc.lookup_record("Notes", &id).await?;
- let cells = rec.as_ref().and_then(|r| r["fields"]["MergeableDataEncrypted"]["value"].as_str()).and_then(quince_icloud::table::cells_from_base64);
+ let cells = rec
+ .as_ref()
+ .and_then(|r| r["fields"]["MergeableDataEncrypted"]["value"].as_str())
+ .and_then(quince_icloud::table::cells_from_base64);
println!("attachment {id}:");
for row in cells.unwrap_or_default() {
println!(" {row:?}");
diff --git a/probe/examples/notes_table_owner.rs b/probe/examples/notes_table_owner.rs
index e2c0d86..ebd5532 100644
--- a/probe/examples/notes_table_owner.rs
+++ b/probe/examples/notes_table_owner.rs
@@ -8,19 +8,46 @@ async fn main() -> Result<()> {
if !client.resume().await? {
return Err(anyhow!("no session"));
}
- let root = client.session().service_url("ckdatabasews").ok_or_else(|| anyhow!("no ck"))?;
+ let root = client
+ .session()
+ .service_url("ckdatabasews")
+ .ok_or_else(|| anyhow!("no ck"))?;
let (http, p) = (client.http().clone(), client.service_params());
let zc = quince_icloud::cloudkit::ZoneClient::new(&http, &root, "com.apple.notes", p.clone());
let walk = zc.all_records("Notes", None).await?;
- for a in walk.records.iter().filter(|r| r["recordType"] == "Attachment") {
+ for a in walk
+ .records
+ .iter()
+ .filter(|r| r["recordType"] == "Attachment")
+ {
let id = a["recordName"].as_str().unwrap_or("");
- let owner = a["fields"]["Note"]["value"]["recordName"].as_str().unwrap_or("");
+ let owner = a["fields"]["Note"]["value"]["recordName"]
+ .as_str()
+ .unwrap_or("");
let note = walk.records.iter().find(|r| r["recordName"] == owner);
- let body = note.and_then(|n| n["fields"]["TextDataEncrypted"]["value"].as_str()).unwrap_or("");
- let placed = quince_icloud::ckdocument::runs_from_base64(body).iter().any(|r| r.attachment.as_deref() == Some(id));
- let cells = a["fields"]["MergeableDataEncrypted"]["value"].as_str().and_then(quince_icloud::table::cells_from_base64);
- println!("{id} → note {owner} ({:?}) placed in text: {placed} deleted: {} modified-by {}", quince_icloud::ckdocument::stored_text_from_base64(body).unwrap_or_default().chars().take(20).collect::<String>(), a["fields"]["Deleted"]["value"], a["modified"]["timestamp"]);
- println!(" {:?}", cells.map(|c| c.into_iter().take(3).collect::<Vec<_>>()));
+ let body = note
+ .and_then(|n| n["fields"]["TextDataEncrypted"]["value"].as_str())
+ .unwrap_or("");
+ let placed = quince_icloud::ckdocument::runs_from_base64(body)
+ .iter()
+ .any(|r| r.attachment.as_deref() == Some(id));
+ let cells = a["fields"]["MergeableDataEncrypted"]["value"]
+ .as_str()
+ .and_then(quince_icloud::table::cells_from_base64);
+ println!(
+ "{id} → note {owner} ({:?}) placed in text: {placed} deleted: {} modified-by {}",
+ quince_icloud::ckdocument::stored_text_from_base64(body)
+ .unwrap_or_default()
+ .chars()
+ .take(20)
+ .collect::<String>(),
+ a["fields"]["Deleted"]["value"],
+ a["modified"]["timestamp"]
+ );
+ println!(
+ " {:?}",
+ cells.map(|c| c.into_iter().take(3).collect::<Vec<_>>())
+ );
}
Ok(())
}
diff --git a/probe/examples/notes_who_wrote.rs b/probe/examples/notes_who_wrote.rs
index 7b20038..928b74c 100644
--- a/probe/examples/notes_who_wrote.rs
+++ b/probe/examples/notes_who_wrote.rs
@@ -7,13 +7,29 @@ async fn main() -> Result<()> {
if !client.resume().await? {
return Err(anyhow!("no session"));
}
- let root = client.session().service_url("ckdatabasews").ok_or_else(|| anyhow!("no ck"))?;
+ let root = client
+ .session()
+ .service_url("ckdatabasews")
+ .ok_or_else(|| anyhow!("no ck"))?;
let (http, p) = (client.http().clone(), client.service_params());
let zc = quince_icloud::cloudkit::ZoneClient::new(&http, &root, "com.apple.notes", p.clone());
let walk = zc.all_records("Notes", None).await?;
for r in walk.records.iter().filter(|r| r["recordType"] == "Note") {
- let text = r["fields"]["TextDataEncrypted"]["value"].as_str().and_then(quince_icloud::ckdocument::stored_text_from_base64).unwrap_or_default();
- println!("{:>4} {:>14} {:?}", r["modified"]["deviceID"].as_str().unwrap_or("?"), r["modified"]["timestamp"], text.lines().next().unwrap_or("").chars().take(30).collect::<String>());
+ let text = r["fields"]["TextDataEncrypted"]["value"]
+ .as_str()
+ .and_then(quince_icloud::ckdocument::stored_text_from_base64)
+ .unwrap_or_default();
+ println!(
+ "{:>4} {:>14} {:?}",
+ r["modified"]["deviceID"].as_str().unwrap_or("?"),
+ r["modified"]["timestamp"],
+ text.lines()
+ .next()
+ .unwrap_or("")
+ .chars()
+ .take(30)
+ .collect::<String>()
+ );
}
Ok(())
}