line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Email::Forward::Dispatch; |
2
|
2
|
|
|
2
|
|
20539
|
use 5.008005; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
70
|
|
3
|
2
|
|
|
2
|
|
9
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
61
|
|
4
|
2
|
|
|
2
|
|
14
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
52
|
|
5
|
2
|
|
|
2
|
|
1177
|
use Email::MIME; |
|
2
|
|
|
|
|
101036
|
|
|
2
|
|
|
|
|
55
|
|
6
|
2
|
|
|
2
|
|
1059
|
use Module::Pluggable::Object; |
|
2
|
|
|
|
|
12700
|
|
|
2
|
|
|
|
|
178
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = "0.04"; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my $id = 0; |
11
|
|
|
|
|
|
|
sub new { |
12
|
3
|
|
|
3
|
0
|
2120
|
my ($class,%args) = @_; |
13
|
|
|
|
|
|
|
|
14
|
3
|
|
|
|
|
5
|
my $default_hook = ""; |
15
|
3
|
50
|
|
|
|
7
|
unless ($args{hooks_dir}) { |
16
|
3
|
50
|
|
|
|
7
|
$args{is_forward_cb} or die 'you must register is_forward_cb!'; |
17
|
3
|
50
|
|
|
|
5
|
$args{forward_cb} or die 'you must register forward_cb!'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
{ |
20
|
3
|
|
|
|
|
3
|
$default_hook = "Email::Forward::Dispatch::Hooks::Default".$id++; |
|
3
|
|
|
|
|
4
|
|
21
|
2
|
|
|
2
|
|
13
|
no strict 'refs'; ## no critic. |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
705
|
|
22
|
3
|
|
|
|
|
4
|
push @{"$default_hook\::ISA"}, 'Email::Forward::Dispatch::Hooks'; |
|
3
|
|
|
|
|
33
|
|
23
|
3
|
|
|
1
|
|
9
|
*{"$default_hook\::is_forward"} = sub { my ($class, $parsed) = @_; $args{is_forward_cb}->($default_hook,$parsed); }; |
|
3
|
|
|
|
|
12
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
3
|
|
24
|
3
|
|
|
1
|
|
8
|
*{"$default_hook\::forward"} = sub { my ($class, $parsed) = @_; $args{forward_cb}->($default_hook,$parsed); }; |
|
3
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
53
|
|
|
1
|
|
|
|
|
2
|
|
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
3
|
|
0
|
|
|
6
|
my $mail = $args{mail} || do {local $/; ; } || die 'you must set mail option or STDIN !'; |
29
|
|
|
|
|
|
|
|
30
|
3
|
|
50
|
|
|
11
|
my $self = bless +{ |
31
|
|
|
|
|
|
|
email => Email::MIME->new($mail), |
32
|
|
|
|
|
|
|
hooks_dir => $args{hooks_dir} || 'Email::Forward::Dispatch::Hooks', |
33
|
|
|
|
|
|
|
default_hook => $default_hook, |
34
|
|
|
|
|
|
|
}, $class; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
2
|
|
|
2
|
0
|
1611
|
sub default_hook { $_[0]->{default_hook} } |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub run { |
40
|
1
|
|
|
1
|
0
|
2219
|
my ($self) = @_; |
41
|
|
|
|
|
|
|
|
42
|
1
|
|
|
|
|
3
|
my @hooks = $self->fetch_hooks(); |
43
|
|
|
|
|
|
|
|
44
|
1
|
50
|
|
|
|
431
|
if (my $default_hook = $self->{default_hook}) { |
45
|
1
|
50
|
|
|
|
4
|
$default_hook->is_forward($self->{email}) |
46
|
|
|
|
|
|
|
and $default_hook->forward($self->{email}); |
47
|
|
|
|
|
|
|
}else{ |
48
|
0
|
|
|
|
|
0
|
for my $hook (@hooks) { |
49
|
0
|
0
|
|
|
|
0
|
next unless $hook->is_forward($self->{email}); |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
0
|
$hook->forward($self->{email}); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub fetch_hooks { |
57
|
1
|
|
|
1
|
0
|
2
|
my $self = shift; |
58
|
|
|
|
|
|
|
|
59
|
1
|
|
|
|
|
9
|
my @hooks = Module::Pluggable::Object->new( |
60
|
|
|
|
|
|
|
require => 1, |
61
|
|
|
|
|
|
|
search_path => $self->{hooks_dir}, |
62
|
|
|
|
|
|
|
)->plugins; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |
66
|
|
|
|
|
|
|
__END__ |