Bound calendar recurrence expansion and retain MQTT license

This commit is contained in:
Pigway
2026-10-08 23:52:06 +08:00
parent 8209aadbb8
commit 32229609c9
4 changed files with 94 additions and 3 deletions
+21 -3
View File
@@ -50,6 +50,12 @@ def calendar_events(raw, now=None):
for props, start, uid, override in parsed:
if props.get("STATUS", [(None, "")])[0][1] == "CANCELLED":
continue
if "EXRULE" in props:
raise FlowError(
E.UNSUPPORTED_CAPABILITY,
"Use EXDATE instead of unsupported EXRULE",
422,
)
occurrences = [start]
if "RRULE" in props and not override:
rule = props["RRULE"][0][1]
@@ -63,9 +69,21 @@ def calendar_events(raw, now=None):
raise FlowError(
E.INVALID_REQUEST, "Calendar recurrence starts too far in the past"
)
occurrences = rrulestr(rule, dtstart=start).between(
now - timedelta(days=1), end, inc=True
)
if len(rule) > 1000:
raise FlowError(
E.INVALID_REQUEST, "Calendar recurrence rule is too long"
)
occurrences = []
for occurrence in rrulestr(rule, dtstart=start).xafter(
now - timedelta(days=1), count=1001, inc=True
):
if occurrence >= end:
break
occurrences.append(occurrence)
if len(occurrences) > 1000:
raise FlowError(
E.INVALID_REQUEST, "Calendar recurrence exceeds 1000 instances"
)
for key, value in props.get("RDATE", []):
occurrences.extend(stamp(key, item) for item in value.split(","))
excluded = {