Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for processing and importing ics without UID #1082

Merged
merged 1 commit into from
Feb 3, 2022
Merged
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
7 changes: 7 additions & 0 deletions khal/icalendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import logging
import pytz
from collections import defaultdict
from hashlib import sha256

from .exceptions import UnsupportedRecurrence
from .parse_datetime import guesstimedeltafstr, rrulefstr
Expand Down Expand Up @@ -62,6 +63,12 @@ def split_ics(ics, random_uid=False, default_timezone=None):
tzs[key] = item

if item.name == 'VEVENT':
if 'UID' not in item:
logger.warning(
f"Event with summary '{item['SUMMARY']}' doesn't have a unique ID."
"A generated ID will be used instead."
)
item['UID'] = sha256(item.to_ical()).hexdigest()
events_grouped[item['UID']].append(item)
else:
continue
Expand Down
8 changes: 8 additions & 0 deletions tests/icalendar_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,11 @@ def test_windows_timezone(caplog):
cal = _get_text("tz_windows_format")
split_ics(cal)
assert "Cannot find timezone `Pacific/Auckland`" not in caplog.text


def test_split_ics_without_uid():
cal = _get_text('without_uid')
vevents = split_ics(cal)
assert vevents
vevents2 = split_ics(cal)
assert vevents[0] == vevents2[0]
10 changes: 10 additions & 0 deletions tests/ics/without_uid.ics
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//PIMUTILS.ORG//NONSGML khal / icalendar //EN
BEGIN:VEVENT
SUMMARY:An Event
DTSTART;VALUE=DATE:20140409
DTEND;VALUE=DATE:20140410
DTSTAMP;VALUE=DATE-TIME:20140401T234817Z
END:VEVENT
END:VCALENDAR