From 539c9e5c9b04ac6e6151de839dd5e08bd603c371 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 23 Mar 2021 16:58:04 -0300 Subject: [PATCH] Bug 26705: (QA follow-up) Do not rely on latest Email::MIME This patch makes the implementation use lower-level methods to deal with headers. So the Email::MIME library in Debian 9 works. Params are sorted for testing purposes. To test: 1. Apply this patch 2. Run the tests => SUCCESS: Things pass in D9+ 3. Sign off :-D Thanks Kyle! Signed-off-by: Tomas Cohen Arazi Signed-off-by: Kyle M Hall Signed-off-by: Jonathan Druart --- Koha/Email.pm | 12 +++++++----- t/Koha/Email.t | 7 ++++--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Koha/Email.pm b/Koha/Email.pm index 450e4015cd..cb1046f731 100644 --- a/Koha/Email.pm +++ b/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 diff --git a/t/Koha/Email.t b/t/Koha/Email.t index 7d383c05e8..6955a3d678 100755 --- a/t/Koha/Email.t +++ b/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' ); -- 2.39.5