| 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
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
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | # Mail::Box::IMAP4 wants a folder or it throws warnings | ||||||||||||||||||||||||||||
| 32 | 1 | ▶ | $args->{folder} ||= '/'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$args->{"folder"} ||= "/"
MC/DC0%0/1
$args->{"folder"} ||= "/"
$args->{"folder"}
Truth table50%1/2
A
A= $args->{"folder"}
| |||||||||||||||||||||||||||||
| 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"
MC/DC0%0/1
$args->{"message_type"} ||= "Mail::Box::IMAP4::Message"
$args->{"message_type"}
Truth table50%1/2
A
A= $args->{"message_type"}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
$imap and $imap->IsAuthenticated
MC/DC0%0/2
$imap and $imap->IsAuthenticated
$imap
$imap->IsAuthenticated
Truth table0%0/3
A and B
A= $imapB= $imap->IsAuthenticated
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||