From 991580546397c5f0b291cfbc6de3151fcf39f887 Mon Sep 17 00:00:00 2001 From: Blou Date: Fri, 7 Mar 2014 13:31:30 -0500 Subject: [PATCH] Bug 8000 - Validate allEmailsTo email address before using it This patch adds Data::Validate::Email to validate the "allEmailsTo" address before using it as a unique destination. Added to PerlDependencies.pm for this and future potential usages. --- C4/Installer/PerlDependencies.pm | 5 +++++ C4/Letters.pm | 9 +++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/C4/Installer/PerlDependencies.pm b/C4/Installer/PerlDependencies.pm index 57c5972..36d097b 100644 --- a/C4/Installer/PerlDependencies.pm +++ b/C4/Installer/PerlDependencies.pm @@ -737,6 +737,11 @@ our $PERL_DEPS = { 'required' => '0', 'min_ver' => '0.89', }, + 'Data::Validate::Email' => { + 'usage' => 'Email validation', + 'required' => '1', + 'min_ver' => '0.04', + }, }; 1; diff --git a/C4/Letters.pm b/C4/Letters.pm index d240c8a..bcf0a49 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -35,6 +35,7 @@ use Date::Calc qw( Add_Delta_Days ); use Encode; use Carp; use Koha::Email; +use Data::Validate::Email qw(is_email); use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); @@ -406,7 +407,7 @@ sub SendAlerts { my $borinfo = C4::Members::GetMember('borrowernumber' => $_->{'borrowernumber'}); my $sendAllEmailsTo = C4::Context->preference('SendAllEmailsTo'); my $email = $sendAllEmailsTo; - if (!($sendAllEmailsTo && $sendAllEmailsTo =~ /@/) ){ # some validation. This could be improved. + if (!($sendAllEmailsTo && is_email($sendAllEmailsTo))){ $email = $borinfo->{email} or next; } @@ -525,7 +526,7 @@ sub SendAlerts { my $emailsCC = join( ',', @cc); my $sendAllEmailsTo = C4::Context->preference('SendAllEmailsTo'); # some validation. This could be improved. - if ($sendAllEmailsTo && $sendAllEmailsTo =~ /@/ ) { + if ($sendAllEmailsTo && is_email($sendAllEmailsTo) ) { $emailsTo = $sendAllEmailsTo; $emailsCC = ''; } @@ -585,7 +586,7 @@ sub SendAlerts { 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. + $emailaddr = $sendAllEmailsTo if ($sendAllEmailsTo && is_email($sendAllEmailsTo) ); my %mail = $email->create_message_headers( { to => $emailaddr, @@ -1154,7 +1155,7 @@ sub _send_message_by_email { $to_address = C4::Members::GetNoticeEmailAddress( $message->{'borrowernumber'} ); } my $sendAllEmailsTo = C4::Context->preference('SendAllEmailsTo'); - $to_address = $sendAllEmailsTo if ($sendAllEmailsTo && $sendAllEmailsTo =~ /@/ ); # some validation. This could be improved. + $to_address = $sendAllEmailsTo if ($sendAllEmailsTo && is_email($sendAllEmailsTo) ); unless ($to_address) { if (!$member) { warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})"; -- 2.1.4