From ba749a9c229337f0d4424ba7ba5e258f7fa308fd Mon Sep 17 00:00:00 2001 From: Alexis Ripetti Date: Wed, 16 Dec 2020 12:05:35 -0500 Subject: [PATCH] Bug 12532 - Rebase and correction of the patch by adding the possibility of sending emails to several guarantors --- C4/Letters.pm | 5 +++++ Koha/Email.pm | 9 ++++++--- Koha/Patron.pm | 22 ++++++++++++---------- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/C4/Letters.pm b/C4/Letters.pm index aa2aa5f8d5..04d96ae687 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -1405,6 +1405,11 @@ sub _send_message_by_email { if !$message->{to_address} || $message->{to_address} ne $email->email->header('To'); + _update_message_from_address($message->{'message_id'},$email->email->header('From') ) + if !$message->{from_address} + || $message->{from_address} ne $email->email->header('From'); + + try { $email->send_or_die({ transport => $smtp_server->transport }); diff --git a/Koha/Email.pm b/Koha/Email.pm index e91a49e402..c114a37a39 100644 --- a/Koha/Email.pm +++ b/Koha/Email.pm @@ -87,9 +87,12 @@ sub create { $args->{to} = $params->{to}; } - Koha::Exceptions::BadParameter->throw("Invalid 'to' parameter: ".$args->{to}) - unless Email::Valid->address($args->{to}); # to is mandatory - + my @emails = split(',', $args->{to}); + foreach my $email (@emails) { + $email =~ s/ //g; + Koha::Exceptions::BadParameter->throw("Invalid 'to' parameter: ".$email) + unless Email::Valid->address($email); # to is mandatory + } my $addresses = {}; $addresses->{reply_to} = $params->{reply_to}; $addresses->{reply_to} ||= C4::Context->preference('ReplytoDefault') diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 0c402ace66..cfe9413740 100755 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -1244,17 +1244,19 @@ sub notice_email_address{ my $use_guarantor = C4::Context->preference('RedirectGuaranteeEmail'); if ($use_guarantor) { - my $guarantor = $self->guarantor; - if ($guarantor) { - if ( $which_address eq 'OFF' ) { - $guarantor_address = $guarantor->first_valid_email_address; - } else { - $guarantor_address = $guarantor->$which_address || ''; - } - if ($address){ - $address .= ', '; - } + my @guarantors = map { $_->guarantor } $self->guarantor_relationships(); + if (@guarantors) { + foreach my $guarantor (@guarantors) { + if ( $which_address eq 'OFF' ) { + $guarantor_address = $guarantor->first_valid_email_address; + } else { + $guarantor_address = $guarantor->$which_address || ''; + } + if ($address){ + $address .= ', '; + } $address .= $guarantor_address if $guarantor_address; + } } } return $address; -- 2.25.1