line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Authen::Simple::POP3; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
4130
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
43
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
198
|
|
|
1
|
|
|
|
|
44
|
|
5
|
1
|
|
|
1
|
|
6
|
use base 'Authen::Simple::Adapter'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
120
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
8938
|
use Net::POP3; |
|
1
|
|
|
|
|
9376
|
|
|
1
|
|
|
|
|
71
|
|
8
|
1
|
|
|
1
|
|
13
|
use Params::Validate qw[]; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1461
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = 0.2; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
__PACKAGE__->options({ |
13
|
|
|
|
|
|
|
host => { |
14
|
|
|
|
|
|
|
type => Params::Validate::SCALAR, |
15
|
|
|
|
|
|
|
default => 'localhost', |
16
|
|
|
|
|
|
|
optional => 1 |
17
|
|
|
|
|
|
|
}, |
18
|
|
|
|
|
|
|
port => { |
19
|
|
|
|
|
|
|
type => Params::Validate::SCALAR, |
20
|
|
|
|
|
|
|
default => 110, |
21
|
|
|
|
|
|
|
optional => 1 |
22
|
|
|
|
|
|
|
}, |
23
|
|
|
|
|
|
|
timeout => { |
24
|
|
|
|
|
|
|
type => Params::Validate::SCALAR, |
25
|
|
|
|
|
|
|
default => 60, |
26
|
|
|
|
|
|
|
optional => 1 |
27
|
|
|
|
|
|
|
}, |
28
|
|
|
|
|
|
|
method => { |
29
|
|
|
|
|
|
|
type => Params::Validate::SCALAR, |
30
|
|
|
|
|
|
|
default => 'plain', |
31
|
|
|
|
|
|
|
optional => 1, |
32
|
|
|
|
|
|
|
callbacks => { |
33
|
|
|
|
|
|
|
'valid option' => sub { |
34
|
|
|
|
|
|
|
$_[0] =~ /^apop|plain|sasl$/; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
}); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub check { |
41
|
0
|
|
|
0
|
1
|
|
my ( $self, $username, $password ) = @_; |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
my $connection = Net::POP3->new( |
44
|
|
|
|
|
|
|
Host => $self->host, |
45
|
|
|
|
|
|
|
Port => $self->port, |
46
|
|
|
|
|
|
|
Timeout => $self->timeout |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
|
49
|
0
|
0
|
|
|
|
|
unless ( defined $connection ) { |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
my $host = $self->host; |
52
|
0
|
|
0
|
|
|
|
my $reason = $@ || $! || 'Unknown reason'; |
53
|
|
|
|
|
|
|
|
54
|
0
|
0
|
|
|
|
|
$self->log->error( qq/Failed to connect to '$host'. Reason: '$reason'/ ) |
55
|
|
|
|
|
|
|
if $self->log; |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
return 0; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
my $success = 0; |
61
|
|
|
|
|
|
|
|
62
|
0
|
0
|
|
|
|
|
if ( $self->method eq 'plain' ) { |
63
|
0
|
0
|
|
|
|
|
$success++ if $connection->login( $username, $password ); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
0
|
0
|
|
|
|
|
if ( $self->method eq 'sasl' ) { |
67
|
0
|
0
|
|
|
|
|
$success++ if $connection->auth( $username, $password ); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
0
|
0
|
|
|
|
|
if ( $self->method eq 'apop' ) { |
71
|
0
|
0
|
|
|
|
|
$success++ if $connection->apop( $username, $password ); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
0
|
0
|
|
|
|
|
unless ( $success ) { |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
0
|
|
|
|
chomp( my $message = $connection->message || 'Unknown reason' ); |
77
|
|
|
|
|
|
|
|
78
|
0
|
0
|
|
|
|
|
$self->log->debug( qq/Failed to authenticate user '$username'. Reason: '$message'/ ) |
79
|
|
|
|
|
|
|
if $self->log; |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
return 0; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
0
|
0
|
|
|
|
|
$self->log->debug( qq/Successfully authenticated user '$username'./ ) |
85
|
|
|
|
|
|
|
if $self->log; |
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
return 1; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
__END__ |