From 184ab2e3a4249a0975cea370c3071b16db2601ba Mon Sep 17 00:00:00 2001
From: Alex Buckley <alexbuckley@catalyst.net.nz>
Date: Tue, 29 Oct 2024 08:54:39 +1300
Subject: [PATCH] Bug 38282: Set ReplytoDefault as the preferred from_address
 of sftp_file.pl

Default to KohaAdminEmailAddress if ReplytoDefault is not set

Test plan:
1. Enter a valid email address into ReplytoDefault and
   KohaAdminEmailAddress sysprefs

2. Apply patch and restart services

3. Generate a file on your Koha server. Place it in /tmp/test.mrc

4. Manually connect to the SFTP remote host and accept the hostkey

5. Enter Koha shell

6. Run the sftp_file.pl command-line script
./sftp_file.pl --host <your remote hostname> --user <your user> --pass <your password> --upload_dir <your upload directory> --file /tmp/test.mrc --email <your email>

7. Confirm the SFTP was successful

8. Confirm that the email that you received has a from address matching the
   ReplytoDefault syspref

9. Empty out the ReplytoDefault syspref and repeat steps 5 and 6

10. Confirm that the new email you received has a from address matching
    the KohaAdminEmailAddress syspref

Sponsored-by: Catalyst IT
Signed-off-by: David Nind <david@davidnind.com>
---
 misc/cronjobs/sftp_file.pl | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/misc/cronjobs/sftp_file.pl b/misc/cronjobs/sftp_file.pl
index 526f9d4882..e769ac1914 100755
--- a/misc/cronjobs/sftp_file.pl
+++ b/misc/cronjobs/sftp_file.pl
@@ -169,7 +169,9 @@ $sftp->setcwd($upload_dir)
 # If the --email parameter is defined then prepare sending an email confirming the success
 # or failure of the SFTP
 if ($email) {
-    if ( C4::Context->preference('KohaAdminEmailAddress') ) {
+    if ( C4::Context->preference('ReplytoDefault') ) {
+        $admin_address = C4::Context->preference('ReplytoDefault');
+    } elsif ( C4::Context->preference('KohaAdminEmailAddress') ) {
         $admin_address = C4::Context->preference('KohaAdminEmailAddress');
     }
 
-- 
2.39.5