Bug 28581: Use from_email_address in the codebase
authorMarcel de Rooy <m.de.rooy@rijksmuseum.nl>
Thu, 17 Jun 2021 09:59:18 +0000 (09:59 +0000)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Wed, 23 Jun 2021 13:09:55 +0000 (15:09 +0200)
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>
C4/Letters.pm
Koha/Patron/Password/Recovery.pm
misc/cronjobs/automatic_renewals.pl
misc/cronjobs/membership_expiry.pl

index 991a7ea..877d139 100644 (file)
@@ -1348,6 +1348,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,
@@ -1356,7 +1365,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}
index c2e2d27..0dafdae 100644 (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(
         {
index c8958cd..7b4158b 100755 (executable)
@@ -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 (
index 5038ce1..c140820 100755 (executable)
@@ -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,