From 220c18170fff3b7ba4e65758cf7fb84bccb328b3 Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Wed, 25 Nov 2026 12:05:06 +0100 Subject: [PATCH] Offer a home set that is itself a calendar as a task list (#180) --- CHANGELOG.md | 2 + .../jeanlucmakiola/caldav/CalDavDiscovery.kt | 13 +++-- .../caldav/CalDavDiscoveryTest.kt | 57 +++++++++++++++++++ 3 files changed, 68 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca31fa1..aa79841 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -96,6 +96,8 @@ All notable changes to this project are documented here. The format follows the next occurrence showed them already ticked. Unticking gives them back their state and dates, and repeating sub-tasks keep their own schedule (#160). +- CalDAV accounts on servers that give each calendar its own account, such as + all-inkl.com, find their task list instead of reporting none (#180). ## [1.3.1] - 2026-11-09 diff --git a/caldav/src/main/kotlin/de/jeanlucmakiola/caldav/CalDavDiscovery.kt b/caldav/src/main/kotlin/de/jeanlucmakiola/caldav/CalDavDiscovery.kt index ec5e0e0..09c9dfe 100644 --- a/caldav/src/main/kotlin/de/jeanlucmakiola/caldav/CalDavDiscovery.kt +++ b/caldav/src/main/kotlin/de/jeanlucmakiola/caldav/CalDavDiscovery.kt @@ -1,7 +1,7 @@ package de.jeanlucmakiola.caldav import at.bitfire.dav4jvm.DavResource -import at.bitfire.dav4jvm.Response +import at.bitfire.dav4jvm.UrlUtils import at.bitfire.dav4jvm.property.CalendarHomeSet import at.bitfire.dav4jvm.exception.HttpException import at.bitfire.dav4jvm.property.CurrentUserPrincipal @@ -319,9 +319,14 @@ class CalDavDiscovery( for (homeSet in homeSets.distinct()) { val result = runCatching { - DavResource(httpClient, homeSet).propfind(1, *collectionProperties) { response, relation -> - if (relation == Response.HrefRelation.SELF) return@propfind - CollectionClassifier.classify(response)?.let { collections[it.url] = it } + // The home set itself is classified too: all-inkl.com reports its + // one calendar as the home set (#180). A plain home collection is + // not a calendar, so the classifier drops it as before. Keyed + // slash-insensitively, since the self href may lack the slash. + DavResource(httpClient, homeSet).propfind(1, *collectionProperties) { response, _ -> + CollectionClassifier.classify(response)?.let { + collections[UrlUtils.withTrailingSlash(it.url)] = it + } } } result.fold( diff --git a/caldav/src/test/kotlin/de/jeanlucmakiola/caldav/CalDavDiscoveryTest.kt b/caldav/src/test/kotlin/de/jeanlucmakiola/caldav/CalDavDiscoveryTest.kt index 65c0e6c..3d0880a 100644 --- a/caldav/src/test/kotlin/de/jeanlucmakiola/caldav/CalDavDiscoveryTest.kt +++ b/caldav/src/test/kotlin/de/jeanlucmakiola/caldav/CalDavDiscoveryTest.kt @@ -245,6 +245,63 @@ class CalDavDiscoveryTest { assertThat(collections.single().isShared).isTrue() } + /** The all-inkl.com shape (#180): the home set is the account's one calendar. */ + private fun calendarAsHomeSet(componentSet: String, vararg members: String) = multistatus( + """ + + ${collection("/calendars/user/1/", "", componentSet, displayName = "Kalender")} + ${members.joinToString("\n")} + + """.trimIndent(), + ) + + private val eventsAndTasks = """""" + + private val taskResource = """ + + /calendars/user/1/0a1b2c.ics + HTTP/1.1 200 OK + + """ + + @Test + fun `a home set that is itself a calendar is offered as a list`() { + server.enqueue(homeSetResponse("/calendars/user/1/")) + server.enqueue(calendarAsHomeSet(eventsAndTasks, taskResource)) + + val found = discovery.fromPrincipal(server.url("/calendars/principals/user/")) as CalDavDiscovery.Outcome.Found + assertThat(found.collections.map { it.url.encodedPath }).containsExactly("/calendars/user/1/") + assertThat(found.collections.single().displayName).isEqualTo("Kalender") + } + + @Test + fun `a home set listed both as itself and as a member is offered once`() { + server.enqueue(homeSetResponse("/calendars/user/1/")) + server.enqueue( + calendarAsHomeSet( + eventsAndTasks, + collection("/calendars/user/1", "", eventsAndTasks, displayName = "Kalender"), + ), + ) + + val found = discovery.fromPrincipal(server.url("/calendars/principals/user/")) as CalDavDiscovery.Outcome.Found + assertThat(found.collections.map { it.url.encodedPath.trimEnd('/') }).containsExactly("/calendars/user/1") + } + + @Test + fun `a home set that is a VEVENT-only calendar is not a list`() { + server.enqueue(homeSetResponse("/calendars/user/1/")) + server.enqueue( + calendarAsHomeSet( + """""", + taskResource, + ), + ) + + val found = discovery.fromPrincipal(server.url("/calendars/principals/user/")) as CalDavDiscovery.Outcome.Found + assertThat(found.collections).isEmpty() + } + @Test fun `a principal with no home set is a failure worth naming`() { server.enqueue(homeSetResponse())