@@ -, +, @@ C4/Letters.pm installer/data/mysql/sysprefs.sql installer/data/mysql/updatedatabase.pl koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref 0) Run updatedatabase.pl 1) Enter a valid address for new preference SendAllEmailsTo, something that will be easily identified as NOT the normal destination for the Koha emails. 2) Have koha generate an email to a user. Or any other mean prefered that cause Koha to send email. 3) Validate that the email is NOT sent to the user. 4) Validate that the email IS sent to the overriding address. 5) Clean the preference 6) Redo the test, validate that the email is going to the right address. PS Not sure if those steps are precise enough. Here's one way: a) set AutoEmailOpacUser to true b) create a new user, with an email address c) Normally, a confirmation email is sent to the user. Validate that it goes to the SendAllEmailsTo one. --- C4/Letters.pm | 19 ++++++++++++++++--- basket/sendbasket.pl | 2 ++ installer/data/mysql/sysprefs.sql | 1 + installer/data/mysql/updatedatabase.pl | 7 +++++++ .../prog/en/modules/admin/preferences/admin.pref | 5 +++++ misc/cronjobs/runreport.pl | 2 ++ opac/opac-sendbasket.pl | 2 ++ opac/opac-sendshelf.pl | 2 ++ virtualshelves/sendshelf.pl | 2 ++ 9 files changed, 39 insertions(+), 3 deletions(-) --- a/C4/Letters.pm +++ a/C4/Letters.pm @@ -284,7 +284,11 @@ sub SendAlerts { foreach (@$alerts) { my $borinfo = C4::Members::GetMember('borrowernumber' => $_->{'borrowernumber'}); - my $email = $borinfo->{email} or next; + my $sendAllEmailsTo = C4::Context->preference('SendAllEmailsTo'); + my $email = $sendAllEmailsTo; + if (!($sendAllEmailsTo && $sendAllEmailsTo =~ /@/) ){ # some validation. This could be improved. + $email = $borinfo->{email} or next; + } # warn "sending issues..."; my $userenv = C4::Context->userenv; @@ -368,9 +372,12 @@ sub SendAlerts { want_librarian => 1, ) or return; + my $allemails = join( ',', @email); + my $sendAllEmailsTo = C4::Context->preference('SendAllEmailsTo'); + $allemails = $sendAllEmailsTo if ($sendAllEmailsTo && $sendAllEmailsTo =~ /@/ ); # some validation. This could be improved. # ... then send mail my %mail = ( - To => join( ',', @email), + To => $allemails, From => $userenv->{emailaddress}, Subject => Encode::encode( "utf8", "" . $letter->{title} ), Message => Encode::encode( "utf8", "" . $letter->{content} ), @@ -406,8 +413,12 @@ sub SendAlerts { ) or return; return { error => "no_email" } unless $externalid->{'emailaddr'}; + my $emailaddr = $externalid->{'emailaddr'}; + my $sendAllEmailsTo = C4::Context->preference('SendAllEmailsTo'); + $emailaddr = $sendAllEmailsTo if ($sendAllEmailsTo && $sendAllEmailsTo =~ /@/ ); # some validation. This could be improved. + # ... then send mail my %mail = ( - To => $externalid->{'emailaddr'}, + To => $emailaddr, From => $branchdetails->{'branchemail'} || C4::Context->preference("KohaAdminEmailAddress"), Subject => Encode::encode( "utf8", $letter->{'title'} ), Message => Encode::encode( "utf8", $letter->{'content'} ), @@ -926,6 +937,8 @@ sub _send_message_by_email { my $member = C4::Members::GetMember( 'borrowernumber' => $message->{'borrowernumber'} ); my $to_address = $message->{'to_address'}; + my $sendAllEmailsTo = C4::Context->preference('SendAllEmailsTo'); + $to_address = $sendAllEmailsTo if ($sendAllEmailsTo && $sendAllEmailsTo =~ /@/ ); # some validation. This could be improved. unless ($to_address) { unless ($member) { warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})"; --- a/basket/sendbasket.pl +++ a/basket/sendbasket.pl @@ -44,7 +44,9 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user ( ); my $bib_list = $query->param('bib_list'); +my $sendAllEmailsTo = C4::Context->preference('SendAllEmailsTo'); my $email_add = $query->param('email_add'); +$email_add = $sendAllEmailsTo if ($sendAllEmailsTo && $sendAllEmailsTo =~ /@/ ); # some validation. This could be improved. my $email_sender = $query->param('email_sender'); my $dbh = C4::Context->dbh; --- a/installer/data/mysql/sysprefs.sql +++ a/installer/data/mysql/sysprefs.sql @@ -336,6 +336,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('SelfCheckHelpMessage','','70|10','Enter HTML to include under the basic Web-based Self Checkout instructions on the Help page','Textarea'), ('SelfCheckReceiptPrompt','1','NULL','If ON, print receipt dialog pops up when self checkout is finished','YesNo'), ('SelfCheckTimeout','120','','Define the number of seconds before the Web-based Self Checkout times out a patron','Integer'), +('SendAllEmailsTo','',NULL,'This email will replace the To address in every message sent by the system. This is meant to help testing only.','Textarea'), ('SeparateHoldings','0',NULL,'Separate current branch holdings from other holdings','YesNo'), ('SeparateHoldingsBranch','homebranch','homebranch|holdingbranch','Branch used to separate holdings','Choice'), ('SessionStorage','mysql','mysql|Pg|tmp','Use database or a temporary file for storing session data','Choice'), --- a/installer/data/mysql/updatedatabase.pl +++ a/installer/data/mysql/updatedatabase.pl @@ -8012,6 +8012,13 @@ if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { SetVersion($DBversion); } +$DBversion = "3.15.00.XXX"; +if ( CheckVersion($DBversion) ) { + $dbh->do("INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES ('SendAllEmailsTo','',NULL,'This email will replace the To address in every message sent by the system. This is meant to help testing and validation only.','Textarea')"); + print "Upgrade to $DBversion done (Bug 8000 - system preferences to override the destination of every email sent by the system.)\n"; + SetVersion ($DBversion); +} + =head1 FUNCTIONS =head2 TableExists($table) --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref @@ -40,6 +40,11 @@ Administration: yes: Allow no: "Don't allow" - staff and patrons to create and view saved lists of books. + - + - Redirect all emails from Koha to + - pref: SendAllEmailsTo + class: email + - instead of their intended user. Login options: - - Automatically log out users after --- a/misc/cronjobs/runreport.pl +++ a/misc/cronjobs/runreport.pl @@ -179,6 +179,8 @@ if ($to or $from or $email) { $from or $from = C4::Context->preference('KohaAdminEmailAddress'); $to or $to = C4::Context->preference('KohaAdminEmailAddress'); } +my $sendAllEmailsTo = C4::Context->preference('SendAllEmailsTo'); +$to = $sendAllEmailsTo if ($sendAllEmailsTo && $sendAllEmailsTo =~ /@/ ); # some validation. This could be improved. unless (scalar(@ARGV)) { print STDERR "ERROR: No reportID(s) specified\n"; --- a/opac/opac-sendbasket.pl +++ a/opac/opac-sendbasket.pl @@ -47,7 +47,9 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user ( ); my $bib_list = $query->param('bib_list'); +my $sendAllEmailsTo = C4::Context->preference('SendAllEmailsTo'); my $email_add = $query->param('email_add'); +$email_add = $sendAllEmailsTo if ($sendAllEmailsTo && $sendAllEmailsTo =~ /@/ ); # some validation. This could be improved. my $email_sender = $query->param('email_sender'); my $dbh = C4::Context->dbh; --- a/opac/opac-sendshelf.pl +++ a/opac/opac-sendshelf.pl @@ -47,7 +47,9 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user ( ); my $shelfid = $query->param('shelfid'); +my $sendAllEmailsTo = C4::Context->preference('SendAllEmailsTo'); my $email = $query->param('email'); +$email = $sendAllEmailsTo if ($sendAllEmailsTo && $sendAllEmailsTo =~ /@/ ); # some validation. This could be improved. my $dbh = C4::Context->dbh; --- a/virtualshelves/sendshelf.pl +++ a/virtualshelves/sendshelf.pl @@ -46,7 +46,9 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user ( ); my $shelfid = $query->param('shelfid'); +my $sendAllEmailsTo = C4::Context->preference('SendAllEmailsTo'); my $email = $query->param('email'); +$email = $sendAllEmailsTo if ($sendAllEmailsTo && $sendAllEmailsTo =~ /@/ ); # some validation. This could be improved. my $dbh = C4::Context->dbh; --