Verify email address format with external module.

This commit is contained in:
Bradley M. Kuhn 2015-12-11 18:32:59 -08:00
parent 9e2359ed72
commit b34de3c1da
3 changed files with 20 additions and 3 deletions

View file

@ -5,7 +5,7 @@ use ExtUtils::MakeMaker;
WriteMakefile(
NAME => 'Supporters',
VERSION_FROM => 'lib/Supporters.pm', # finds $VERSION, requires EU::MM from perl >= 5.5
PREREQ_PM => { DBI => 1.6, 'Test::Exception' => 0.35}, # e.g., Module::Name => 1.1
PREREQ_PM => { DBI => 1.6, 'Test::Exception' => 0.35, 'Mail::RFC822::Address' => 0.3 },
ABSTRACT_FROM => 'lib/Supporters.pm', # retrieve abstract from module
AUTHOR => 'Bradley M. Kuhn <bkuhn@>',
#LICENSE => 'perl',

View file

@ -28,6 +28,7 @@ our @EXPORT = qw(
our $VERSION = '0.02';
use Scalar::Util qw(looks_like_number);
use Mail::RFC822::Address;
######################################################################
@ -177,12 +178,16 @@ sub addEmailAddress($$$$) {
die "addEmailAddress: invalid id, $id" unless $self->_verifyId($id);
die "addEmailAddress:: invalid email address, $emailAddressType"
unless defined $emailAddressType and Mail::RFC822::Address::valid($emailAddress);
$self->dbh->begin_work();
my $addressTypeId = $self->addAddressType($emailAddressType);
my $sth = $self->dbh->prepare("INSERT INTO email_address(email_address, type_id, date_encountered)" .
"VALUES( ?, ?, date('now'))");
$self->dbh->begin_work();
$sth->execute($emailAddress, $addressTypeId);
my $addressId = $self->dbh->last_insert_id("","","","");
$sth->finish();

View file

@ -5,7 +5,7 @@
use strict;
use warnings;
use Test::More tests => 23;
use Test::More tests => 25;
use Test::Exception;
use Scalar::Util qw(looks_like_number);
@ -78,6 +78,18 @@ dies_ok { $sp->addEmailAddress(undef, 'drapper@example.org', 'paypal'); }
"addEmailAddress: dies for undefined id";
dies_ok { $sp->addEmailAddress("String", 'drapper@example.org', 'paypal'); }
"addEmailAddress: dies for non-numeric id";
dies_ok { $sp->addEmailAddress($drapperId, undef, 'work') }
"addEmailAddress: email address undefined fails";
dies_ok { $sp->addEmailAddress($drapperId, 'drapper@ex@ample.org', 'work') }
"addEmailAddress: email address with extra @ fails to add.";
# Verify that the addressType wasn't added when the Email address is invalid
# and the address type did not already exist.
my $val = $sp->dbh()->selectall_hashref("SELECT id FROM address_type WHERE name = 'work'", 'id');
ok((not defined $val or not defined $val->{'id'}),
"addEmailAddress: type is not added with email address is bad");
my $drapperEmailId;