@@ -, +, @@ --- Koha/Email.pm | 12 +++++++----- t/Koha/Email.t | 7 ++++--- 2 files changed, 11 insertions(+), 8 deletions(-) --- a/Koha/Email.pm +++ a/Koha/Email.pm @@ -22,6 +22,8 @@ use Modern::Perl; use Email::Valid; use Email::MessageID; +use List::Util qw(pairs); + use Koha::Exceptions; use C4::Context; @@ -153,11 +155,11 @@ sub send_or_die { my @recipients; - # extract all recipient addresses from header - foreach my $header ( 'To', 'Cc', 'Bcc' ) { - push @recipients, - map { $_->as_string } - $self->email->header_obj->header_as_obj($header)->addresses; + my @headers = $self->email->header_str_pairs; + foreach my $pair ( pairs @headers ) { + my ( $header, $value ) = @$pair; + push @recipients, split (', ', $value) + if grep { $_ eq $header } ('To', 'Cc', 'Bcc'); } # Remove the Bcc header --- a/t/Koha/Email.t +++ a/t/Koha/Email.t @@ -226,11 +226,12 @@ subtest 'send_or_die() tests' => sub { 'If explicitly passed, "to" is preserved' ); $THE_email->send_or_die( { transport => $transport } ); + my @to = sort @{ $args->{to} }; is_deeply( - $args->{to}, + [@to], [ - 'to@example.com', 'cc@example.com', - 'bcc_1@example.com', 'bcc_2@example.com' + 'bcc_1@example.com', 'bcc_2@example.com', + 'cc@example.com', 'to@example.com', ], 'If "to" is not explicitly passed, extract recipients from headers' ); --