From 8bcd43742aa561d3d57131db3a4f302f6593f16d Mon Sep 17 00:00:00 2001 From: Peter Bieringer Date: Sun, 21 Jun 2026 16:30:53 +0200 Subject: [PATCH] add test whether vobject supports PERIOD --- radicale/item/__init__.py | 21 +++++++++++++++++++++ radicale/utils.py | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/radicale/item/__init__.py b/radicale/item/__init__.py index 17ef72fb..17cb66fb 100644 --- a/radicale/item/__init__.py +++ b/radicale/item/__init__.py @@ -200,6 +200,27 @@ def check_and_sanitize_items( logger.trace("ITEM/check_and_sanitize_item: remove existing tzinfo (dtstart has none): '%s' -> '%s'", date, dates.value[i]) if all(type(d) is type(ref_date) for d in dates.value): continue + if dates.params.get("VALUE") == ["PERIOD"]: + if not utils.vobject_supports_period(): + raise ValueError("PERIOD not supported by used vobject=%s in object %r" % (utils.package_version("vobject"), component_uid)) + # period = period-explicit / period-start + # period-explicit = date-time "/" date-time + # period-start = date-time "/" dur-value + for i, date in enumerate(dates.value): + if not isinstance(date, tuple): + raise ValueError("invalid PERIOD (not a tuple) in object %r" % component_uid) + if len(date) != 2: + raise ValueError("invalid PERIOD (not 2 elements) in object %r" % component_uid) + if type(date[0]) is datetime.datetime and type(date[1]) is datetime.datetime: + if (date[0] > date[1]): + raise ValueError("invalid PERIOD (end before start) in object %r" % component_uid) + # skip explicit tzinfo check for now, no buggy client known + logger.trace("ITEM/check_and_sanitize_item: PERIOD/start-stop found: '%s'", date) + elif type(date[0]) is datetime.datetime and type(date[1]) is datetime.timedelta: + logger.trace("ITEM/check_and_sanitize_item: PERIOD/start-duration found: '%s'", date) + else: + raise ValueError("invalid PERIOD (element types not matching) in object %r" % component_uid) + continue for i, date in enumerate(dates.value): dates.value[i] = ref_date.replace( date.year, date.month, date.day) diff --git a/radicale/utils.py b/radicale/utils.py index eba1fa30..dbf8b8eb 100644 --- a/radicale/utils.py +++ b/radicale/utils.py @@ -27,6 +27,8 @@ from importlib import import_module, metadata from string import ascii_letters, digits, punctuation from typing import Callable, Sequence, Tuple, Type, TypeVar, Union +import vobject + from radicale import config from radicale.log import logger @@ -107,6 +109,43 @@ def vobject_supports_vcard4() -> bool: return False +# global cache +vobject_supports_period_cache: Union[bool, None] = None + + +def vobject_supports_period() -> bool: + """Check if vobject supports period (requires version > 0.9.9).""" + global vobject_supports_period_cache + + if vobject_supports_period_cache is not None: + return vobject_supports_period_cache + + content_test = """ +BEGIN:VCALENDAR +VERSION:2.0 +PRODID:test +BEGIN:VEVENT +UID:test-rdate-period-time-start-stop +DTSTART:20000101T000000Z +DURATION:PT1H +DESCRIPTION:event with rdate period start and stop +DTSTAMP:20000101T000000Z +RDATE;VALUE=PERIOD:20000102T000000Z/20000402T000000Z +RRULE:FREQ=WEEKLY +END:VEVENT +END:VCALENDAR +""" + obj = vobject.readOne(content_test) + + try: + obj.serialize() + except Exception: + vobject_supports_period_cache = False + else: + vobject_supports_period_cache = True + return vobject_supports_period_cache + + def packages_version(): versions = [] versions.append("python=%s.%s.%s" % (sys.version_info[0], sys.version_info[1], sys.version_info[2]))