From a4e0e24ab7e6ee83cae7b941a04fd02dc26e553e Mon Sep 17 00:00:00 2001
From: nmemmert <67961292+nmemmert@users.noreply.github.com>
Date: Tue, 20 Oct 2026 15:46:24 -0400
Subject: [PATCH] iCloud: recognise Apple's calendar entries; say what was seen
when none match
Apple writes (attributes, no prefix), which the
previous pattern missed, so a valid sign-in reported "No calendars found". Match it with a
lookahead, check the HTTP status of the listing, and name what iCloud returned if nothing matches.
Co-Authored-By: Claude Sonnet 5.5
---
caldav.js | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/caldav.js b/caldav.js
index a7cfc98..dfc1878 100644
--- a/caldav.js
+++ b/caldav.js
@@ -65,10 +65,15 @@ async function connect(appleId, password) {
if (!homeHref) throw new Error('Could not find the calendar home for this account');
const home = abs(homeHref, b.url);
const c = await dav('PROPFIND', home, { ...o, depth: 1, body: PROPFIND_CALS });
- const calendars = [];
+ if (c.status >= 400) throw new Error(`iCloud answered ${c.status} when listing the calendars`);
+ const calendars = [], seen = [];
for (const r of responses(c.text)) {
const rt = tag(r, 'resourcetype') || '';
- if (!/<(?:\w+:)?calendar\s*\/?>/i.test(rt)) continue;
+ // Apple writes (with attributes, and often no prefix); the lookahead keeps
+ // calendar-proxy-read, calendar-home-set etc. from matching.
+ const isCal = /<(?:[\w-]+:)?calendar(?=[\s/>])/i.test(rt);
+ seen.push(isCal ? 'calendar' : (rt.replace(/<(?:[\w-]+:)?([\w-]+)[^>]*>/g, '$1 ').trim() || 'other').slice(0, 30));
+ if (!isCal) continue;
const comps = tag(r, 'supported-calendar-component-set');
const events = !comps || /name="VEVENT"/i.test(comps), todos = !!comps && /name="VTODO"/i.test(comps);
if (!events && !todos) continue;
@@ -76,7 +81,7 @@ async function connect(appleId, password) {
const color = (tag(r, 'calendar-color') || '').trim().slice(0, 7);
calendars.push({ id: calId(href), href, name: decode(tag(r, 'displayname') || 'Calendar').trim() || 'Calendar', color: /^#[0-9a-f]{6}$/i.test(color) ? color : '#d9453a', enabled: true, events, todos });
}
- if (!calendars.length) throw new Error('No calendars found on this account');
+ if (!calendars.length) throw new Error(`Signed in, but no calendars were found (iCloud listed ${seen.length} item${seen.length === 1 ? '' : 's'}: ${seen.slice(0, 6).join(', ') || 'none'}). Make sure Calendar is turned on for this Apple ID in iCloud settings.`);
save({ user: o.user, pass: o.pass, calendars });
return status();
}