diff --git a/mailboxes/mailboxes-lib.pl b/mailboxes/mailboxes-lib.pl index e84d66894..2fedaa368 100755 --- a/mailboxes/mailboxes-lib.pl +++ b/mailboxes/mailboxes-lib.pl @@ -1331,210 +1331,211 @@ my $adjust_time_with_timezone = sub { }; }; # Lines processor -my $process_line = sub { - my ($line) = @_; - # Start a new event - if ($line =~ /^BEGIN:VEVENT/) { - %event = (); - $event{'description'} = [ ]; - $event{'attendees'} = [ ]; - } - # Convert times using the timezone - elsif ($line =~ /^END:VEVENT/) { - # Local timezone - $event{'tzid_local'} = - DateTime::TimeZone->new(name => 'local')->name(); - $event{'tzid'} = 'UTC', $event{'tzid_missing'} = 1 - if (!$event{'tzid'}); - # Adjust times with timezone - my ($adjusted_start, $adjusted_end); - $event{'tzid'} = $timezone_map{$event{'tzid'}} || $event{'tzid'}; - # Add single start/end time - if ($event{'dtstart'}) { - $adjusted_start = - $adjust_time_with_timezone->($event{'dtstart'}, - $event{'tzid'}); - $event{'dtstart_timestamp'} = $adjusted_start->{'timestamp'}; - my $dtstart_date = - &make_date($event{'dtstart_timestamp'}, - { tz => $event{'tzid'} }); - $event{'dtstart_date'} = - "$dtstart_date->{'short'} ". - "$dtstart_date->{'timeshort'}"; - $event{'dtstart_local_timestamp'} = - $adjusted_start->{'timestamp_local'}; - $event{'dtstart_local_date'} = - &make_date($event{'dtstart_local_timestamp'}); - } - if ($event{'dtend'}) { - $adjusted_end = - $adjust_time_with_timezone->($event{'dtend'}, - $event{'tzid'}); - $event{'dtend_timestamp'} = $adjusted_end->{'timestamp'}; - my $dtend_date = &make_date($event{'dtend_timestamp'}, +my $process_line = sub +{ +my ($line) = @_; +# Start a new event +if ($line =~ /^BEGIN:VEVENT/) { + %event = (); + $event{'description'} = [ ]; + $event{'attendees'} = [ ]; + } +# Convert times using the timezone +elsif ($line =~ /^END:VEVENT/) { + # Local timezone + $event{'tzid_local'} = + DateTime::TimeZone->new(name => 'local')->name(); + $event{'tzid'} = 'UTC', $event{'tzid_missing'} = 1 + if (!$event{'tzid'}); + # Adjust times with timezone + my ($adjusted_start, $adjusted_end); + $event{'tzid'} = $timezone_map{$event{'tzid'}} || $event{'tzid'}; + # Add single start/end time + if ($event{'dtstart'}) { + $adjusted_start = + $adjust_time_with_timezone->($event{'dtstart'}, + $event{'tzid'}); + $event{'dtstart_timestamp'} = $adjusted_start->{'timestamp'}; + my $dtstart_date = + &make_date($event{'dtstart_timestamp'}, { tz => $event{'tzid'} }); - $event{'dtend_date'} = - "$dtend_date->{'short'} ". - "$dtend_date->{'timeshort'}"; - $event{'dtend_local_timestamp'} = - $adjusted_end->{'timestamp_local'}; - $event{'dtend_local_date'} = - &make_date($event{'dtend_local_timestamp'}); - } - if ($event{'dtstart'} && $event{'dtend'}) { - # Try to add local 'when (period)' - my $dtstart_local_obj = - $event{'_obj_dtstart_local_time'} = - make_date($event{'dtstart_local_timestamp'}, - { _ }); - my $dtend_local_obj = - $event{'_obj_dtend_local_time'} = - make_date($event{'dtend_local_timestamp'}, - { _ }); - # Build when local, e.g.: - # Tue Jun 04, 2024 04:30 PM – 05:15 - # PM (Asia/Nicosia +0300) - # or - # Tue Jun 04, 2024 04:30 PM – Wed Jun 05, 2024 01:15 - # AM (Asia/Nicosia +0300) - $event{'dtwhen_local'} = - # Start local - $dtstart_local_obj->{'week'}.' '. - $dtstart_local_obj->{'month'}.' '. - $dtstart_local_obj->{'day'}.', '. - $dtstart_local_obj->{'year'}.' '. - $dtstart_local_obj->{'timeshort'}.' – '; - # End local - if ($dtstart_local_obj->{'year'} eq - $dtend_local_obj->{'year'} && - $dtstart_local_obj->{'month'} eq - $dtend_local_obj->{'month'} && - $dtstart_local_obj->{'day'} eq - $dtend_local_obj->{'day'}) { + $event{'dtstart_date'} = + "$dtstart_date->{'short'} ". + "$dtstart_date->{'timeshort'}"; + $event{'dtstart_local_timestamp'} = + $adjusted_start->{'timestamp_local'}; + $event{'dtstart_local_date'} = + &make_date($event{'dtstart_local_timestamp'}); + } + if ($event{'dtend'}) { + $adjusted_end = + $adjust_time_with_timezone->($event{'dtend'}, + $event{'tzid'}); + $event{'dtend_timestamp'} = $adjusted_end->{'timestamp'}; + my $dtend_date = &make_date($event{'dtend_timestamp'}, + { tz => $event{'tzid'} }); + $event{'dtend_date'} = + "$dtend_date->{'short'} ". + "$dtend_date->{'timeshort'}"; + $event{'dtend_local_timestamp'} = + $adjusted_end->{'timestamp_local'}; + $event{'dtend_local_date'} = + &make_date($event{'dtend_local_timestamp'}); + } + if ($event{'dtstart'} && $event{'dtend'}) { + # Try to add local 'when (period)' + my $dtstart_local_obj = + $event{'_obj_dtstart_local_time'} = + make_date($event{'dtstart_local_timestamp'}, + { _ }); + my $dtend_local_obj = + $event{'_obj_dtend_local_time'} = + make_date($event{'dtend_local_timestamp'}, + { _ }); + # Build when local, e.g.: + # Tue Jun 04, 2024 04:30 PM – 05:15 + # PM (Asia/Nicosia +0300) + # or + # Tue Jun 04, 2024 04:30 PM – Wed Jun 05, 2024 01:15 + # AM (Asia/Nicosia +0300) + $event{'dtwhen_local'} = + # Start local + $dtstart_local_obj->{'week'}.' '. + $dtstart_local_obj->{'month'}.' '. + $dtstart_local_obj->{'day'}.', '. + $dtstart_local_obj->{'year'}.' '. + $dtstart_local_obj->{'timeshort'}.' – '; + # End local + if ($dtstart_local_obj->{'year'} eq + $dtend_local_obj->{'year'} && + $dtstart_local_obj->{'month'} eq + $dtend_local_obj->{'month'} && + $dtstart_local_obj->{'day'} eq + $dtend_local_obj->{'day'}) { + $event{'dtwhen_local'} .= + $dtend_local_obj->{'timeshort'}; + } + else { + $event{'dtwhen_local'} .= + $dtend_local_obj->{'week'}.' '. + $dtend_local_obj->{'month'}.' '. + $dtend_local_obj->{'day'}.', '. + $dtend_local_obj->{'year'}.' '. + $dtend_local_obj->{'timeshort'}; + } + # Timezone local + if ($event{'tzid_local'} || + $dtstart_local_obj->{'tz'}) { + if ($event{'tzid_local'} && + $dtstart_local_obj->{'tz'}) { + if ($event{'tzid_local'} eq + $dtstart_local_obj->{'tz'}) { + $event{'dtwhen_local'} .= + " ($event{'tzid_local'})"; + } + else { + $event{'dtwhen_local'} .= + " ($event{'tzid_local'} ". + "$dtstart_local_obj->{'tz'})"; + } + } + elsif ($event{'tzid_local'}) { $event{'dtwhen_local'} .= - $dtend_local_obj->{'timeshort'}; + " ($event{'tzid_local'})"; } else { $event{'dtwhen_local'} .= - $dtend_local_obj->{'week'}.' '. - $dtend_local_obj->{'month'}.' '. - $dtend_local_obj->{'day'}.', '. - $dtend_local_obj->{'year'}.' '. - $dtend_local_obj->{'timeshort'}; + " ($dtstart_local_obj->{'tz'})"; } - # Timezone local - if ($event{'tzid_local'} || - $dtstart_local_obj->{'tz'}) { - if ($event{'tzid_local'} && - $dtstart_local_obj->{'tz'}) { - if ($event{'tzid_local'} eq - $dtstart_local_obj->{'tz'}) { - $event{'dtwhen_local'} .= - " ($event{'tzid_local'})"; - } - else { - $event{'dtwhen_local'} .= - " ($event{'tzid_local'} ". - "$dtstart_local_obj->{'tz'})"; - } - } - elsif ($event{'tzid_local'}) { - $event{'dtwhen_local'} .= - " ($event{'tzid_local'})"; - } - else { - $event{'dtwhen_local'} .= - " ($dtstart_local_obj->{'tz'})"; - } - } - # Try to add original 'when (period)' - my $dtstart_obj = - $event{'_obj_dtstart_time'} = - make_date($event{'dtstart_timestamp'}, - { tz => $event{'tzid'} }); - my $dtend_obj = - $event{'_obj_dtend_time'} = - make_date($event{'dtend_timestamp'}, - { tz => $event{'tzid'} }); - # Build original when - if (!$event{'tzid_missing'}) { - $event{'dtwhen'} = - # Start original - $dtstart_obj->{'week'}.' '. - $dtstart_obj->{'month'}.' '. - $dtstart_obj->{'day'}.', '. - $dtstart_obj->{'year'}.' '. - $dtstart_obj->{'timeshort'}.' – '; - # End original - if ($dtstart_obj->{'year'} eq - $dtend_obj->{'year'} && - $dtstart_obj->{'month'} eq - $dtend_obj->{'month'} && - $dtstart_obj->{'day'} eq - $dtend_obj->{'day'}) { - $event{'dtwhen'} .= - $dtend_obj->{'timeshort'}; - } - else { - $event{'dtwhen'} .= - $dtend_obj->{'week'}.' '. - $dtend_obj->{'month'}.' '. - $dtend_obj->{'day'}.', '. - $dtend_obj->{'year'}.' '. - $dtend_obj->{'timeshort'}; - } - # Timezone original - if ($dtstart_obj->{'tz'}) { - $event{'dtwhen'} .= - " ($dtstart_obj->{'tz'})"; - } } + # Try to add original 'when (period)' + my $dtstart_obj = + $event{'_obj_dtstart_time'} = + make_date($event{'dtstart_timestamp'}, + { tz => $event{'tzid'} }); + my $dtend_obj = + $event{'_obj_dtend_time'} = + make_date($event{'dtend_timestamp'}, + { tz => $event{'tzid'} }); + # Build original when + if (!$event{'tzid_missing'}) { + $event{'dtwhen'} = + # Start original + $dtstart_obj->{'week'}.' '. + $dtstart_obj->{'month'}.' '. + $dtstart_obj->{'day'}.', '. + $dtstart_obj->{'year'}.' '. + $dtstart_obj->{'timeshort'}.' – '; + # End original + if ($dtstart_obj->{'year'} eq + $dtend_obj->{'year'} && + $dtstart_obj->{'month'} eq + $dtend_obj->{'month'} && + $dtstart_obj->{'day'} eq + $dtend_obj->{'day'}) { + $event{'dtwhen'} .= + $dtend_obj->{'timeshort'}; + } + else { + $event{'dtwhen'} .= + $dtend_obj->{'week'}.' '. + $dtend_obj->{'month'}.' '. + $dtend_obj->{'day'}.', '. + $dtend_obj->{'year'}.' '. + $dtend_obj->{'timeshort'}; + } + # Timezone original + if ($dtstart_obj->{'tz'}) { + $event{'dtwhen'} .= + " ($dtstart_obj->{'tz'})"; + } } - # Add the event to the list - push(@events, { %event }); - } - # Parse fields - elsif ($line =~ /^SUMMARY.*?:(.*)$/) { - $event{'summary'} = $1; - } - elsif ($line =~ /^DTSTART:(.*)$/) { - $event{'dtstart'} = $1; - } - elsif ($line =~ /^DTSTART;TZID=(.*?):(.*)$/) { - $event{'tzid'} = $1; - $event{'dtstart'} = $2; - } - elsif ($line =~ /^DTEND:(.*)$/) { - $event{'dtend'} = $1; - } - elsif ($line =~ /^DTEND;TZID=(.*?):(.*)$/) { - $event{'tzid'} = $1; - $event{'dtend'} = $2; - } - elsif ($line =~ /^DESCRIPTION:(.*)$/) { - my $description = $1; - $description =~ s/\\n/
/g; - $description =~ s/\\//g; - unshift(@{$event{'description'}}, $description); - } - elsif ($line =~ /^DESCRIPTION;LANGUAGE=([a-z]{2}-[A-Z]{2}):(.*)$/) { - my $description = $2; - $description =~ s/\\n/
/g; - $description =~ s/\\//g; - unshift(@{$event{'description'}}, $description); - } - elsif ($line =~ /^LOCATION.*?:(.*)$/) { - $event{'location'} = $1; - } - elsif ($line =~ /^ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN=(.*?):mailto:(.*)$/ || - $line =~ /^ATTENDEE;.*CN=(.*?);.*mailto:(.*)$/ || - $line =~ /^ATTENDEE:mailto:(.*)$/) { - push(@{$event{'attendees'}}, { 'name' => $1, 'email' => $2 }); - } - elsif ($line =~ /^ORGANIZER;CN=(.*?):(?:mailto:)?(.*)$/) { - $event{'organizer_name'} = $1; - $event{'organizer_email'} = $2; } + # Add the event to the list + push(@events, { %event }); + } +# Parse fields +elsif ($line =~ /^SUMMARY.*?:(.*)$/) { + $event{'summary'} = $1; + } +elsif ($line =~ /^DTSTART:(.*)$/) { + $event{'dtstart'} = $1; + } +elsif ($line =~ /^DTSTART;TZID=(.*?):(.*)$/) { + $event{'tzid'} = $1; + $event{'dtstart'} = $2; + } +elsif ($line =~ /^DTEND:(.*)$/) { + $event{'dtend'} = $1; + } +elsif ($line =~ /^DTEND;TZID=(.*?):(.*)$/) { + $event{'tzid'} = $1; + $event{'dtend'} = $2; + } +elsif ($line =~ /^DESCRIPTION:(.*)$/) { + my $description = $1; + $description =~ s/\\n/
/g; + $description =~ s/\\//g; + unshift(@{$event{'description'}}, $description); + } +elsif ($line =~ /^DESCRIPTION;LANGUAGE=([a-z]{2}-[A-Z]{2}):(.*)$/) { + my $description = $2; + $description =~ s/\\n/
/g; + $description =~ s/\\//g; + unshift(@{$event{'description'}}, $description); + } +elsif ($line =~ /^LOCATION.*?:(.*)$/) { + $event{'location'} = $1; + } +elsif ($line =~ /^ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN=(.*?):mailto:(.*)$/ || + $line =~ /^ATTENDEE;.*CN=(.*?);.*mailto:(.*)$/ || + $line =~ /^ATTENDEE:mailto:(.*)$/) { + push(@{$event{'attendees'}}, { 'name' => $1, 'email' => $2 }); + } +elsif ($line =~ /^ORGANIZER;CN=(.*?):(?:mailto:)?(.*)$/) { + $event{'organizer_name'} = $1; + $event{'organizer_email'} = $2; + } }; # Read the ICS file lines or just use the lines my $ics_file_lines =