Skip to content

Commit 70ced6a

Browse files
committed
fix: read RFC 10051 statuses from their own hint
caldav now records PENDING and FAILED apart from RFC 5545's four statuses (save-load.todo.status.rfc10051), since a server not supporting RFC 10051 need not keep them. A task list declares the statuses both hints keep, and a status no hint knows to be kept is left out. On Ox, which keeps the four and drops the two, the values are as before; the note now says Ox does not advertise RFC 10051. Prompts: (on the save-load.todo.status hint, in the caldav review) Note for "save-load.todo.status" - a server may or may not support RFC 10051. We can only demand it to support FAILED and PENDING if the server declares support for RFC 50051 (sic). If there are many servers acceptign (sic) all the RFC 5545 statuses but not accepting FAILED and PENDING, then maybe we need to split out a child for the RFC 10051-statuses Followup-Prompt: (...) save-load.todo.status.rfc10051 is fine. (...) Assisted-By: Claude Opus 5.5 <noreply@anthropic.com> Reviewed-by: Tobias Brox <tobias@redpill-linpro.com>
1 parent 0af710b commit 70ced6a

2 files changed

Lines changed: 72 additions & 13 deletions

File tree

‎src/calendaring/_caldav_features.py‎

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,14 @@
6868
Feature.TASK_ESTIMATE: "save-load.icalendar.unknown-property", # probed with ESTIMATED-DURATION
6969
}
7070

71-
# Feature -> the caldav feature listing the values a task keeps (``values``), and stores as another (``map``).
71+
# Feature -> the caldav features listing the values a task keeps (``values``) and stores as another
72+
# (``map``), each with the values it probes: what is kept where the server keeps them all.
7273
VALUES_FROM_SERVER = {
73-
Feature.TASK_STATUS: "save-load.todo.status",
74-
Feature.TASK_PRIORITY: "save-load.todo.priority",
74+
Feature.TASK_STATUS: (
75+
("save-load.todo.status", ("NEEDS-ACTION", "IN-PROCESS", "COMPLETED", "CANCELLED")),
76+
("save-load.todo.status.rfc10051", ("PENDING", "FAILED")), # Ox drops them, Zimbra maps them
77+
),
78+
Feature.TASK_PRIORITY: (("save-load.todo.priority", tuple(range(10))),),
7579
}
7680

7781
COMPONENT_FROM_SERVER = {
@@ -204,14 +208,33 @@ def stored_components(features: Any, listed: frozenset[Component]) -> frozenset[
204208
return frozenset(c for c in listed if _level(features, COMPONENT_FROM_SERVER[c][1]) is not U)
205209

206210

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+
def _values(features: Any, feature: Feature) -> dict[str, Any] | None:
212+
"""LOSSY with the values the server keeps, where one of the hints says it does not keep them all.
213+
A refused value is left out, as is a dropped one: the loss planner drops it before sending.
214+
PRIORITY:0 is not sent as the server's stand-in either (Ox: 5), since no PRIORITY means the same as 0."""
215+
hints = VALUES_FROM_SERVER[feature]
216+
if not any(_level(features, name) is U for name, _ in hints):
217+
return None
211218
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}
219+
values: list[Any] = []
220+
mapping: dict[Any, Any] = {}
221+
notes = []
222+
seen: list[dict[str, Any]] = []
223+
for name, probed in hints:
224+
level = _level(features, name)
225+
if level is F:
226+
values.extend(probed)
227+
if level is not U:
228+
continue # unknown: nothing is known to be kept
229+
hint = features.is_supported(name, dict)
230+
if hint in seen: # caldav answers a child with its parent's node where only the parent is set
231+
continue
232+
seen.append(hint)
233+
values.extend(number(v) for v in hint.get("values", []))
234+
mapping.update({number(k): number(v) for k, v in hint.get("map", {}).items() if number(k) != 0})
235+
if hint.get("behaviour"):
236+
notes.append(hint["behaviour"])
237+
return {"level": L, "values": values, "map": mapping, "note": "; ".join(notes) or None}
215238

216239

217240
def multiget_serves_deleted(features: Any) -> bool:
@@ -256,9 +279,9 @@ def collection_capabilities(features: Any, components: frozenset[Component]) ->
256279
for feature, name in lowered.items():
257280
if _level(features, name) is U:
258281
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))
282+
for feature in VALUES_FROM_SERVER: # Ox keeps priorities 1, 5 and 9; Zimbra refuses CANCELLED
283+
if (declared := _values(features, feature)) is not None:
284+
table[feature] = declared
262285
stable_url = features.is_supported("save-load.stable-url", dict) if _hinted(features) else {}
263286
if stable_url.get("forces_uid_ics"):
264287
table[Feature.IDENTITY_CLIENT_NATIVE_ID] = {"level": U, "note": "the server renames every object <uid>.ics"}

‎tests/test_caldav_features.py‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,42 @@ def test_statuses_a_task_list_does_not_keep() -> None:
185185
assert collection_capabilities(server, frozenset({Component.EVENT})).level(Feature.TASK_STATUS) is not Support.LOSSY
186186

187187

188+
@needs_hint("save-load.todo.status.rfc10051")
189+
def test_rfc_10051_statuses_lost_where_the_rfc_5545_ones_are_kept() -> None:
190+
"""Ox keeps RFC 5545's four statuses and drops PENDING and FAILED."""
191+
from caldav import compatibility_hints
192+
193+
server = features({"save-load": {"support": "full"}, **compatibility_hints.ox})
194+
table = collection_capabilities(server, frozenset({Component.TASK}))
195+
details = table.details(Feature.TASK_STATUS)
196+
assert details["values"] == ["NEEDS-ACTION", "IN-PROCESS", "COMPLETED", "CANCELLED"]
197+
assert details["map"] == {}
198+
assert "does not advertise RFC 10051" in (table[Feature.TASK_STATUS].note or "")
199+
200+
201+
@needs_hint("save-load.todo.status.rfc10051")
202+
def test_a_parent_status_hint_alone_is_not_counted_twice() -> None:
203+
"""caldav answers the child with the parent's node where only the parent is set."""
204+
hint = {"support": "ungraceful", "values": ["NEEDS-ACTION", "IN-PROCESS", "COMPLETED"], "refused": ["CANCELLED"]}
205+
server = features({"save-load": {"support": "full"}, "save-load.todo.status": hint})
206+
details = collection_capabilities(server, frozenset({Component.TASK})).details(Feature.TASK_STATUS)
207+
assert details["values"] == ["NEEDS-ACTION", "IN-PROCESS", "COMPLETED"]
208+
209+
210+
@needs_hint("save-load.todo.status.rfc10051")
211+
def test_statuses_not_known_to_be_kept_are_not_declared_kept() -> None:
212+
"""A hint the tester could not settle says nothing kept: PENDING and FAILED are left out."""
213+
server = features(
214+
{
215+
"save-load": {"support": "full"},
216+
"save-load.todo.status": {"support": "unsupported", "values": ["NEEDS-ACTION"]},
217+
"save-load.todo.status.rfc10051": {"support": "unknown"},
218+
}
219+
)
220+
details = collection_capabilities(server, frozenset({Component.TASK})).details(Feature.TASK_STATUS)
221+
assert details["values"] == ["NEEDS-ACTION"]
222+
223+
188224
@needs_hint("save-load.todo.priority")
189225
def test_priority_zero_is_left_out_not_sent_as_the_servers_stand_in() -> None:
190226
"""Ox keeps 1, 5 and 9 and stores 0 as 5; no PRIORITY means the same as 0."""

0 commit comments

Comments
 (0)