blib/lib/Mail/Box/IMAP4/SSL.pm

filter: Statementstmt 60.0% 33 / 55 Branchbran 8.3% 1 / 12 Conditioncond 30.0% 3 / 10 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 90.0% 9 / 10 Podpod 50.0% 1 / 2 totaltotal 49.4% 47 / 95 CC 12 SCAR 38.4
CC
12
Cov
48%
init
80.3
type
2.0
BEGIN
1.0
CRAP 46.4
↑ Summary
1 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Mail::Box::IMAP4::SSL;
6 # ABSTRACT: handle IMAP4 folders with SSL
7 1 our $VERSION = '0.03'; # VERSION
8  
9 1 ▶use superclass 'Mail::Box::IMAP4' => 2.079;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use IO::Socket::SSL 1.12;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Mail::Reporter 2.079 qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Mail::Transport::IMAP4 2.079 qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Mail::IMAPClient 3.02;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 my $imaps_port = 993; # standard port for IMAP over SSL
16  
17 #--------------------------------------------------------------------------#
18 # init
19 #--------------------------------------------------------------------------#
20  
21 1 ▶sub init {
Subroutine init: called CC=12 SCAR=43.9
Pod undocumented
22 1 my ( $self, $args ) = @_;
23  
24 # until we're connected, mark as closed in case we exit early
25 # (otherwise, Mail::Box::DESTROY will try to close/unlock, which dies)
26 1 $self->{MB_is_closed}++;
27  
28 # if no port is provided, use the default
29 1 ▶ $args->{server_port} ||= $imaps_port;
Condition33%1/3
$args->{"server_port"} ||= $imaps_port
l!l&&r!l&&!r
010
MC/DC0%0/2
$args->{"server_port"} ||= $imaps_port
$args->{"server_port"} $imaps_port
Truth table33%1/3
A ||= B
A= $args->{"server_port"}B= $imaps_port
ABresult
1X1
011
000
30  
31 # Mail::Box::IMAP4 wants a folder or it throws warnings
32 1 ▶ $args->{folder} ||= '/';
Condition50%1/2
$args->{"folder"} ||= "/"
l!l
01
MC/DC0%0/1
$args->{"folder"} ||= "/"
$args->{"folder"}
Truth table50%1/2
A
A= $args->{"folder"}
Aresult
11
00
33  
34 # Use messages classes from our superclass type
35 1 ▶ $args->{message_type} ||= 'Mail::Box::IMAP4::Message';
Condition50%1/2
$args->{"message_type"} ||= "Mail::Box::IMAP4::Message"
l!l
01
MC/DC0%0/1
$args->{"message_type"} ||= "Mail::Box::IMAP4::Message"
$args->{"message_type"}
Truth table50%1/2
A
A= $args->{"message_type"}
Aresult
11
00
36  
37 # giving us a transport argument is an error since our only purpose
38 # is to create the right kind of transport object
39 1 ▶ if ( $args->{transporter} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"transporter"}) 1 0 1
40 1 Mail::Reporter->log(
41 ERROR => "The 'transporter' option is not valid for " . __PACKAGE__ );
42 0 return;
43 }
44  
45 # some arguments are required to connect to a server
46 0 for my $req (qw/ server_name username password/) {
47 0 ▶ if ( not defined $args->{$req} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args->{$req}) 0 0 0
48 0 Mail::Reporter->log( ERROR => "The '$req' option is required for " . __PACKAGE__ );
49 0 return;
50 }
51 }
52  
53 # trying to create the transport object
54  
55 my $verify_mode =
56 0 ▶ $ENV{MAIL_BOX_IMAP4_SSL_NOVERIFY} ? SSL_VERIFY_NONE() : SSL_VERIFY_PEER();
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'MAIL_BOX_IMAP4_SSL_NOVERIFY'} ? : 0 0 0
57  
58 my $ssl_socket = IO::Socket::SSL->new(
59 Proto => 'tcp',
60 PeerAddr => $args->{server_name},
61 PeerPort => $args->{server_port},
62 0 SSL_verify_mode => $verify_mode,
63 );
64  
65 0 ▶ unless ($ssl_socket) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ssl_socket) 0 0 0
66 0 Mail::Reporter->log( ERROR => "Couldn't connect to '$args->{server_name}': "
67 . IO::Socket::SSL::errstr() );
68 0 return;
69 }
70  
71 my $imap = Mail::IMAPClient->new(
72 User => $args->{username},
73 Password => $args->{password},
74 0 Socket => $ssl_socket,
75 Uid => 1, # Mail::Transport::IMAP4 does this
76 Peek => 1, # Mail::Transport::IMAP4 does this
77 );
78 0 my $imap_err = $@;
79  
80 0 ▶ unless ( $imap && $imap->IsAuthenticated ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($imap and $imap->IsAuthenticated) 0 0 0
Condition0%0/3
$imap and $imap->IsAuthenticated
!ll&&!rl&&r
000
MC/DC0%0/2
$imap and $imap->IsAuthenticated
$imap $imap->IsAuthenticated
Truth table0%0/3
A and B
A= $imapB= $imap->IsAuthenticated
ABresult
0X0
100
111
81 0 Mail::Reporter->log( ERROR => "Login rejected for user '$args->{username}'"
82 . " on server '$args->{server_name}': $imap_err" );
83 0 return;
84 }
85  
86 0 $args->{transporter} = Mail::Transport::IMAP4->new( imap_client => $imap, );
87  
88 0 ▶ unless ( $args->{transporter} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args->{"transporter"}) 0 0 0
89 0 Mail::Reporter->log(
90 ERROR => "Error creating Mail::Transport::IMAP4 from the SSL connection." );
91 0 return;
92 }
93  
94 # now that we have a valid transporter, mark ourselves open
95 # and let the superclass initialize
96 0 delete $self->{MB_is_closed};
97 0 $self->SUPER::init($args);
98  
99 }
100  
101 0 ▶sub type { 'imaps' }
Subroutine type: not called CC=1 SCAR=6.9
Pod documented
102  
103 1 1;
104  
105 __END__
↑ Summary