pimutils / khal

:calendar: CLI calendar application
https://lostpackets.de/khal/
MIT License
2.62k stars 207 forks source link

ICS with multiple "STATUS" fields aren't handled correctly #1002

Open eyenx opened 3 years ago

eyenx commented 3 years ago

Some Calendar tools, create ICS objects of invitations with multiple Status fields. This seems for me to happen on Kopano, when I change a reccurring invitation Item to not be recurring anymore for one day. (A.e. recurring daily meeting is rescheduled to a later point in the day).

This looks like this:

~ grep STATUS .calendars/Calendar/040000008200E00074xxxxxx9743BD251B5C9FBD.ics
STATUS:CONFIRMED
STATUS:CONFIRMED
STATUS:CONFIRMED

When I then want to use khal to see the events or khal interactive, following happens:

Traceback:

Traceback (most recent call last):
  File "/usr/bin/khal", line 5, in <module>
    main_khal()
  File "/usr/lib/python3.9/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python3.9/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3.9/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python3.9/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python3.9/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/usr/lib/python3.9/site-packages/click/decorators.py", line 21, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/lib/python3.9/site-packages/khal/cli.py", line 624, in at
    rows = controllers.khal_list(
  File "/usr/lib/python3.9/site-packages/khal/controllers.py", line 262, in khal_list
    current_events = get_events_between(
  File "/usr/lib/python3.9/site-packages/khal/controllers.py", line 198, in get_events_between
    event_string = event.format(agenda_format, relative_to=(start, end), env=env)
  File "/usr/lib/python3.9/site-packages/khal/khalendar/event.py", line 623, in format
    attributes['status'] = self.status + ' ' if self.status else ''
TypeError: can only concatenate list (not "str") to list

Debugging

Tried to debugg the issue. Looks like event.py can't handle a list of "STATUS". Tried adding a print on line 662 of event.py to print out the state:

Normal invitationICS:

~ khal at 2021-01-12 09:00

CONFIRMED
CONFIRMED
CONFIRMED
2021-01-12 09:00
09:00-10:30 meeting for this and taht

Invitation which isn't recurring for one day:

~ khal at 2021-01-11 13:00
[vText('b'CONFIRMED''), vText('b'CONFIRMED'')]
[vText('b'CONFIRMED''), vText('b'CONFIRMED'')]
[vText('b'CONFIRMED''), vText('b'CONFIRMED'')]
2021-01-11 13:00
13:00-15:00 Training  ⟳

Quickfix

My quickfix for now was to add following lines inside event.py on line 661

    @property
    def status(self):
        status=self._vevents[self.ref].get('STATUS', '')
        if type(status) == list:
            return status[0]
        else:
          return status

This just returns only the first item of a status if it's a list. But I guess it could be done better by writing a sanitize function somewhere else.

ephase commented 3 years ago

Hi @eyenx and thanks for your detailed report. About STATUS, RFC say (link):

Conformance: This property can be specified once in "VEVENT", "VTODO", or "VJOURNAL" calendar components.

So maybe we can sanitize multiple STATUS to be compatible with such services / programs but we will not be RFC Compliant

geier commented 3 years ago

At the very least, we shouldn't throw an exception (but a warning).

@eyenx can you perhaps post an anonymized version of one of those .ics files? I currently have no clear picture yet, how those multiple status occur. (Are the multiple Status all one after the other? Are they scattered through the .ics file?)

eyenx commented 3 years ago

Yes, here you go. This happens, for me with KOPANO when a recurring event is moved out of the timeframe it would usually be:

BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Kopano//8.7.19//EN
CALSCALE:GREGORIAN
METHOD:REQUEST
BEGIN:VTIMEZONE
TZID:(GMT +01:00)
BEGIN:STANDARD
DTSTART:19700101T030000
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10;WKST=SU
END:STANDARD
BEGIN:DAYLIGHT
DTSTART:19700101T020000
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=3;WKST=SU
END:DAYLIGHT
END:VTIMEZONE
BEGIN:VEVENT
STATUS:CONFIRMED
X-MOZ-SEND-INVITATIONS:TRUE
ORGANIZER;CN=xxx xxx:mailto:xxx.xxx@xxx.com
TRANSP:OPAQUE
X-MICROSOFT-CDO-INTENDEDSTATUS:OOF
CREATED:20201127T064839Z
DTSTAMP:20210331T180338Z
LAST-MODIFIED:20210512T091729Z
DTSTART;TZID="(GMT +01:00)":20201130T070000
DTEND;TZID="(GMT +01:00)":20201130T093000
SUMMARY:Training
PRIORITY:5
CLASS:PUBLIC
UID:
 040000008200E00074C5B7101A82E00800000000803550E3CEC4D601000000000000000001
 00000080C900B5003447849743BD251B5C9FBD
SEQUENCE:1
X-MOZ-SNOOZE-TIME:20210514T044500Z
X-MICROSOFT-CDO-OWNER-CRITICAL-CHANGE:20210331T180338Z
X-MICROSOFT-CDO-ATTENDEE-CRITICAL-CHANGE:20210331T180338Z
X-MICROSOFT-CDO-APPT-SEQUENCE:1
X-MICROSOFT-CDO-OWNERAPPTID:-1
X-MICROSOFT-CDO-ALLDAYEVENT:FALSE
X-KOPANO-REC-PATTERN:Occurs every week on Monday\, Tuesday\, Wednesday\,
 and Friday effective 11/30/2020 from 7:00 to 9:30.
RRULE:FREQ=WEEKLY;BYDAY=MO,TU,WE,FR
BEGIN:VALARM
TRIGGER:-PT15M
ACTION:DISPLAY
DESCRIPTION:Reminder
END:VALARM
END:VEVENT
BEGIN:VEVENT
STATUS:CONFIRMED
X-MOZ-SEND-INVITATIONS:TRUE
TRANSP:OPAQUE
X-MICROSOFT-CDO-INTENDEDSTATUS:OOF
CREATED:20201127T064839Z
DTSTAMP:20210331T180338Z
LAST-MODIFIED:20210512T091729Z
SUMMARY:Training
PRIORITY:5
UID:
 040000008200E00074C5B7101A82E00800000000803550E3CEC4D601000000000000000001
 00000080C900B5003447849743BD251B5C9FBD
SEQUENCE:1
X-MOZ-SNOOZE-TIME:20210514T044500Z
X-MICROSOFT-CDO-OWNER-CRITICAL-CHANGE:20210331T180338Z
X-MICROSOFT-CDO-ATTENDEE-CRITICAL-CHANGE:20210331T180338Z
X-MICROSOFT-CDO-APPT-SEQUENCE:1
X-MICROSOFT-CDO-OWNERAPPTID:-1
X-MICROSOFT-CDO-ALLDAYEVENT:FALSE
X-KOPANO-REC-PATTERN:Occurs every week on Monday\, Tuesday\, Wednesday\,
 and Friday effective 11/30/2020 from 7:00 to 9:30.
STATUS:CONFIRMED
X-MOZ-SEND-INVITATIONS:TRUE
ORGANIZER;CN=xxx xxx;SENT-BY="mailto:xxx.xxx@xxx.com":mailto:
 xxx.xxx@xxx.com
DTSTART;TZID="(GMT +01:00)":20210421T110000
DTEND;TZID="(GMT +01:00)":20210421T124500
RECURRENCE-ID;TZID="(GMT +01:00)":20210421T070000
BEGIN:VALARM
TRIGGER:-PT15M
ACTION:DISPLAY
DESCRIPTION:Reminder
END:VALARM
END:VEVENT
BEGIN:VEVENT
STATUS:CONFIRMED
X-MOZ-SEND-INVITATIONS:TRUE
TRANSP:OPAQUE
X-MICROSOFT-CDO-INTENDEDSTATUS:OOF
CREATED:20201127T064839Z
DTSTAMP:20210331T180338Z
LAST-MODIFIED:20210512T091729Z
SUMMARY:Training
PRIORITY:5
UID:
 040000008200E00074C5B7101A82E00800000000803550E3CEC4D601000000000000000001
 00000080C900B5003447849743BD251B5C9FBD
SEQUENCE:1
X-MOZ-SNOOZE-TIME:20210514T044500Z
X-MICROSOFT-CDO-OWNER-CRITICAL-CHANGE:20210331T180338Z
X-MICROSOFT-CDO-ATTENDEE-CRITICAL-CHANGE:20210331T180338Z
X-MICROSOFT-CDO-APPT-SEQUENCE:1
X-MICROSOFT-CDO-OWNERAPPTID:-1
X-MICROSOFT-CDO-ALLDAYEVENT:FALSE
X-KOPANO-REC-PATTERN:Occurs every week on Monday\, Tuesday\, Wednesday\,
 and Friday effective 11/30/2020 from 7:00 to 9:30.
STATUS:CONFIRMED
X-MOZ-SEND-INVITATIONS:TRUE
ORGANIZER;CN=xxx xxx;SENT-BY="mailto:xxx.xxx@xxx.com":mailto:
 xxx.xxx@xxx.com
DTSTART;TZID="(GMT +01:00)":20210427T070000
DTEND;TZID="(GMT +01:00)":20210427T110000
RECURRENCE-ID;TZID="(GMT +01:00)":20210427T070000
BEGIN:VALARM
TRIGGER:-PT15M
ACTION:DISPLAY
DESCRIPTION:Reminder
END:VALARM
END:VEVENT
BEGIN:VEVENT
STATUS:CONFIRMED
X-MOZ-SEND-INVITATIONS:TRUE
TRANSP:OPAQUE
X-MICROSOFT-CDO-INTENDEDSTATUS:OOF
CREATED:20201127T064839Z
DTSTAMP:20210331T180338Z
LAST-MODIFIED:20210512T091729Z
SUMMARY:Training
PRIORITY:5
UID:
 040000008200E00074C5B7101A82E00800000000803550E3CEC4D601000000000000000001
 00000080C900B5003447849743BD251B5C9FBD
SEQUENCE:1
X-MOZ-SNOOZE-TIME:20210514T044500Z
X-MICROSOFT-CDO-OWNER-CRITICAL-CHANGE:20210331T180338Z
X-MICROSOFT-CDO-ATTENDEE-CRITICAL-CHANGE:20210331T180338Z
X-MICROSOFT-CDO-APPT-SEQUENCE:1
X-MICROSOFT-CDO-OWNERAPPTID:-1
X-MICROSOFT-CDO-ALLDAYEVENT:FALSE
X-KOPANO-REC-PATTERN:Occurs every week on Monday\, Tuesday\, Wednesday\,
 and Friday effective 11/30/2020 from 7:00 to 9:30.
STATUS:CONFIRMED
X-MOZ-SEND-INVITATIONS:TRUE
ORGANIZER;CN=xxx xxx;SENT-BY="mailto:xxx.xxx@xxx.com":mailto:
 xxx.xxx@xxx.com
DTSTART;TZID="(GMT +01:00)":20210505T160000
DTEND;TZID="(GMT +01:00)":20210505T183000
RECURRENCE-ID;TZID="(GMT +01:00)":20210505T070000
BEGIN:VALARM
TRIGGER:-PT15M
ACTION:DISPLAY
DESCRIPTION:Reminder
END:VALARM
END:VEVENT
BEGIN:VEVENT
STATUS:CONFIRMED
X-MOZ-SEND-INVITATIONS:TRUE
TRANSP:OPAQUE
X-MICROSOFT-CDO-INTENDEDSTATUS:OOF
CREATED:20201127T064839Z
DTSTAMP:20210331T180338Z
LAST-MODIFIED:20210512T091729Z
SUMMARY:Training
PRIORITY:5
UID:
 040000008200E00074C5B7101A82E00800000000803550E3CEC4D601000000000000000001
 00000080C900B5003447849743BD251B5C9FBD
SEQUENCE:1
X-MOZ-SNOOZE-TIME:20210514T044500Z
X-MICROSOFT-CDO-OWNER-CRITICAL-CHANGE:20210331T180338Z
X-MICROSOFT-CDO-ATTENDEE-CRITICAL-CHANGE:20210331T180338Z
X-MICROSOFT-CDO-APPT-SEQUENCE:1
X-MICROSOFT-CDO-OWNERAPPTID:-1
X-MICROSOFT-CDO-ALLDAYEVENT:FALSE
X-KOPANO-REC-PATTERN:Occurs every week on Monday\, Tuesday\, Wednesday\,
 and Friday effective 11/30/2020 from 7:00 to 9:30.
STATUS:CONFIRMED
X-MOZ-SEND-INVITATIONS:TRUE
ORGANIZER;CN=xxx xxx;SENT-BY="mailto:xxx.xxx@xxx.com":mailto:
 xxx.xxx@xxx.com
DTSTART;TZID="(GMT +01:00)":20210510T113000
DTEND;TZID="(GMT +01:00)":20210510T140000
RECURRENCE-ID;TZID="(GMT +01:00)":20210510T070000
BEGIN:VALARM
TRIGGER:-PT15M
ACTION:DISPLAY
DESCRIPTION:Reminder
END:VALARM
END:VEVENT
BEGIN:VEVENT
STATUS:CONFIRMED
X-MOZ-SEND-INVITATIONS:TRUE
TRANSP:OPAQUE
X-MICROSOFT-CDO-INTENDEDSTATUS:OOF
CREATED:20201127T064839Z
DTSTAMP:20210331T180338Z
LAST-MODIFIED:20210512T091729Z
SUMMARY:xxx
PRIORITY:5
UID:
 040000008200E00074C5B7101A82E00800000000803550E3CEC4D601000000000000000001
 00000080C900B5003447849743BD251B5C9FBD
SEQUENCE:1
X-MOZ-SNOOZE-TIME:20210514T044500Z
X-MICROSOFT-CDO-OWNER-CRITICAL-CHANGE:20210331T180338Z
X-MICROSOFT-CDO-ATTENDEE-CRITICAL-CHANGE:20210331T180338Z
X-MICROSOFT-CDO-APPT-SEQUENCE:1
X-MICROSOFT-CDO-OWNERAPPTID:-1
X-MICROSOFT-CDO-ALLDAYEVENT:FALSE
X-KOPANO-REC-PATTERN:Occurs every week on Monday\, Tuesday\, Wednesday\,
 and Friday effective 11/30/2020 from 7:00 to 9:30.
STATUS:CONFIRMED
X-MOZ-SEND-INVITATIONS:TRUE
ORGANIZER;CN=xxx xxx;SENT-BY="mailto:xxx.xxx@xxx.com":mailto:
 xxx.xxx@xxx.com
DTSTART;TZID="(GMT +01:00)":20210512T113000
DTEND;TZID="(GMT +01:00)":20210512T140000
RECURRENCE-ID;TZID="(GMT +01:00)":20210512T070000
BEGIN:VALARM
TRIGGER:-PT15M
ACTION:DISPLAY
DESCRIPTION:Reminder
END:VALARM
END:VEVENT
BEGIN:VEVENT
STATUS:CONFIRMED
X-MOZ-SEND-INVITATIONS:TRUE
TRANSP:OPAQUE
X-MICROSOFT-CDO-INTENDEDSTATUS:OOF
CREATED:20201127T064839Z
DTSTAMP:20210331T180338Z
LAST-MODIFIED:20210512T091729Z
SUMMARY:Training
PRIORITY:5
UID:
 040000008200E00074C5B7101A82E00800000000803550E3CEC4D601000000000000000001
 00000080C900B5003447849743BD251B5C9FBD
SEQUENCE:1
X-MOZ-SNOOZE-TIME:20210514T044500Z
X-MICROSOFT-CDO-OWNER-CRITICAL-CHANGE:20210331T180338Z
X-MICROSOFT-CDO-ATTENDEE-CRITICAL-CHANGE:20210331T180338Z
X-MICROSOFT-CDO-APPT-SEQUENCE:1
X-MICROSOFT-CDO-OWNERAPPTID:-1
X-MICROSOFT-CDO-ALLDAYEVENT:FALSE
X-KOPANO-REC-PATTERN:Occurs every week on Monday\, Tuesday\, Wednesday\,
 and Friday effective 11/30/2020 from 7:00 to 9:30.
STATUS:CONFIRMED
X-MOZ-SEND-INVITATIONS:TRUE
ORGANIZER;CN=xxx xxx;SENT-BY="mailto:xxx.xxx@xxx.com":mailto:
 xxx.xxx@xxx.com
DTSTART;TZID="(GMT +01:00)":20210517T113000
DTEND;TZID="(GMT +01:00)":20210517T140000
RECURRENCE-ID;TZID="(GMT +01:00)":20210517T070000
BEGIN:VALARM
TRIGGER:-PT15M
ACTION:DISPLAY
DESCRIPTION:Reminder
END:VALARM
END:VEVENT
END:VCALENDAR
d7415 commented 3 years ago

While we should probably do something on the khal side too, have you also reported to this to Kopano?

eyenx commented 3 years ago

Not yet.

On 12 May 2021 17:15:26 CEST, Martin Stone @.***> wrote:

While we should probably do something on the khal side too, have you also reported to this to Kopano?

d7415 commented 3 years ago

It's probably worth pointing out that they're not standards compliant. Especially if you're a paying customer.

eyenx commented 3 years ago

Will do.

On 12 May 2021 17:50:16 CEST, Martin Stone @.***> wrote:

It's probably worth pointing out that they're not standards compliant. Especially if you're a paying customer.