Bug 28581: Use from_email_address in the codebase

Adding only a few (trivial) cases now. Changes in C4::Letters
are not trivial after all..
We now add the KohaAdminEmail fallback implicitly when the from
address was still empty. The extra check makes us not rely on
a do or die action in Email::Stuffer.

Test plan:
Run password recovery or membership expiry cron.
Check sender address.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
This commit is contained in:
Marcel de Rooy 2021-06-17 09:59:18 +00:00 committed by Kyle M Hall
parent eff0187295
commit 17ac49efaf
4 changed files with 14 additions and 8 deletions

View file

@ -1370,6 +1370,15 @@ sub _send_message_by_email {
$branch_returnpath = $library->branchreturnpath;
}
my $from_address = $message->{'from_address'} || $library->from_email_address;
if( !$from_address ) {
_set_message_status({
message_id => $message->{'message_id'},
status => 'failed',
delivery_note => 'No from address',
});
return;
};
my $email = Koha::Email->create(
{
to => $to_address,
@ -1378,7 +1387,7 @@ sub _send_message_by_email {
? ( bcc => C4::Context->preference('NoticeBcc') )
: ()
),
from => $message->{'from_address'} || $branch_email,
from => $from_address,
reply_to => $message->{'reply_address'} || $branch_replyto,
sender => $branch_returnpath,
subject => "" . $message->{subject}

View file

@ -151,7 +151,7 @@ sub SendPasswordRecoveryEmail {
# define from emails
my $library = $borrower->library;
my $kohaEmail = $library->branchemail || C4::Context->preference('KohaAdminEmailAddress'); # send from patron's branch or Koha Admin
my $kohaEmail = $library->from_email_address; # send from patron's branch or Koha Admin
my $message_id = C4::Letters::EnqueueLetter(
{

View file

@ -212,7 +212,7 @@ if ( $send_notices && $confirm ) {
);
my $library = Koha::Libraries->find( $patron->branchcode );
my $admin_email_address = $library->branchemail || C4::Context->preference('KohaAdminEmailAddress');
my $admin_email_address = $library->from_email_address;
C4::Letters::EnqueueLetter(
{ letter => $letter,
@ -270,8 +270,6 @@ String that denote the letter code.
sub send_digests {
my $params = shift;
my $admin_email_address = C4::Context->preference('KohaAdminEmailAddress');
PATRON: while ( my ( $borrowernumber, $digest ) = each %{$params->{digests}} ) {
my $borrower_preferences =
C4::Members::Messaging::GetMessagingPreferences(
@ -285,7 +283,7 @@ sub send_digests {
my $patron = Koha::Patrons->find( $borrowernumber );
my $library = Koha::Libraries->find( $params->{branchcode} );
my $from_address = $library->{branchemail} || $admin_email_address;
my $from_address = $library->from_email_address;
foreach my $transport ( keys %{ $borrower_preferences->{'transports'} } ) {
my $letter = C4::Letters::GetPreparedLetter (

View file

@ -168,7 +168,6 @@ if( !$expdays ) {
exit;
}
my $admin_adress = C4::Context->preference('KohaAdminEmailAddress');
warn 'getting upcoming membership expires' if $verbose;
my $upcoming_mem_expires = Koha::Patrons->search_upcoming_membership_expires(
{
@ -183,7 +182,7 @@ warn 'found ' . $upcoming_mem_expires->count . ' soon expiring members'
# main loop
$letter_type = 'MEMBERSHIP_EXPIRY' if !$letter_type;
while ( my $recent = $upcoming_mem_expires->next ) {
my $from_address = $recent->library->branchemail || $admin_adress;
my $from_address = $recent->library->from_email_address;
my $letter = C4::Letters::GetPreparedLetter(
module => 'members',
letter_code => $letter_type,