diff options
-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; |