diff --git a/CHANGELOG.md b/CHANGELOG.md index aa79841..cf371d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -59,6 +59,10 @@ All notable changes to this project are documented here. The format follows all-day reminder time. With a tasks app as the store, both ends gain or drop their time together (#101). +### Fixed +- 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.2] - 2026-11-13 ### Added @@ -96,8 +100,6 @@ 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/app/src/full/java/de/jeanlucmakiola/agendula/data/sync/RemoteListRepository.kt b/app/src/full/java/de/jeanlucmakiola/agendula/data/sync/RemoteListRepository.kt index 98ba699..7441ea1 100644 --- a/app/src/full/java/de/jeanlucmakiola/agendula/data/sync/RemoteListRepository.kt +++ b/app/src/full/java/de/jeanlucmakiola/agendula/data/sync/RemoteListRepository.kt @@ -107,7 +107,6 @@ class RemoteListRepository @Inject constructor( val homeSet = account.homeSetUrl?.toHttpUrlOrNull() ?: return@withContext Outcome.NoAccount val admin = adminFor(account) ?: return@withContext Outcome.NoAccount - if (homeSetIsAList(account)) return@withContext Outcome.Unsupported val capabilities = support.refresh(accountId) { admin.support(homeSet) } if (!capabilities.canCreate) return@withContext Outcome.Unsupported @@ -234,17 +233,10 @@ class RemoteListRepository @Inject constructor( private suspend fun supportFor(account: AccountEntity): CollectionSupport { val homeSet = account.homeSetUrl?.toHttpUrlOrNull() ?: return CollectionSupport.NONE - if (homeSetIsAList(account)) return CollectionSupport.NONE val admin = adminFor(account) ?: return CollectionSupport.NONE return support.refresh(account.id) { admin.support(homeSet) } } - /** A home set that is itself a calendar (#180) cannot hold another one. */ - private fun homeSetIsAList(account: AccountEntity): Boolean { - val homeSet = account.homeSetUrl?.trimEnd('/') ?: return false - return database.taskLists().syncedForAccount(account.id).any { it.href?.trimEnd('/') == homeSet } - } - /** * Null when the account has no credential we can use — a stopped account, or * a restore. diff --git a/caldav/src/main/kotlin/de/jeanlucmakiola/caldav/CalDavDiscovery.kt b/caldav/src/main/kotlin/de/jeanlucmakiola/caldav/CalDavDiscovery.kt index 4c156ce..83f389c 100644 --- a/caldav/src/main/kotlin/de/jeanlucmakiola/caldav/CalDavDiscovery.kt +++ b/caldav/src/main/kotlin/de/jeanlucmakiola/caldav/CalDavDiscovery.kt @@ -320,21 +320,21 @@ class CalDavDiscovery( for (homeSet in homeSets.distinct()) { var self: TaskCollection? = null - var hasMemberCollections = false + var hasMemberCalendars = false val result = runCatching { DavResource(httpClient, homeSet).propfind(1, *collectionProperties) { response, relation -> if (relation == Response.HrefRelation.SELF) { if (self == null) self = CollectionClassifier.classify(response) return@propfind } - if (response[ResourceType::class.java]?.types?.contains(ResourceType.COLLECTION) == true) { - hasMemberCollections = true + if (response[ResourceType::class.java]?.types?.contains(ResourceType.CALENDAR) == true) { + hasMemberCalendars = true } CollectionClassifier.classify(response)?.let { collections[it.url] = it } } - // A home set that is itself a calendar with no collections in it - // is the account's one list, as on all-inkl.com (#180). - self?.takeIf { !hasMemberCollections }?.let { collections.putIfAbsent(it.url, it) } + // A home set that is itself a calendar with none inside it is the + // account's one list, as on all-inkl.com (#180). + self?.takeIf { !hasMemberCalendars }?.let { collections.putIfAbsent(it.url, it) } } result.fold( // A failed home set must not fail the account — the same rule the diff --git a/caldav/src/main/kotlin/de/jeanlucmakiola/caldav/CollectionAdmin.kt b/caldav/src/main/kotlin/de/jeanlucmakiola/caldav/CollectionAdmin.kt index 6364acf..a505fa2 100644 --- a/caldav/src/main/kotlin/de/jeanlucmakiola/caldav/CollectionAdmin.kt +++ b/caldav/src/main/kotlin/de/jeanlucmakiola/caldav/CollectionAdmin.kt @@ -1,8 +1,10 @@ package de.jeanlucmakiola.caldav +import at.bitfire.dav4jvm.DavResource import at.bitfire.dav4jvm.Property import at.bitfire.dav4jvm.XmlUtils import at.bitfire.dav4jvm.XmlUtils.insertTag +import at.bitfire.dav4jvm.property.ResourceType import okhttp3.HttpUrl import okhttp3.MediaType.Companion.toMediaType import okhttp3.OkHttpClient @@ -121,7 +123,7 @@ class DavCollectionAdmin( mkCalendar = "MKCALENDAR" in allow, extendedMkCol = "EXTENDED-MKCOL" in dav, ) - } + }.takeIf { !it.canCreate || !isCalendar(homeSet) } ?: CollectionSupport.NONE } catch (_: IOException) { // Unknown reads as "no", which costs the user an affordance they can // reach again on the next attempt — the other way round costs them a @@ -129,6 +131,19 @@ class DavCollectionAdmin( CollectionSupport.NONE } + /** A home set that is itself a calendar, as on all-inkl.com (#180), cannot hold another. */ + private fun isCalendar(homeSet: HttpUrl): Boolean { + var calendar = false + runCatching { + DavResource(httpClient, homeSet).propfind(0, ResourceType.NAME) { response, _ -> + if (response[ResourceType::class.java]?.types?.contains(ResourceType.CALENDAR) == true) { + calendar = true + } + } + } + return calendar + } + /** * ⚠️ MKCALENDAR first where both exist. It is the method written for this * job, every server that has it treats it as authoritative, and extended diff --git a/caldav/src/test/kotlin/de/jeanlucmakiola/caldav/CalDavDiscoveryTest.kt b/caldav/src/test/kotlin/de/jeanlucmakiola/caldav/CalDavDiscoveryTest.kt index a32dbff..fd7d5e6 100644 --- a/caldav/src/test/kotlin/de/jeanlucmakiola/caldav/CalDavDiscoveryTest.kt +++ b/caldav/src/test/kotlin/de/jeanlucmakiola/caldav/CalDavDiscoveryTest.kt @@ -302,6 +302,21 @@ class CalDavDiscoveryTest { assertThat(found.collections.map { it.url.encodedPath }).containsExactly("/calendars/user/1/tasks/") } + @Test + fun `a calendar home set holding only non-calendar collections is still offered`() { + server.enqueue(homeSetResponse("/calendars/user/1/")) + server.enqueue( + calendarAsHomeSet( + eventsAndTasks, + collection("/calendars/user/1/attachments/", ""), + 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/") + } + @Test fun `a home set that is a VEVENT-only calendar is not a list`() { server.enqueue(homeSetResponse("/calendars/user/1/")) diff --git a/caldav/src/test/kotlin/de/jeanlucmakiola/caldav/CollectionAdminTest.kt b/caldav/src/test/kotlin/de/jeanlucmakiola/caldav/CollectionAdminTest.kt index dce7577..6f8b284 100644 --- a/caldav/src/test/kotlin/de/jeanlucmakiola/caldav/CollectionAdminTest.kt +++ b/caldav/src/test/kotlin/de/jeanlucmakiola/caldav/CollectionAdminTest.kt @@ -39,6 +39,7 @@ class CollectionAdminTest { .setHeader("Allow", "OPTIONS, GET, PROPFIND, MKCOL") .setHeader("DAV", "1, 2, 3, calendar-access, extended-mkcol"), ) + server.enqueue(resourceType("")) val support = admin.support(homeSet()) @@ -47,6 +48,34 @@ class CollectionAdminTest { assertThat(support.canCreate).isTrue() } + @Test + fun `a home set that is itself a calendar offers nothing`() { + // all-inkl.com (#180): the home set is the account's one calendar, and + // a calendar cannot hold another. + server.enqueue( + MockResponse() + .setResponseCode(200) + .setHeader("Allow", "OPTIONS, GET, PROPFIND, MKCALENDAR") + .setHeader("DAV", "1, 2, 3, calendar-access, extended-mkcol"), + ) + server.enqueue(resourceType("")) + + assertThat(admin.support(homeSet())).isEqualTo(CollectionSupport.NONE) + } + + private fun resourceType(types: String) = MockResponse() + .setResponseCode(207) + .setHeader("Content-Type", "application/xml; charset=utf-8") + .setBody( + """ + + /dav/calendars/me/ + $types + HTTP/1.1 200 OK + + """.trimIndent(), + ) + @Test fun `a server offering neither offers nothing`() { server.enqueue(