diff options
author | Jonas Smedegaard <dr@jones.dk> | 2021-05-20 01:38:46 +0200 |
---|---|---|
committer | Jonas Smedegaard <dr@jones.dk> | 2021-05-20 01:38:46 +0200 |
commit | f7694214009de69f1c8c5f5f6f3dca73f8869ca1 (patch) | |
tree | 2e41fc42db60ae9d0068bda8e44d0bcd0ac25e77 | |
parent | d18f341ffb2d820096006abeffd4b4772a50adcf (diff) |
fix use string entries from Data::ICal object (iCal::Parser is broken: not only fails to unescape characters but rewraps raw octets which breaks UTF-8 e.g. when danish å is first character after an auto-wrap that gets rewrapped)
-rwxr-xr-x | bin/events2md.pl | 29 |
1 files changed, 13 insertions, 16 deletions
diff --git a/bin/events2md.pl b/bin/events2md.pl index 2964867..282afa8 100755 --- a/bin/events2md.pl +++ b/bin/events2md.pl @@ -133,7 +133,7 @@ if ( $log->is_trace ) { # serialize calendar events $log->debug('serialize calendar events...'); my $parser = iCal::Parser->new( start => $start, end => $end ); -my $events = $parser->parse_strings( decode_utf8 $calendar->as_string ); +my $events = $parser->parse_strings( $calendar->as_string ); if ( $log->is_trace ) { use DDP; p $events; @@ -177,17 +177,18 @@ sub print_event p $entry; p $event; } - my $summary = unescape( $event->{SUMMARY} ); - my $description = unescape( $event->{DESCRIPTION} ); + my $summary = get_property_string( $entry, 'summary' ); + my $description = get_property_string( $entry, 'description' ); $description =~ s/\n\n[Pp]ris:\s*((?!\n).+)\s*\z//m; my $price = $1; my @attendees; - if ( $event->{ATTENDEE} ) { - for ( @{ $event->{ATTENDEE} } ) { - push @attendees, $_->{'CN'} || $_->{value} =~ s/^mailto://r; + if ( $entry->property('attendee') ) { + for ( @{ $entry->property('attendee') } ) { + push @attendees, decode_utf8 $_->parameters->{'CN'} + || $_->value =~ s/^mailto://r; } } - my $location = unescape( $event->{LOCATION} ); + my $location = get_property_string( $entry, 'location' ); my $time_begin = ucfirst( $event->{DTSTART}->strftime('%A') ); $time_begin .= $event->{DTSTART}->strftime(' %e. %B kl. %k.%M'); my $time_end = $event->{DTEND}->strftime('%k.%M'); @@ -228,18 +229,14 @@ sub print_event } } -# unescape characters in iCalendar TEXT content strings -# should fully cover iCalendar 2.0 (rfc5545 and rfc6868) -sub unescape +sub get_property_string { - ($_) = @_; + my ( $entry, $key ) = @_; - s/\^n|\\[Nn]/\n/g; - s/\^\'/\"/g; - s/\^\^/^/g; - s/\\([\\;,])/$1/g; + return '' + unless $entry->property($key); - return $_; + return decode_utf8 $entry->property($key)->[0]->value; } 1; |