diff --git a/khal/khalendar/event.py b/khal/khalendar/event.py index 8fda097e5..294d59f7d 100644 --- a/khal/khalendar/event.py +++ b/khal/khalendar/event.py @@ -837,7 +837,21 @@ def delete_instance(self, instance: dt.datetime) -> None: @property def status(self) -> str: - return self._vevents[self.ref].get("STATUS", "") + status = self._vevents[self.ref].get("STATUS", "") + # Some malformed events have multiple status entries. Only use the + # last one. + if isinstance(status, list): + if status: + status = status[-1] + logger.warning( + f'{self.href} ("{self.summary}"): The event contains ' + "multiple 'STATUS' entries, which is invalid as per " + "RFC 5545. Khal will assume the last entry is " + f"intended ({status})" + ) + else: + status = "" + return status @property def partstat(self) -> str | None: diff --git a/tests/event_test.py b/tests/event_test.py index c33e4ed94..0a05c6027 100644 --- a/tests/event_test.py +++ b/tests/event_test.py @@ -364,6 +364,20 @@ def test_event_rd(): assert event.recurring is True +def test_status_multiple(): + event = Event.fromString(_get_text("event_dt_status_multiple"), **EVENT_KWARGS) + assert event.status == "CONFIRMED" + FORMAT_CALENDAR = ( + "{calendar-color}{status-symbol}{start-end-time-style} ({calendar}) " + "{title} [{location}]{repeat-symbol}" + ) + + assert ( + human_formatter(FORMAT_CALENDAR)(event.attributes(dt.date(2014, 4, 9))) + == "✔09:30-10:30 (foobar) An Event []\x1b[0m" + ) + + def test_status_confirmed(): event = Event.fromString(_get_text("event_dt_status_confirmed"), **EVENT_KWARGS) assert event.status == "CONFIRMED" diff --git a/tests/ics/event_dt_status_multiple.ics b/tests/ics/event_dt_status_multiple.ics new file mode 100644 index 000000000..e99a97d17 --- /dev/null +++ b/tests/ics/event_dt_status_multiple.ics @@ -0,0 +1,13 @@ +BEGIN:VCALENDAR +VERSION:2.0 +PRODID:-//PIMUTILS.ORG//NONSGML khal / icalendar //EN +BEGIN:VEVENT +SUMMARY:An Event +DTSTART;TZID=Europe/Berlin:20140409T093000 +DTEND;TZID=Europe/Berlin:20140409T103000 +DTSTAMP:20140401T234817Z +UID:V042MJ8B3SJNFXQOJL6P53OFMHJE8Z3VZWOU +STATUS:TENTATIVE +STATUS:CONFIRMED +END:VEVENT +END:VCALENDAR