line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Email::Find; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
71825
|
use strict; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
121
|
|
4
|
3
|
|
|
3
|
|
15
|
use vars qw($VERSION @EXPORT); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
225
|
|
5
|
|
|
|
|
|
|
$VERSION = "0.10"; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# Need qr//. |
8
|
|
|
|
|
|
|
require 5.005; |
9
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
17
|
use base qw(Exporter); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
401
|
|
11
|
|
|
|
|
|
|
@EXPORT = qw(find_emails); |
12
|
|
|
|
|
|
|
|
13
|
3
|
|
|
3
|
|
2998
|
use Email::Valid; |
|
3
|
|
|
|
|
423263
|
|
|
3
|
|
|
|
|
124
|
|
14
|
3
|
|
|
3
|
|
1607
|
use Email::Find::addrspec; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
340
|
|
15
|
3
|
|
|
3
|
|
16
|
use Mail::Address; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
1315
|
|
16
|
|
|
|
|
|
|
|
17
|
12
|
|
|
12
|
0
|
23
|
sub addr_regex { $Addr_spec_re } |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
{ |
20
|
|
|
|
|
|
|
my $validator = Email::Valid->new( |
21
|
|
|
|
|
|
|
'-fudge' => 0, |
22
|
|
|
|
|
|
|
'-fqdn' => 1, |
23
|
|
|
|
|
|
|
'-local_rules' => 0, |
24
|
|
|
|
|
|
|
'-mxcheck' => 0, |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub do_validate { |
28
|
96
|
|
|
96
|
0
|
149
|
my($self, $addr) = @_; |
29
|
96
|
|
|
|
|
316
|
$validator->address($addr); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub new { |
34
|
12
|
|
|
12
|
1
|
3538
|
my($proto, $callback) = @_; |
35
|
12
|
|
33
|
|
|
80
|
my $class = ref $proto || $proto; |
36
|
12
|
|
|
|
|
55
|
bless { callback => $callback }, $class; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub find { |
40
|
12
|
|
|
12
|
1
|
29
|
my($self, $r_text) = @_; |
41
|
|
|
|
|
|
|
|
42
|
12
|
|
|
|
|
18
|
my $emails_found = 0; |
43
|
12
|
|
|
|
|
31
|
my $re = $self->addr_regex; |
44
|
12
|
|
|
|
|
1294
|
$$r_text =~ s{($re)}{ |
45
|
96
|
|
|
|
|
284
|
my($replace, $found) = $self->validate($1); |
46
|
96
|
|
|
|
|
139
|
$emails_found += $found; |
47
|
96
|
|
|
|
|
54888
|
$replace; |
48
|
|
|
|
|
|
|
}eg; |
49
|
12
|
|
|
|
|
130
|
return $emails_found; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub validate { |
53
|
96
|
|
|
96
|
0
|
240
|
my($self, $orig_match) = @_; |
54
|
|
|
|
|
|
|
|
55
|
96
|
|
|
|
|
108
|
my $replace; |
56
|
96
|
|
|
|
|
125
|
my $found = 0; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# XXX Add cruft handling. |
59
|
96
|
|
|
|
|
118
|
my($start_cruft) = ''; |
60
|
96
|
|
|
|
|
119
|
my($end_cruft) = ''; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
63
|
96
|
50
|
|
|
|
407
|
if( $orig_match =~ s|([),.'";?!]+)$|| ) { #"')){ |
64
|
0
|
|
|
|
|
0
|
$end_cruft = $1; |
65
|
|
|
|
|
|
|
} |
66
|
96
|
100
|
|
|
|
196
|
if( my $email = $self->do_validate($orig_match) ) { |
67
|
45
|
|
|
|
|
17711
|
$email = Mail::Address->new('', $email); |
68
|
45
|
|
|
|
|
257
|
$found++; |
69
|
45
|
|
|
|
|
166
|
$replace = $start_cruft . $self->{callback}->($email, $orig_match) . $end_cruft; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
else { |
72
|
|
|
|
|
|
|
# XXX Again with the cruft! |
73
|
51
|
|
|
|
|
14770
|
$replace = $start_cruft . $orig_match . $end_cruft; |
74
|
|
|
|
|
|
|
} |
75
|
96
|
|
|
|
|
6307
|
return $replace, $found; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# backward comaptibility |
79
|
|
|
|
|
|
|
sub find_emails(\$&) { |
80
|
7
|
|
|
7
|
0
|
7068
|
my($r_text, $callback) = @_; |
81
|
7
|
|
|
|
|
139
|
my $finder = __PACKAGE__->new($callback); |
82
|
7
|
|
|
|
|
25
|
$finder->find($r_text); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
1; |
86
|
|
|
|
|
|
|
__END__ |