line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::CheckArgs::email; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
31
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
6
|
use base 'HTML::CheckArgs::Object'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
702
|
|
7
|
1
|
|
|
1
|
|
1061
|
use Email::Valid; |
|
1
|
|
|
|
|
142297
|
|
|
1
|
|
|
|
|
519
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub is_valid { |
10
|
13
|
|
|
13
|
0
|
19
|
my $self = shift; |
11
|
|
|
|
|
|
|
|
12
|
13
|
|
|
|
|
38
|
my $value = $self->value; |
13
|
13
|
|
|
|
|
42
|
my $config = $self->config; |
14
|
|
|
|
|
|
|
|
15
|
13
|
|
|
|
|
63
|
$self->check_params( |
16
|
|
|
|
|
|
|
required => [], |
17
|
|
|
|
|
|
|
optional => [ qw( no_admin_addr no_gov_addr banned_domains ) ], |
18
|
|
|
|
|
|
|
cleanable => 1, |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# no value passed in |
22
|
13
|
100
|
100
|
|
|
98
|
if ( $config->{required} && !$value ) { |
|
|
100
|
100
|
|
|
|
|
23
|
1
|
|
|
|
|
9
|
$self->error_code( 'email_00' ); # required |
24
|
1
|
|
|
|
|
7
|
$self->error_message( 'Not given.' ); |
25
|
1
|
|
|
|
|
6
|
return; |
26
|
|
|
|
|
|
|
} elsif ( !$config->{required} && !$value ) { |
27
|
1
|
|
|
|
|
4
|
return 1; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# clean for validation |
31
|
11
|
|
|
|
|
24
|
$value = lc $value; |
32
|
11
|
|
|
|
|
26
|
$value =~ s/\s+//g; # rid of white space |
33
|
|
|
|
|
|
|
|
34
|
11
|
100
|
|
|
|
43
|
if ( !Email::Valid->address( $value ) ) { |
35
|
2
|
|
|
|
|
584
|
$self->error_code( 'email_01' ); # not valid |
36
|
2
|
|
|
|
|
9
|
$self->error_message( 'Not valid.' ); |
37
|
2
|
|
|
|
|
9
|
return; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# sanity check on length |
41
|
|
|
|
|
|
|
# not sure if it is strictly illegal to have addresses this long |
42
|
9
|
50
|
|
|
|
6406
|
if ( length( $value ) > 255 ) { |
43
|
0
|
|
|
|
|
0
|
$self->error_code( 'email_02' ); # over max length |
44
|
0
|
|
|
|
|
0
|
$self->error_message( 'Exceeds the maximum allowable length (255 characters).' ); |
45
|
0
|
|
|
|
|
0
|
return; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# check params |
49
|
|
|
|
|
|
|
# legal ones are: no_admin_addr, no_gov_addr, banned_domains |
50
|
9
|
100
|
|
|
|
25
|
if ( $config->{params}{no_admin_addr} ) { |
51
|
4
|
100
|
|
|
|
28
|
if ( $value =~ m/(^root@|^webmaster@|^postmaster@|^listmaster@|^hostmaster@|^abuse@)/ ) { |
52
|
1
|
|
|
|
|
5
|
$self->error_code( 'email_03' ); # admin address |
53
|
1
|
|
|
|
|
4
|
$self->error_message( 'System administrator addresses are prohibited; please use a personal address.' ); |
54
|
1
|
|
|
|
|
4
|
return; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
8
|
100
|
|
|
|
19
|
if ( $config->{params}{no_gov_addr} ) { |
59
|
3
|
100
|
|
|
|
13
|
if ( $value =~ m/\.gov$/ ) { |
60
|
1
|
|
|
|
|
4
|
$self->error_code( 'email_04' ); # gov address |
61
|
1
|
|
|
|
|
4
|
$self->error_message( 'Government addresses are prohibited; please use a personal address.' ); |
62
|
1
|
|
|
|
|
3
|
return; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
7
|
100
|
|
|
|
20
|
if ( exists $config->{params}{banned_domains} ) { |
67
|
2
|
100
|
|
|
|
5
|
if ( grep { $value =~ m/$_$/ } @{ $config->{params}{banned_domains} } ) { |
|
2
|
|
|
|
|
2615
|
|
|
2
|
|
|
|
|
7
|
|
68
|
1
|
|
|
|
|
12
|
$self->error_code( 'email_05' ); # banned domains |
69
|
1
|
|
|
|
|
4
|
$self->error_message( 'Addresses from this domain are prohibited.' ); |
70
|
1
|
|
|
|
|
7
|
return; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# send back cleaned up value? |
75
|
6
|
50
|
|
|
|
31
|
unless ( $config->{noclean} ) { |
76
|
6
|
|
|
|
|
21
|
$self->value( $value ); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
6
|
|
|
|
|
24
|
return 1; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |