Skip to content

Commit

Permalink
[iCal] Handle multiple summaries
Browse files Browse the repository at this point in the history
Summary: Fixes T967. This is a pretty simple patch --- in the case where there's multiple SUMMARY lines in an iCalendar file, we join them with a " - ". It's the best we can do because every provider handles this differently, sometimes ignoring the second line (or the first) or joining them in random order.

Test Plan: Added regression test.

Reviewers: spang

Reviewed By: spang

Maniphest Tasks: T967

Differential Revision: https://review.inboxapp.com/D1385
  • Loading branch information
khamidou committed Apr 1, 2015
1 parent acbefb7 commit 9387e31
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
9 changes: 8 additions & 1 deletion inbox/events/ical.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,14 @@ def events_from_ics(namespace, calendar, ics_str):
assert last_modified is not None, \
"Event should have a DtStamp or LAST-MODIFIED timestamp"

title = component.get('summary')
title = None
summaries = component.get('summary', [])
if not isinstance(summaries, list):
summaries = [summaries]

if summaries != []:
title = " - ".join(summaries)

description = unicode(component.get('description'))

recur = component.get('rrule')
Expand Down
29 changes: 29 additions & 0 deletions tests/events/fixtures/multiple_summaries.ics
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
BEGIN:VCALENDAR
PRODID:-//Google Inc//Google Calendar 70.9054//EN
VERSION:2.0
CALSCALE:GREGORIAN
METHOD:REQUEST
BEGIN:VEVENT
DTSTART:20150319T233000Z
DTEND:20150320T003000Z
DTSTAMP:20150318T190309Z
ORGANIZER;CN=Karim Hamidou:mailto:test@nilas.com
UID:jvbogoss39aumnj4p5og9rd0@google.com
ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=ACCEPTED;RSVP=TRUE
;CN=Karim Hamidou;X-NUM-GUESTS=0:mailto:test@nilas.com
ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=
TRUE;CN=testaccount@gmail.com;X-NUM-GUESTS=0:mailto:testaccount@gmail.com
CREATED:20150318T190309Z
DESCRIPTION:Affichez votre \xc3\xa9v\xc3\xa9nement sur la page https://www.google.com/cal
endar/event?action=VIEW&eid=anZicm9nZ29zMTM5YXVtbmo0cDVvZzlyZDAgaW5ib3hhcHB
0ZXN0LmZyZW5jaEBt&tok=MTUja2FyaW1AbmlsYXMuY29tOTdlNTFmYzliN2Y5Y2RhMTQ1MzAwM
GYyMThjNGVlNGM3NTYwYzZjYg&ctz=America/Los_Angeles&hl=fr.
LAST-MODIFIED:20150318T190309Z
LOCATION:Olympia Hall\\, 28 Boulevard des Capucines\\, 75009 Paris\\, France
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY;LANGUAGE=en-us:The Strokes
SUMMARY:Is this it?
TRANSP:OPAQUE
END:VEVENT
END:VCALENDAR
12 changes: 12 additions & 0 deletions tests/events/test_ics_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,15 @@ def test_multiple_events(db, default_account):
assert len(ev1.participants) == 0

assert ev1.start == arrow.get(2015, 03, 17, 0, 0)


def test_multiple_summaries(db, default_account):
data = None
with open(absolute_path(FIXTURES + 'multiple_summaries.ics')) as fd:
data = fd.read()

events = events_from_ics(default_account.namespace,
default_account.emailed_events_calendar, data)

assert len(events) == 1
assert events[0].title == 'The Strokes - Is this it?'

0 comments on commit 9387e31

Please sign in to comment.