|
68 | 68 | Feature.TASK_ESTIMATE: "save-load.icalendar.unknown-property", # probed with ESTIMATED-DURATION |
69 | 69 | } |
70 | 70 |
|
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. |
72 | 73 | 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))),), |
75 | 79 | } |
76 | 80 |
|
77 | 81 | COMPONENT_FROM_SERVER = { |
@@ -204,14 +208,33 @@ def stored_components(features: Any, listed: frozenset[Component]) -> frozenset[ |
204 | 208 | return frozenset(c for c in listed if _level(features, COMPONENT_FROM_SERVER[c][1]) is not U) |
205 | 209 |
|
206 | 210 |
|
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 |
211 | 218 | 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} |
215 | 238 |
|
216 | 239 |
|
217 | 240 | def multiget_serves_deleted(features: Any) -> bool: |
@@ -256,9 +279,9 @@ def collection_capabilities(features: Any, components: frozenset[Component]) -> |
256 | 279 | for feature, name in lowered.items(): |
257 | 280 | if _level(features, name) is U: |
258 | 281 | 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 |
262 | 285 | stable_url = features.is_supported("save-load.stable-url", dict) if _hinted(features) else {} |
263 | 286 | if stable_url.get("forces_uid_ics"): |
264 | 287 | table[Feature.IDENTITY_CLIENT_NATIVE_ID] = {"level": U, "note": "the server renames every object <uid>.ics"} |
|
0 commit comments