diff --git a/cassandane/Cassandane/Cyrus/Caldav.pm b/cassandane/Cassandane/Cyrus/Caldav.pm index c06190d988..1bc3f5d043 100644 --- a/cassandane/Cassandane/Cyrus/Caldav.pm +++ b/cassandane/Cassandane/Cyrus/Caldav.pm @@ -5666,4 +5666,109 @@ sub test_calendaradmin_get $self->assert_str_equals('200', $res->{status}); } +sub test_imip_encode_address + :needs_component_httpd + :NoStartInstances +{ + my ($self) = @_; + + $self->{instance}->{config}->set('imipnotifier' => undef); + $self->_start_instances(); + $self->_setup_http_service_objects(); + + my $service = $self->{instance}->get_service("http"); + my $caldav = $self->{caldav}; + + my @testCases = ( + { mailto => 'a@example.com', + cn => 'A', + expect => 'A ', + }, + { mailto => 'b@example.com', + cn => 'A ', + expect => '"A " ', + }, + { mailto => 'c@example.com', + cn => "A \N{TOMATO} B", + expect => '=?UTF-8?Q?A_=F0=9F=8D=85_B?= ', + }, + { mailto => 'd@example.com', + cn => 'A "T" B', + expect => '"A \"T\" B" ', + }, + { mailto => 'e@example.com', + cn => 'A \ B', + expect => '"A \\\\ B" ', + }, + { mailto => 'f@example.com', + cn => 'A,B', + expect => '"A,B" ', + }, + { mailto => 'g@example.com', + cn => undef, + expect => 'g@example.com', + }, + ); + + my $uuidgen = Data::UUID->new; + + foreach my $tc (@testCases) { + my $uid = $uuidgen->create_str; + my $ical = <{cn}) { + $ical .= "ORGANIZER;CN=$tc->{cn}:MAILTO:$tc->{mailto}\n"; + } else { + $ical .= "ORGANIZER:MAILTO:$tc->{mailto}\n"; + } + + $ical .= <Request( + 'PUT', "Default/$uid.ics", $ical, + 'Content-Type' => 'text/calendar; charset=utf-8' + ); + } + + my %recipients = (); + + my $messages_dir = $self->{instance}->get_basedir() . '/smtpd'; + opendir(my $dh, $messages_dir) or die "opendir $messages_dir: $!"; + while (readdir $dh) { + next if not m/\.smtp$/; + + my $message_file = "$messages_dir/$_"; + open(my $fh, '<', $message_file) or die "open $message_file: $!"; + while (<$fh>) { + s/[\x0d\x0a]{1,2}$//; # leniently chomp eol chars + last if not $_; # empty line: end of headers + + if (m/^To: (.*(\w+\@example\.com)>?)$/) { + $recipients{$2} = $1; + } + } + close $fh; + } + closedir $dh; + + foreach my $tc (@testCases) { + $self->assert_str_equals($tc->{expect}, + $recipients{$tc->{mailto}}); + } +} + 1; diff --git a/cassandane/tiny-tests/Caldav/imip_encode_address b/cassandane/tiny-tests/Caldav/imip_encode_address deleted file mode 100644 index 4c30f0b3b3..0000000000 --- a/cassandane/tiny-tests/Caldav/imip_encode_address +++ /dev/null @@ -1,111 +0,0 @@ -#!perl -use warnings; -use strict; - -use Cassandane::Tiny; -use Data::UUID; - -sub test_imip_encode_address - :needs_component_httpd - :NoStartInstances -{ - my ($self) = @_; - - $self->{instance}->{config}->set('imipnotifier' => undef); - $self->_start_instances(); - $self->_setup_http_service_objects(); - - my $service = $self->{instance}->get_service("http"); - my $caldav = $self->{caldav}; - - my @testCases = ( - { mailto => 'a@example.com', - cn => 'A', - expect => 'A ', - }, - { mailto => 'b@example.com', - cn => 'A ', - expect => '"A " ', - }, - { mailto => 'c@example.com', - cn => "A \N{TOMATO} B", - expect => '=?UTF-8?Q?A_=F0=9F=8D=85_B?= ', - }, - { mailto => 'd@example.com', - cn => 'A "T" B', - expect => '"A \"T\" B" ', - }, - { mailto => 'e@example.com', - cn => 'A \ B', - expect => '"A \\\\ B" ', - }, - { mailto => 'f@example.com', - cn => 'A,B', - expect => '"A,B" ', - }, - { mailto => 'g@example.com', - cn => undef, - expect => 'g@example.com', - }, - ); - - my $uuidgen = Data::UUID->new; - - foreach my $tc (@testCases) { - my $uid = $uuidgen->create_str; - my $ical = <{cn}) { - $ical .= "ORGANIZER;CN=$tc->{cn}:MAILTO:$tc->{mailto}\n"; - } else { - $ical .= "ORGANIZER:MAILTO:$tc->{mailto}\n"; - } - - $ical .= <Request( - 'PUT', "Default/$uid.ics", $ical, - 'Content-Type' => 'text/calendar; charset=utf-8' - ); - } - - my %recipients = (); - - my $messages_dir = $self->{instance}->get_basedir() . '/smtpd'; - opendir(my $dh, $messages_dir) or die "opendir $messages_dir: $!"; - while (readdir $dh) { - next if not m/\.smtp$/; - - my $message_file = "$messages_dir/$_"; - open(my $fh, '<', $message_file) or die "open $message_file: $!"; - while (<$fh>) { - s/[\x0d\x0a]{1,2}$//; # leniently chomp eol chars - last if not $_; # empty line: end of headers - - if (m/^To: (.*(\w+\@example\.com)>?)$/) { - $recipients{$2} = $1; - } - } - close $fh; - } - closedir $dh; - - foreach my $tc (@testCases) { - $self->assert_str_equals($tc->{expect}, - $recipients{$tc->{mailto}}); - } -}