Skip to content

Commit 0af710b

Browse files
committed
fix: declare what caldav's hints record
The capability table ignored many of caldav's hints, so it claimed full support where a server drops or refuses data. Task lists now declare what Ox and Zimbra lose (attendees, recurrences, X- and unknown properties, STATUS and PRIORITY values, object names), and time entries go without users where six servers refuse PARTICIPANT. Where a multiget returns deleted objects (Zimbra), an object is read with a GET. Hints an older caldav lacks read as unknown. Prompt: [do the remaining conformance-triage work (unmapped caldav hints, new caldav-server-tester checks and caldav profile updates) now] Assisted-By: Claude Opus 5.5 <noreply@anthropic.com> Reviewed-by: Tobias Brox <tobias@redpill-linpro.com>
1 parent 1b3e573 commit 0af710b

18 files changed

Lines changed: 358 additions & 7 deletions

‎news/+caldav-hints.bugfix.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The CalDAV backend now declares what caldav's hints already record: a task list on Ox stores no attendees, recurrences or X- properties (so no planned times), Ox and Zimbra drop ``ESTIMATED-DURATION``, and Zimbra renames every object to ``<uid>.ics``, so ``identity.client-native-id`` is unsupported there. Where the server refuses an event holding a ``PARTICIPANT`` (CCS, Bedework 3, robur, GMX, Ox, Zimbra), ``time-log`` is ``lossy`` with ``users`` lost, and entries are written without their users instead of being refused.

‎news/+caldav-values.bugfix.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
With a caldav whose hints record them, the CalDAV backend declares the ``STATUS`` and ``PRIORITY`` values a server's task lists keep (Ox: priorities 1, 5 and 9; Zimbra: no ``CANCELLED``), ``write.wire`` unsupported where X- parameters are dropped, and ``identity.client-native-id`` unsupported in Ox task lists. On Zimbra, whose calendar-multiget still returns deleted objects, an object is read with a GET. ``PRIORITY:0`` is left out rather than stored as another priority. The conformance suite's ``test_values_map_as_declared`` no longer adds one item twice, which failed on a backend keeping the client's UID.

‎src/calendaring/_async/caldav.py‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@
2121
import icalendar
2222
from icalendar_searcher import Searcher
2323

