Bugzilla – Attachment 37481 Details for
Bug 8000
Test mode for notices
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 8000 - Override emails of every message sent from Koha
Bug-8000---Override-emails-of-every-message-sent-f.patch (text/plain), 11.00 KB, created by
Mark Tompsett
on 2015-04-03 17:48:06 UTC
(
hide
)
Description:
Bug 8000 - Override emails of every message sent from Koha
Filename:
MIME Type:
Creator:
Mark Tompsett
Created:
2015-04-03 17:48:06 UTC
Size:
11.00 KB
patch
obsolete
>From 9d730e2681a14c1d9ec3753c564f7d0ae05663f6 Mon Sep 17 00:00:00 2001 >From: Blou <philippe.blouin@inlibro.com> >Date: Thu, 6 Mar 2014 15:16:09 -0500 >Subject: [PATCH] Bug 8000 - Override emails of every message sent from Koha > >For testing purposes, we do not want emails sent to (legitimate) users. >And sometime we also like to actually see what would be generated for the users. >This preference will allow to override every message sent by koha with >a new (temporary) To address. Leave it empty for normal usage. > > C4/Letters.pm > installer/data/mysql/sysprefs.sql > installer/data/mysql/updatedatabase.pl > koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref > >TESTING: > 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 | 27 ++++++++++++++++++---- > basket/sendbasket.pl | 2 ++ > installer/data/mysql/sysprefs.sql | 1 + > installer/data/mysql/updatedatabase.pl | 8 +++++++ > .../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, 47 insertions(+), 4 deletions(-) > >diff --git a/C4/Letters.pm b/C4/Letters.pm >index fb21c38..62f49ba 100644 >--- a/C4/Letters.pm >+++ b/C4/Letters.pm >@@ -403,7 +403,11 @@ sub SendAlerts { > my $alerts = getalert( '', 'issue', $externalid ); > 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; >@@ -515,10 +519,20 @@ sub SendAlerts { > # Remove the order tag > $letter->{content} =~ s/<order>(.*?)<\/order>/$1/gxms; > >+ # SendAllEmailsTo system preference to override for testing >+ my $emailsTo = join( ',', @email); >+ my $emailsCC = join( ',', @cc); >+ my $sendAllEmailsTo = C4::Context->preference('SendAllEmailsTo'); >+ # some validation. This could be improved. >+ if ($sendAllEmailsTo && $sendAllEmailsTo =~ /@/ ) { >+ $emailsTo = $sendAllEmailsTo; >+ $emailsCC = ''; >+ } >+ > # ... then send mail > my %mail = ( >- To => join( ',', @email), >- Cc => join( ',', @cc), >+ To => $emailsTo, >+ Cc => $emailsCC, > From => $userenv->{emailaddress}, > Subject => Encode::encode( "UTF-8", "" . $letter->{title} ), > Message => $letter->{'is_html'} >@@ -568,9 +582,12 @@ sub SendAlerts { > ) or return; > return { error => "no_email" } unless $externalid->{'emailaddr'}; > my $email = Koha::Email->new(); >+ my $emailaddr = $externalid->{'emailaddr'}; >+ my $sendAllEmailsTo = C4::Context->preference('SendAllEmailsTo'); >+ $emailaddr = $sendAllEmailsTo if ($sendAllEmailsTo && $sendAllEmailsTo =~ /@/ ); # some validation. This could be improved. > my %mail = $email->create_message_headers( > { >- to => $externalid->{'emailaddr'}, >+ to => $emailaddr, > from => $branchdetails->{'branchemail'}, > replyto => $branchdetails->{'branchreplyto'}, > sender => $branchdetails->{'branchreturnpath'}, >@@ -1128,6 +1145,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})"; >diff --git a/basket/sendbasket.pl b/basket/sendbasket.pl >index 0614aa3..356b351 100755 >--- a/basket/sendbasket.pl >+++ b/basket/sendbasket.pl >@@ -45,7 +45,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/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql >index 1e07e3c..64c0f37 100644 >--- a/installer/data/mysql/sysprefs.sql >+++ b/installer/data/mysql/sysprefs.sql >@@ -371,6 +371,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'), > ('SessionRestrictionByIP','1','Check for change in remote IP address for session security. Disable only when remote IP address changes frequently.','','YesNo'), >diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl >index 0592a94..8ba9f17 100755 >--- a/installer/data/mysql/updatedatabase.pl >+++ b/installer/data/mysql/updatedatabase.pl >@@ -9971,6 +9971,13 @@ if ( CheckVersion($DBversion) ) { > SetVersion($DBversion); > } > >+$DBversion = "3.19.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); >+} >+ > > # DEVELOPER PROCESS, search for anything to execute in the db_update directory > # SEE bug 13068 >@@ -9985,6 +9992,7 @@ while ( my $file = readdir $dirh ) { > my $rv = $installer->load_sql( $update_dir . $file ) ? 0 : 1; > } > >+ > =head1 FUNCTIONS > > =head2 TableExists($table) >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref >index e1d54a6..2cf5895 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref >@@ -50,6 +50,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 >diff --git a/misc/cronjobs/runreport.pl b/misc/cronjobs/runreport.pl >index 9dc6c58..4d0748c 100755 >--- a/misc/cronjobs/runreport.pl >+++ b/misc/cronjobs/runreport.pl >@@ -204,6 +204,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 551ee1c..0205194 100755 >--- a/opac/opac-sendbasket.pl >+++ b/opac/opac-sendbasket.pl >@@ -48,7 +48,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 3086ccc..5ef3c19 100755 >--- a/opac/opac-sendshelf.pl >+++ b/opac/opac-sendshelf.pl >@@ -48,7 +48,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 031c38a..b5c707a 100755 >--- a/virtualshelves/sendshelf.pl >+++ b/virtualshelves/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; > >-- >1.9.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 8000
:
21976
|
22315
|
24784
|
25917
|
25919
|
25920
|
25923
|
25924
|
25925
|
25926
|
25927
|
25928
|
25939
|
25950
|
25951
|
26446
|
37463
|
37464
|
37465
|
37466
|
37467
|
37468
|
37469
|
37472
|
37473
|
37474
|
37475
|
37476
|
37477
|
37478
|
37481
|
37482
|
37483
|
37484
|
37485
|
37486
|
37487
|
39985
|
39986
|
39987
|
39988
|
39989
|
39990
|
39991
|
39992
|
40215
|
40216
|
40217
|
40218
|
40219
|
40220
|
40221
|
40222
|
40223
|
40224
|
40225
|
40226
|
40227
|
40228
|
40229
|
40230
|
46354
|
46355
|
46356
|
46357
|
46358
|
46359
|
46360
|
46361
|
46362
|
49991
|
49992
|
49993
|
49998
|
49999
|
50000
|
55940
|
58434
|
62863
|
67155
|
70086
|
70087
|
70484
|
74110
|
74111
|
74848
|
80370
|
81487
|
81488
|
81589
|
81590
|
81591
|
84801
|
84802
|
84803
|
84804
|
84805
|
86861
|
86862
|
86863
|
86864
|
86865
|
88874
|
88875
|
88876
|
88877
|
88878
|
88879