File Coverage

blib/lib/Authen/Simple/Gmail.pm
Criterion Covered Total %
statement 15 42 35.7
branch 0 12 0.0
condition n/a
subroutine 5 7 71.4
pod 1 1 100.0
total 21 62 33.8


line stmt bran cond sub pod time code
1             package Authen::Simple::Gmail;
2              
3 1     1   892 use strict;
  1         2  
  1         46  
4 1     1   5 use warnings;
  1         2  
  1         41  
5              
6             $Authen::Simple::Gmail::VERSION = '0.2';
7              
8 1     1   1404 use IO::Socket::SSL ();
  1         93880  
  1         27  
9 1     1   858 use Authen::Simple::Adapter ();
  1         41752  
  1         23  
10 1     1   22 use base 'Authen::Simple::Adapter';
  1         2  
  1         436  
11              
12             my $portable_crlf = "\015\012"; # "\r\n" is not portable
13              
14             sub check {
15 0     0 1   my ( $self, $username, $password ) = @_;
16              
17 0           my $sock = IO::Socket::SSL->new(
18             'PeerHost' => "pop.gmail.com",
19             'PeerPort' => "995",
20             'SSL_verify_mode' => IO::Socket::SSL::SSL_VERIFY_NONE, # Patches welcome!
21             );
22              
23 0 0         if ( !$sock ) {
24 0 0         $self->log->error( IO::Socket::SSL->errstr() ) if $self->log;
25 0           return;
26             }
27              
28 0           my $line = <$sock>; # welcome msg
29              
30             # d("init: $line");
31 0           print {$sock} "USER $username$portable_crlf";
  0            
32 0           $line = <$sock>;
33              
34             # d("user: $line");
35 0 0         if ( $line !~ /^\+OK/ ) {
36 0 0         $self->log->debug("user not OK: $line") if $self->log;
37 0           __socket_end($sock);
38 0           return;
39             }
40              
41 0           print {$sock} "PASS $password$portable_crlf";
  0            
42 0           $line = <$sock>;
43              
44             # d("pass: $line");
45 0 0         if ( $line !~ /^\+OK/ ) {
46 0 0         $self->log->debug("user/pass not OK: $line") if $self->log;
47 0           __socket_end($sock);
48 0           return;
49             }
50              
51 0           __socket_end($sock);
52 0           return 1;
53             }
54              
55             sub __socket_end {
56 0     0     my ($sock) = @_;
57 0           print {$sock} "QUIT$portable_crlf";
  0            
58 0           $sock->close( 'SSL_ctx_free' => 1 );
59 0           return;
60             }
61              
62             1;
63              
64             __END__