From 49069e0437b0403327a43378e67bedbf2b5f8bec Mon Sep 17 00:00:00 2001 From: Blou Date: Wed, 23 Oct 2013 09:58:18 -0400 Subject: [PATCH] Bug 8000 - Override emails of every message sent from Koha Following Jonathan Druart's comments, I fixed every single sendmail occurence: C4/Letters.pm (fixed SendAlerts() in addition to the previous standard method) basket/sendbasket.pl misc/cronjobs/runreport.pl opac/opac-sendbasket.pl opac/opac-sendshelf.pl virtualshelves/sendshelf.pl --- C4/Letters.pm | 17 ++++++++++++++--- basket/sendbasket.pl | 2 ++ misc/cronjobs/runreport.pl | 2 ++ opac/opac-sendbasket.pl | 2 ++ opac/opac-sendshelf.pl | 2 ++ virtualshelves/sendshelf.pl | 2 ++ 6 files changed, 24 insertions(+), 3 deletions(-) diff --git a/C4/Letters.pm b/C4/Letters.pm index 9a48cd2..6c492a4 100644 --- a/C4/Letters.pm +++ b/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'} ), diff --git a/basket/sendbasket.pl b/basket/sendbasket.pl index 66f73fa..d172fc0 100755 --- a/basket/sendbasket.pl +++ b/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; diff --git a/misc/cronjobs/runreport.pl b/misc/cronjobs/runreport.pl index 2357ed8..a269fd2 100755 --- a/misc/cronjobs/runreport.pl +++ b/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"; diff --git a/opac/opac-sendbasket.pl b/opac/opac-sendbasket.pl index da74745..6639e05 100755 --- a/opac/opac-sendbasket.pl +++ b/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; diff --git a/opac/opac-sendshelf.pl b/opac/opac-sendshelf.pl index 80b54e2..6f2ec7c 100755 --- a/opac/opac-sendshelf.pl +++ b/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; diff --git a/virtualshelves/sendshelf.pl b/virtualshelves/sendshelf.pl index 37a98ec..37db8c4 100755 --- a/virtualshelves/sendshelf.pl +++ b/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; -- 1.7.10.4