From 3616c9a8a896d8bf1746d0dea07c1c7660efdd3d 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 259f9de..c31d3b3 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); @@ -405,7 +406,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; } @@ -524,7 +525,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 = ''; } @@ -584,7 +585,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, @@ -1153,7 +1154,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})"; -- 1.7.9.5