24-
from .._caldav_features import backend_capabilities, collection_capabilities, stored_components
24+
from .._caldav_features import (
25+
backend_capabilities,
26+
collection_capabilities,
27+
multiget_serves_deleted,
28+
stored_components,
29+
)
2530
from .._caldav_io import Calendar
2631
from ..capabilities import Feature
2732
from ..errors import (
@@ -115,6 +120,8 @@ def _kinds(self, searcher: Searcher | None) -> frozenset[Component]:
115120
return self.components & wanted if wanted else self.components
116121

117122
async def _fetch(self, native_id: str) -> StoredObject:
123+
if multiget_serves_deleted(self._backend._dav.client.features): # Zimbra
124+
return self._stored(await self._backend._dav.get(self.calendar, self._href(native_id)))
118125
for obj in await self._backend._dav.multiget(self.calendar, [self._href(native_id)]):
119126
if obj.data is not None: # caldav returns a missing href as an object without data
120127
return self._stored(obj)

‎src/calendaring/_async/collection.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,15 +283,21 @@ async def _time_entries(
283283
async def _time_log(self, item: Item) -> list[TimeEntry]:
284284
return [entry for _, entry in await self._log_target()._time_entries(None, None, parent=item.uid)]
285285

286+
def _storable_entry(self, entry: TimeEntry) -> TimeEntry:
287+
"""``entry`` less the users the log collection declares lost: a server refusing them would refuse it all."""
288+
lost = self._log_target().capabilities.details(Feature.TIME_LOG).get("lost", ())
289+
return replace(entry, users=()) if "users" in lost else entry
290+
286291
async def _add_time(self, item: Item, entry: TimeEntry) -> TimeEntry:
292+
entry = self._storable_entry(entry)
287293
stored = await self._log_target().add(Event(_wrap_component(entry_to_component(entry, parent=item))))
288294
return entry_from_component(stored.component)[1]
289295

290296
async def _amend_time(self, item: Item, old: TimeEntry, new: TimeEntry) -> TimeEntry:
291297
assert old.id is not None
292298
stored = await self._log_target().get(old.id)
293299
component = stored.component # edited in place: what other clients added stays
294-
apply_entry(component, new)
300+
apply_entry(component, self._storable_entry(new))
295301
sequence = int(component.pop("SEQUENCE", 0))
296302
for name, value in (("SEQUENCE", sequence + 1), ("LAST-MODIFIED", datetime.now(UTC))):
297303
component.pop(name, None)

‎src/calendaring/_async/conformance.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,9 @@ async def test_values_map_as_declared(self, collection: AsyncCollection, feature
825825
def policy(losses: Sequence[Loss], item: Item) -> None:
826826
seen.append(losses)
827827

828-
await collection.add(item, loss=policy)
828+
again = Task.new(summary=f"{name} outside, again") # the first is stored now, under its UID
829+
again.component[name] = outside[0]
830+
await collection.add(again, loss=policy)
829831
assert [[loss.property for loss in losses] for losses in seen] == [[name]]
830832
assert seen[0][0].sent == outside[0]
831833

‎src/calendaring/_async/dav.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,14 @@ async def multiget(self, calendar: Calendar, urls: list[str]) -> list[CalendarOb
8282
found: Any = calendar.multiget([URL.objectify(u) for u in urls])
8383
return list(await _awaited(cast(Any, found)))
8484

85+
async def get(self, calendar: Calendar, url: str) -> CalendarObjectResource:
86+
"""The object at ``url``, read with a GET: ``NotFoundError`` if it is gone."""
87+
obj = _resource(self.client, calendar, url)
88+
with translated():
89+
# No multiget fallback: the reason to GET is a multiget serving deleted objects.
90+
await _awaited(obj.load(multiget_fallback=False))
91+
return obj
92+
8593
async def etags(self, url: str) -> dict[str, str]:
8694
with translated():
8795
# Positional: the sync client's second parameter is props=, which also takes an XML body.

‎src/calendaring/_caldav_features.py‎

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,26 @@
5454
Feature.TASK_UNCOMPLETE: "save-load.todo.uncomplete",
5555
}
5656

57+
# Feature -> the caldav feature probed on a task. A level is the collection's, not a component's, so
58+
# a calendar holding events too keeps these: lowering them would cost its events what they can keep.
59+
TASK_FROM_SERVER = {
60+
Feature.ATTENDEES: "save-load.todo.attendee",
61+
Feature.RECURRENCE: "save-load.todo.recurrences",
62+
Feature.PROPERTIES_PASSTHROUGH: "save-load.icalendar.x-property", # Ox drops X- properties from tasks only
63+
}
64+
65+
# The same for what only a task has: lowered wherever tasks are held.
66+
TASK_ONLY_FROM_SERVER = {
67+
Feature.TASK_PLANNED: "save-load.icalendar.x-property", # X-PYCAL-PLANNED-*
68+
Feature.TASK_ESTIMATE: "save-load.icalendar.unknown-property", # probed with ESTIMATED-DURATION
69+
}
70+
71+
# Feature -> the caldav feature listing the values a task keeps (``values``), and stores as another (``map``).
72+
VALUES_FROM_SERVER = {
73+
Feature.TASK_STATUS: "save-load.todo.status",
74+
Feature.TASK_PRIORITY: "save-load.todo.priority",
75+
}
76+
5777
COMPONENT_FROM_SERVER = {
5878
Component.EVENT: (Feature.COMPONENT_EVENT, "save-load.event"),
5979
Component.TASK: (Feature.COMPONENT_TASK, "save-load.todo"),
@@ -80,7 +100,7 @@ def _hinted(features: Any) -> bool:
80100

81101

82102
def _level(features: Any, name: str) -> Support:
83-
if not _hinted(features):
103+
if not _hinted(features) or name not in getattr(features, "FEATURES", {name}): # a hint newer than this caldav
84104
return X
85105
return LEVELS.get(str(features.is_supported(name, str)), X)
86106

@@ -184,6 +204,21 @@ def stored_components(features: Any, listed: frozenset[Component]) -> frozenset[
184204
return frozenset(c for c in listed if _level(features, COMPONENT_FROM_SERVER[c][1]) is not U)
185205

186206

207+
def _values(feature: Feature, hint: dict[str, Any]) -> dict[str, Any]:
208+
"""LOSSY with the values the server keeps. A refused one is left out, as is a dropped one:
209+
the loss planner drops it before sending. PRIORITY:0 is not sent as the server's
210+
stand-in either (Ox: 5), since no PRIORITY means the same as 0."""
211+
number = int if feature is Feature.TASK_PRIORITY else str # a hint from YAML or JSON may carry "5"
212+
mapping = {number(k): number(v) for k, v in hint.get("map", {}).items() if number(k) != 0}
213+
values = [number(v) for v in hint.get("values", [])]
214+
return {"level": L, "values": values, "map": mapping, "note": hint.get("behaviour") or None}
215+
216+
217+
def multiget_serves_deleted(features: Any) -> bool:
218+
"""Zimbra answers a GET of a deleted object with 404, and a calendar-multiget of it with the old data."""
219+
return _level(features, "multiget.deleted") is U
220+
221+
187222
def backend_capabilities(features: Any) -> Capabilities:
188223
return Capabilities({f: v for f, v in _table(features).items() if f in BACKEND_FEATURES})
189224

@@ -210,5 +245,31 @@ def collection_capabilities(features: Any, components: frozenset[Component]) ->
210245
}
211246
if _level(features, "save-load.icalendar.related-to") is U:
212247
table[Feature.TIME_LOG] = {"level": U, "note": "the server strips RELATED-TO, which ties an entry to its item"}
248+
elif _level(features, "save-load.icalendar.participant") is U:
249+
table[Feature.TIME_LOG] = {
250+
"level": L,
251+
"lost": ["users"],
252+
"note": "the server refuses an event with a PARTICIPANT, which names who did the work",
253+
}
254+
if Component.TASK in components:
255+
lowered = {**TASK_ONLY_FROM_SERVER, **(TASK_FROM_SERVER if Component.EVENT not in components else {})}
256+
for feature, name in lowered.items():
257+
if _level(features, name) is U:
258+
table[feature] = U
259+
for feature, name in VALUES_FROM_SERVER.items():
260+
if _level(features, name) is U: # Ox keeps priorities 1, 5 and 9; Zimbra refuses CANCELLED
261+
table[feature] = _values(feature, features.is_supported(name, dict))
262+
stable_url = features.is_supported("save-load.stable-url", dict) if _hinted(features) else {}
263+
if stable_url.get("forces_uid_ics"):
264+
table[Feature.IDENTITY_CLIENT_NATIVE_ID] = {"level": U, "note": "the server renames every object <uid>.ics"}
265+
elif renamed := sorted(c.value for c in components if c.value in stable_url.get("uid_ics_components", ())):
266+
table[Feature.IDENTITY_CLIENT_NATIVE_ID] = {"level": U, "note": f"the server renames a {', '.join(renamed)} <uid>.ics"}
267+
x_property = features.is_supported("save-load.icalendar.x-property", dict) if _hinted(features) else {}
268+
if _level(features, "save-load.icalendar.x-property") is U and not x_property.get("behaviour", "").endswith(
269+
"in a task"
270+
): # dropped from events too
271+
table[Feature.PROPERTIES_PASSTHROUGH] = U
272+
if _level(features, "save-load.icalendar.x-parameter") is U:
273+
table[Feature.WRITE_WIRE] = {"level": U, "note": "the server drops X- parameters: bytes are not stored as sent"}
213274
held_only(table, components)
214275
return Capabilities({f: Capability.coerce(v) for f, v in table.items()})

‎src/calendaring/_sync/caldav.py‎

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/calendaring/_sync/collection.py‎

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/calendaring/_sync/conformance.py‎

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)