Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion khal/khalendar/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 14 additions & 0 deletions tests/event_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
13 changes: 13 additions & 0 deletions tests/ics/event_dt_status_multiple.ics
Original file line number Diff line number Diff line change
@@ -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
Loading