From f7694214009de69f1c8c5f5f6f3dca73f8869ca1 Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Thu, 20 May 2021 01:38:46 +0200 Subject: 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) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/events2md.pl | 29 +++++++++++++---------------- 1 file 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; -- cgit v1.2.3