From e22e4e07d8953fe3dfa15501faeb1aae36cd8bfc Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Thu, 17 Jun 2021 09:59:18 +0000 Subject: [PATCH] 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 Signed-off-by: Nick Clemens --- C4/Letters.pm | 11 ++++++++++- Koha/Patron/Password/Recovery.pm | 2 +- misc/cronjobs/automatic_renewals.pl | 6 ++---- misc/cronjobs/membership_expiry.pl | 3 +-- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/C4/Letters.pm b/C4/Letters.pm index b8de25bdc8..98dfda4a40 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -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} diff --git a/Koha/Patron/Password/Recovery.pm b/Koha/Patron/Password/Recovery.pm index c2e2d27930..0dafdae4f3 100644 --- a/Koha/Patron/Password/Recovery.pm +++ b/Koha/Patron/Password/Recovery.pm @@ -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( { diff --git a/misc/cronjobs/automatic_renewals.pl b/misc/cronjobs/automatic_renewals.pl index c8958cdc9d..7b4158b969 100755 --- a/misc/cronjobs/automatic_renewals.pl +++ b/misc/cronjobs/automatic_renewals.pl @@ -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 ( diff --git a/misc/cronjobs/membership_expiry.pl b/misc/cronjobs/membership_expiry.pl index 5038ce1f9f..c140820ea5 100755 --- a/misc/cronjobs/membership_expiry.pl +++ b/misc/cronjobs/membership_expiry.pl @@ -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, -- 2.20.1