Fix XML namespace handling for Radicale responses

Radicale uses default DAV: namespace (no d: prefix) and CR: for CardDAV
instead of c:. Fixed all regex patterns to handle both variants:
- <href> and <d:href>
- <displayname> and <d:displayname>
- <CR:address-data> and <c:address-data>
- <C:calendar-data> and <c:calendar-data>
- </response> and </d:response>

Also fixed calendar discovery to match <C:calendar/> resourcetype
instead of looking for VEVENT string in the response.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Stefan Lohmaier
2026-06-12 10:17:14 +02:00
parent 45cd6935fb
commit 80fc323374
3 changed files with 21 additions and 12 deletions
+8 -4
View File
@@ -36,11 +36,15 @@ def _discover(user, comp):
cols = []
for base in CAL_PATHS.get(user, []):
xml = _propfind(RADICALE + base, auth)
for m in re.finditer(r'<d:href>([^<]+)</d:href>', xml):
for m in re.finditer(r'<(?:d:)?href>([^<]+)</(?:d:)?href>', xml):
href = m.group(1)
if href.rstrip("/") == base.rstrip("/"): continue
block = xml[m.start():xml.find("</d:response>", m.end())]
if comp not in block: continue
block = xml[m.start():xml.find("</response>", m.end())]
# Radicale returns <C:calendar/> or <CR:addressbook/> as resourcetype
# Match calendar collections (both VEVENT and VTODO live in calendars)
is_calendar = "calendar" in block.lower() and "addressbook" not in block.lower()
if comp in ("VEVENT", "VTODO") and not is_calendar:
continue
nm = re.search(r'<d:displayname>([^<]*)</d:displayname>', block)
cols.append({"name": nm.group(1) if nm else href.split("/")[-2], "href": href})
return cols
@@ -56,7 +60,7 @@ def _report_tasks(href, auth, inc=False):
def _parse(xml, comp="VEVENT"):
objs = []
for m in re.finditer(r'<c:calendar-data[^>]*>(.*?)</c:calendar-data>', xml, re.DOTALL):
for m in re.finditer(r'<(?:c|C):calendar-data[^>]*>(.*?)</(?:c|C):calendar-data>', xml, re.DOTALL):
raw = m.group(1).replace("&lt;","<").replace("&gt;",">").replace("&amp;","&")
try:
for c in vobject.readOne(raw).components():