| 1 | # Copyrights 2001-2019 by [Mark Overmeer]. | ||||||||||||||||||||||||||||
| 2 | # For other contributors see ChangeLog. | ||||||||||||||||||||||||||||
| 3 | # See the manual pages for details on the licensing terms. | ||||||||||||||||||||||||||||
| 4 | # Pod stripped from pm file by OODoc 2.02. | ||||||||||||||||||||||||||||
| 5 | # This code is part of distribution Mail-Box-IMAP4. Meta-POD processed with | ||||||||||||||||||||||||||||
| 6 | # OODoc into POD and HTML manual-pages. See README.md | ||||||||||||||||||||||||||||
| 7 | # Copyright Mark Overmeer. Licensed under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | package Mail::Transport::IMAP4; | ||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use vars '$VERSION'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 3 | $VERSION = '3.007'; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use base 'Mail::Transport::Receive'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 3 | ▶ | use Digest::HMAC_MD5; # only availability check for CRAM_MD5 | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 3 | ▶ | use Mail::IMAPClient (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 3 | ▶ | use List::Util qw/first/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | sub init($) | ||||||||||||||||||||||||||||
| 24 | 0 | ▶ | { my ($self, $args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
init: not called CC=16 SCAR=56.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 0 | ▶ | my $imap = $args->{imap_client} || 'Mail::IMAPClient'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$args->{'imap_client'} || 'Mail::IMAPClient'
MC/DC0%0/1
$args->{'imap_client'} || 'Mail::IMAPClient'
$args->{'imap_client'}
Truth table0%0/2
A
A= $args->{'imap_client'}
| |||||||||||||||||||||||||||||
| 27 | 0 | ▶ | if(ref $imap) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | 0 | { $args->{port} = $imap->Port; | |||||||||||||||||||||||||||
| 29 | 0 | $args->{hostname} = $imap->Server; | |||||||||||||||||||||||||||
| 30 | 0 | $args->{username} = $imap->User; | |||||||||||||||||||||||||||
| 31 | 0 | $args->{password} = $imap->Password; | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | else | ||||||||||||||||||||||||||||
| 34 | 0 | ▶ | { $args->{port} ||= $args->{ssl} ? 993 : 143; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$args->{"port"} ||= $args->{"ssl"} ? 993 : 143
MC/DC0%0/2
$args->{"port"} ||= $args->{"ssl"} ? 993 : 143
$args->{"port"}
$args->{"ssl"} ? 993 : 143
Truth table0%0/3
A ||= B
A= $args->{"port"}B= $args->{"ssl"} ? 993 : 143
| |||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | ▶ | $args->{via} ||= 'imap4'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$args->{"via"} ||= "imap4"
MC/DC0%0/1
$args->{"via"} ||= "imap4"
$args->{"via"}
Truth table0%0/2
A
A= $args->{"via"}
| |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 0 | ▶ | $self->SUPER::init($args) or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | ▶ | $self->authentication($args->{authenticate} || 'AUTO'); | ||||||||||||||||||||||||||
|
Condition0%0/2
$args->{'authenticate'} || 'AUTO'
MC/DC0%0/1
$args->{'authenticate'} || 'AUTO'
$args->{'authenticate'}
Truth table0%0/2
A
A= $args->{'authenticate'}
| |||||||||||||||||||||||||||||
| 42 | 0 | $self->{MTI_domain} = $args->{domain}; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | unless(ref $imap) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | { # Create the IMAP transporter | ||||||||||||||||||||||||||||
| 46 | 0 | my %opts; | |||||||||||||||||||||||||||
| 47 | $opts{ucfirst lc} = delete $args->{$_} | ||||||||||||||||||||||||||||
| 48 | 0 | for grep /^[A-Z]/, keys %$args; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | # backwards compatibility | ||||||||||||||||||||||||||||
| 51 | 0 | ▶ | $opts{Starttls} ||= $args->{starttls}; | ||||||||||||||||||||||||||
|
Condition0%0/3
$opts{"Starttls"} ||= $args->{"starttls"}
MC/DC0%0/2
$opts{"Starttls"} ||= $args->{"starttls"}
$opts{"Starttls"}
$args->{"starttls"}
Truth table0%0/3
A ||= B
A= $opts{"Starttls"}B= $args->{"starttls"}
| |||||||||||||||||||||||||||||
| 52 | 0 | ▶ | my $ssl = $opts{Ssl} ||= $args->{ssl}; | ||||||||||||||||||||||||||
|
Condition0%0/3
$opts{"Ssl"} ||= $args->{"ssl"}
MC/DC0%0/2
$opts{"Ssl"} ||= $args->{"ssl"}
$opts{"Ssl"}
$args->{"ssl"}
Truth table0%0/3
A ||= B
A= $opts{"Ssl"}B= $args->{"ssl"}
| |||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 0 | ▶ | $opts{Ssl} = [ %$ssl ] if ref $ssl eq 'HASH'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | ▶ | $imap = $self->createImapClient($imap, %opts) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | or return undef; | ||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | $self->imapClient($imap) or return undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 0 | ▶ | $self->login or return undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 0 | $self; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | sub url() | ||||||||||||||||||||||||||||
| 66 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
url: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 67 | 0 | my ($host, $port, $user, $pwd) = $self->remoteHost; | |||||||||||||||||||||||||||
| 68 | 0 | my $name = $self->folderName; | |||||||||||||||||||||||||||
| 69 | 0 | ▶ | my $proto = $self->usesSSL ? 'imap4s' : 'imap4'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 0 | "$proto://$user:$pwd\@$host:$port$name"; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | #------------------------------------------ | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 0 | ▶ | sub usesSSL() { shift->imapClient->Ssl } | ||||||||||||||||||||||||||
|
Subroutine
usesSSL: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | sub authentication(@) | ||||||||||||||||||||||||||||
| 80 | 0 | ▶ | { my ($self, @types) = @_; | ||||||||||||||||||||||||||
|
Subroutine
authentication: not called CC=13 SCAR=52.0
Pod
documented
| |||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | # What the client wants to use to login | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | @types | ||||||||||||||||||||||||||||
| 85 | 0 | ▶ | or @types = exists $self->{MTI_auth} ? @{$self->{MTI_auth}} : 'AUTO'; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 0 | ▶ | @types = qw/CRAM-MD5 DIGEST-MD5 PLAIN NTLM LOGIN/ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@types == 1 and $types[0] eq "AUTO"
MC/DC0%0/2
@types == 1 and $types[0] eq "AUTO"
@types == 1
$types[0] eq "AUTO"
Truth table0%0/3
A and B
A= @types == 1B= $types[0] eq "AUTO"
| |||||||||||||||||||||||||||||
| 88 | if @types == 1 && $types[0] eq 'AUTO'; | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 0 | $self->{MTI_auth} = \@types; | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 0 | my @clientside; | |||||||||||||||||||||||||||
| 93 | 0 | foreach my $auth (@types) | |||||||||||||||||||||||||||
| 94 | 0 | ▶ | { push @clientside | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 95 | , ref $auth eq 'ARRAY' ? $auth | ||||||||||||||||||||||||||||
| 96 | : $auth eq 'NTLM' ? [ NTLM => \&Authen::NTLM::ntlm ] | ||||||||||||||||||||||||||||
| 97 | : [ $auth => undef ]; | ||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 0 | my %clientside = map +($_->[0] => $_), @clientside; | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | # What does the server support? in its order of preference. | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 0 | ▶ | my $imap = $self->imapClient or return (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | 0 | ▶ | my @serverside = map { m/^AUTH=(\S+)/ ? uc($1) : () } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | $imap->capability; | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 0 | my @auth; | |||||||||||||||||||||||||||
| 109 | 0 | ▶ | if(@serverside) # server list auth capabilities | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | 0 | ▶ | { @auth = map { $clientside{$_} ? delete $clientside{$_} : () } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | @serverside; | ||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | 0 | ▶ | @auth = @clientside unless @auth; # fallback to client's preference | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 0 | @auth; | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | sub domain(;$) | ||||||||||||||||||||||||||||
| 120 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
domain: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 121 | 0 | ▶ | return $self->{MTI_domain} = shift if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | 0 | ▶ | $self->{MTI_domain} || ($self->remoteHost)[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | #------------------------------------------ | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | sub imapClient(;$) | ||||||||||||||||||||||||||||
| 129 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
imapClient: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 130 | 0 | ▶ | @_ ? ($self->{MTI_client} = shift) : $self->{MTI_client}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | sub createImapClient($@) | ||||||||||||||||||||||||||||
| 135 | 0 | ▶ | { my ($self, $class, @args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
createImapClient: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 0 | my ($host, $port) = $self->remoteHost; | |||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 0 | my $debug_level = $self->logPriority('DEBUG')+0; | |||||||||||||||||||||||||||
| 140 | 0 | ▶ | if($self->log <= $debug_level || $self->trace <= $debug_level) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->log <= $debug_level or $self->trace <= $debug_level
MC/DC0%0/2
$self->log <= $debug_level or $self->trace <= $debug_level
$self->log <= $debug_level
$self->trace <= $debug_level
Truth table0%0/3
A or B
A= $self->log <= $debug_levelB= $self->trace <= $debug_level
| |||||||||||||||||||||||||||||
| 141 | 0 | { tie *dh, 'Mail::IMAPClient::Debug', $self; | |||||||||||||||||||||||||||
| 142 | 0 | push @args, Debug => 1, Debug_fh => \*dh; | |||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | 0 | my $client = $class->new | |||||||||||||||||||||||||||
| 146 | ( Server => $host, Port => $port | ||||||||||||||||||||||||||||
| 147 | , User => undef, Password => undef # disable auto-login | ||||||||||||||||||||||||||||
| 148 | , Uid => 1 # Safer | ||||||||||||||||||||||||||||
| 149 | , Peek => 1 # Don't set \Seen automaticly | ||||||||||||||||||||||||||||
| 150 | , @args | ||||||||||||||||||||||||||||
| 151 | ); | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 0 | ▶ | $self->log(ERROR => $@), return undef if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 154 | 0 | $client; | |||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | sub login(;$) | ||||||||||||||||||||||||||||
| 159 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
login: not called CC=12 SCAR=50.5
Pod
documented
| |||||||||||||||||||||||||||||
| 160 | 0 | my $imap = $self->imapClient; | |||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 0 | ▶ | return $self if $imap->IsAuthenticated; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 0 | my ($interval, $retries, $timeout) = $self->retry; | |||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 0 | my ($host, $port, $username, $password) = $self->remoteHost; | |||||||||||||||||||||||||||
| 167 | 0 | ▶ | unless(defined $username) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 168 | 0 | { $self->log(ERROR => "IMAP4 requires a username and password"); | |||||||||||||||||||||||||||
| 169 | 0 | return; | |||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||
| 171 | 0 | ▶ | unless(defined $password) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 172 | 0 | { $self->log(ERROR => "IMAP4 username $username requires a password"); | |||||||||||||||||||||||||||
| 173 | 0 | return; | |||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | 0 | my $warn_fail; | |||||||||||||||||||||||||||
| 177 | 0 | while(1) | |||||||||||||||||||||||||||
| 178 | { | ||||||||||||||||||||||||||||
| 179 | 0 | foreach my $auth ($self->authentication) | |||||||||||||||||||||||||||
| 180 | 0 | { my ($mechanism, $challenge) = @$auth; | |||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | 0 | $imap->User(undef); | |||||||||||||||||||||||||||
| 183 | 0 | $imap->Password(undef); | |||||||||||||||||||||||||||
| 184 | 0 | $imap->Authmechanism(undef); # disable auto-login | |||||||||||||||||||||||||||
| 185 | 0 | $imap->Authcallback(undef); | |||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | 0 | ▶ | unless($imap->connect) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 188 | 0 | { $self->log(ERROR => "IMAP cannot connect to $host: " | |||||||||||||||||||||||||||
| 189 | , $imap->LastError); | ||||||||||||||||||||||||||||
| 190 | 0 | return undef; | |||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | 0 | $imap->User($username); | |||||||||||||||||||||||||||
| 194 | 0 | $imap->Password($password); | |||||||||||||||||||||||||||
| 195 | 0 | $imap->Authmechanism($mechanism); | |||||||||||||||||||||||||||
| 196 | 0 | ▶ | $imap->Authcallback($challenge) if defined $challenge; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | 0 | ▶ | if($imap->login) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 199 | { | ||||||||||||||||||||||||||||
| 200 | 0 | $self->log(NOTICE => "IMAP4 authenication $mechanism to " | |||||||||||||||||||||||||||
| 201 | . "$username\@$host:$port successful"); | ||||||||||||||||||||||||||||
| 202 | 0 | return $self; | |||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | 0 | ▶ | $self->log(ERROR => "Couldn't contact to $username\@$host:$port") | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$retries > 0 and --$retries == 0
MC/DC0%0/2
$retries > 0 and --$retries == 0
$retries > 0
--$retries == 0
Truth table0%0/3
A and B
A= $retries > 0B= --$retries == 0
| |||||||||||||||||||||||||||||
| 207 | , return undef if $retries > 0 && --$retries == 0; | ||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | 0 | ▶ | $warn_fail++ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 210 | or $self->log(WARNING => "Failed attempt to login $username\@$host" | ||||||||||||||||||||||||||||
| 211 | . ", retrying ".($retries+1)." times"); | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | 0 | ▶ | sleep $interval if $interval; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | 0 | undef; | |||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | sub currentFolder(;$) | ||||||||||||||||||||||||||||
| 221 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
currentFolder: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||
| 222 | 0 | ▶ | return $self->{MTI_folder} unless @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | 0 | my $name = shift; | |||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | 0 | ▶ | if(defined $self->{MTI_folder} && $name eq $self->{MTI_folder}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $self->{"MTI_folder"} and $name eq $self->{"MTI_folder"}
MC/DC0%0/2
defined $self->{"MTI_folder"} and $name eq $self->{"MTI_folder"}
defined $self->{"MTI_folder"}
$name eq $self->{"MTI_folder"}
Truth table0%0/3
A and B
A= defined $self->{"MTI_folder"}B= $name eq $self->{"MTI_folder"}
| |||||||||||||||||||||||||||||
| 227 | 0 | { $self->log(DEBUG => "Folder $name already selected."); | |||||||||||||||||||||||||||
| 228 | 0 | return $name; | |||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | # imap first deselects the old folder so if the next call | ||||||||||||||||||||||||||||
| 232 | # fails the server will not have anything selected. | ||||||||||||||||||||||||||||
| 233 | 0 | $self->{MTI_folder} = undef; | |||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | 0 | ▶ | my $imap = $self->imapClient or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | 0 | ▶ | if($name eq '/' || $imap->select($name)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$name eq "/" or $imap->select($name)
MC/DC0%0/2
$name eq "/" or $imap->select($name)
$name eq "/"
$imap->select($name)
Truth table0%0/3
A or B
A= $name eq "/"B= $imap->select($name)
| |||||||||||||||||||||||||||||
| 238 | 0 | { $self->{MTI_folder} = $name; | |||||||||||||||||||||||||||
| 239 | 0 | $self->log(NOTICE => "Selected folder $name"); | |||||||||||||||||||||||||||
| 240 | 0 | return 1; | |||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | # Just because we couldn't select the folder that doesn't mean it doesn't | ||||||||||||||||||||||||||||
| 244 | # exist. It just means that this particular imap client is warning us | ||||||||||||||||||||||||||||
| 245 | # that it can't contain messages. So we'll verify that it does exist | ||||||||||||||||||||||||||||
| 246 | # and, if so, we'll pretend like we could have selected it as if it were | ||||||||||||||||||||||||||||
| 247 | # a regular folder. | ||||||||||||||||||||||||||||
| 248 | # IMAPClient::exists() only works reliably for leaf folders so we need | ||||||||||||||||||||||||||||
| 249 | # to grep for it ourselves. | ||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | 0 | ▶ | if(first { $_ eq $name } $self->folders) | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 252 | 0 | { $self->{MTI_folder} = $name; | |||||||||||||||||||||||||||
| 253 | 0 | $self->log(NOTICE => "Couldn't select $name but it does exist."); | |||||||||||||||||||||||||||
| 254 | 0 | return 0; | |||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | 0 | $self->log(NOTICE => "Folder $name does not exist!"); | |||||||||||||||||||||||||||
| 258 | 0 | undef; | |||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | sub folders(;$) | ||||||||||||||||||||||||||||
| 263 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
folders: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 264 | 0 | my $top = shift; | |||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | 0 | ▶ | my $imap = $self->imapClient or return (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 267 | 0 | ▶ | $top = undef if defined $top && $top eq '/'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $top and $top eq "/"
MC/DC0%0/2
defined $top and $top eq "/"
defined $top
$top eq "/"
Truth table0%0/3
A and B
A= defined $topB= $top eq "/"
| |||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||
| 269 | # We need to force the remote IMAP client to only return folders | ||||||||||||||||||||||||||||
| 270 | # *underneath* the folder we specify. By default they want to return | ||||||||||||||||||||||||||||
| 271 | # all folders. | ||||||||||||||||||||||||||||
| 272 | # Alas IMAPClient always appends the separator so, despite what it says | ||||||||||||||||||||||||||||
| 273 | # in its own docs, there's purpose to doing this. We just need | ||||||||||||||||||||||||||||
| 274 | # to get whatever we get and postprocess it. ???Still true??? | ||||||||||||||||||||||||||||
| 275 | 0 | my @folders = $imap->folders($top); | |||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||
| 277 | # We need to post-process the list returned by IMAPClient. | ||||||||||||||||||||||||||||
| 278 | # This selects out the level of directories we're interested in. | ||||||||||||||||||||||||||||
| 279 | 0 | my $sep = $imap->separator; | |||||||||||||||||||||||||||
| 280 | 0 | ▶ | my $level = 1 + (defined $top ? () = $top =~ m/\Q$sep\E/g : -1); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||
| 282 | # There may be duplications, thanks to subdirs so we uniq it | ||||||||||||||||||||||||||||
| 283 | 0 | my %uniq; | |||||||||||||||||||||||||||
| 284 | 0 | ▶ | $uniq{(split /\Q$sep\E/, $_)[$level] || ''}++ for @folders; | ||||||||||||||||||||||||||
|
Condition0%0/2
(split(/\Q$sep\E/, $_, 0))[$level] || ''
MC/DC0%0/1
(split(/\Q$sep\E/, $_, 0))[$level] || ''
(split(/\Q$sep\E/, $_, 0))[$level]
Truth table0%0/2
A
A= (split(/\Q$sep\E/, $_, 0))[$level]
| |||||||||||||||||||||||||||||
| 285 | 0 | delete $uniq{''}; | |||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||
| 287 | 0 | keys %uniq; | |||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||
| 291 | sub ids($) | ||||||||||||||||||||||||||||
| 292 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
ids: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 293 | 0 | ▶ | my $imap = $self->imapClient or return (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 294 | 0 | $imap->messages; | |||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||
| 298 | # Explanation in Mail::Box::IMAP4::Message chapter DETAILS | ||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||
| 300 | 3 | my %flags2labels = | |||||||||||||||||||||||||||
| 301 | ( # Standard IMAP4 labels | ||||||||||||||||||||||||||||
| 302 | '\Seen' => [seen => 1] | ||||||||||||||||||||||||||||
| 303 | , '\Answered' => [replied => 1] | ||||||||||||||||||||||||||||
| 304 | , '\Flagged' => [flagged => 1] | ||||||||||||||||||||||||||||
| 305 | , '\Deleted' => [deleted => 1] | ||||||||||||||||||||||||||||
| 306 | , '\Draft' => [draft => 1] | ||||||||||||||||||||||||||||
| 307 | , '\Recent' => [old => 0] | ||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||
| 309 | # For the Netzwert extension (Mail::Box::Netzwert), some labels were | ||||||||||||||||||||||||||||
| 310 | # added. You'r free to support them as well. | ||||||||||||||||||||||||||||
| 311 | , '\Spam' => [spam => 1] | ||||||||||||||||||||||||||||
| 312 | ); | ||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||
| 314 | 3 | my %labels2flags; | |||||||||||||||||||||||||||
| 315 | 3 | ▶ | while(my ($k, $v) = each %flags2labels) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 316 | 21 | { $labels2flags{$v->[0]} = [ $k => $v->[1] ]; | |||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||
| 319 | # where IMAP4 supports requests for multiple flags at once, we here only | ||||||||||||||||||||||||||||
| 320 | # request one set of flags a time (which will be slower) | ||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||
| 322 | sub getFlags($$) | ||||||||||||||||||||||||||||
| 323 | 0 | ▶ | { my ($self, $id) = @_; | ||||||||||||||||||||||||||
|
Subroutine
getFlags: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 324 | 0 | ▶ | my $imap = $self->imapClient or return (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 325 | 0 | my $labels = $self->flagsToLabels(SET => $imap->flags($id)); | |||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||
| 327 | # Add default values for missing flags | ||||||||||||||||||||||||||||
| 328 | 0 | foreach my $s (values %flags2labels) | |||||||||||||||||||||||||||
| 329 | { $labels->{$s->[0]} = not $s->[1] | ||||||||||||||||||||||||||||
| 330 | 0 | ▶ | unless exists $labels->{$s->[0]}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||
| 333 | 0 | $labels; | |||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||
| 337 | 0 | ▶ | sub listFlags() { keys %flags2labels } | ||||||||||||||||||||||||||
|
Subroutine
listFlags: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||
| 340 | # Mail::IMAPClient can only set one value a time, however we do more... | ||||||||||||||||||||||||||||
| 341 | sub setFlags($@) | ||||||||||||||||||||||||||||
| 342 | 0 | ▶ | { my ($self, $id) = (shift, shift); | ||||||||||||||||||||||||||
|
Subroutine
setFlags: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||
| 344 | 0 | ▶ | my $imap = $self->imapClient or return (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 345 | 0 | my (@set, @unset, @nonstandard); | |||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||
| 347 | 0 | ▶ | while(@_) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 348 | 0 | { my ($label, $value) = (shift, shift); | |||||||||||||||||||||||||||
| 349 | 0 | ▶ | if(my $r = $labels2flags{$label}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 350 | 0 | { my $flag = $r->[0]; | |||||||||||||||||||||||||||
| 351 | 0 | ▶ | $value = $value ? $r->[1] : !$r->[1]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 352 | # exor can not be used, because value may be string | ||||||||||||||||||||||||||||
| 353 | 0 | ▶ | $value ? (push @set, $flag) : (push @unset, $flag); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||
| 355 | else | ||||||||||||||||||||||||||||
| 356 | 0 | { push @nonstandard, ($label => $value); | |||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||
| 360 | 0 | $imap->set_flag($_, $id) foreach @set; | |||||||||||||||||||||||||||
| 361 | 0 | $imap->unset_flag($_, $id) foreach @unset; | |||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||
| 363 | 0 | @nonstandard; | |||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||
| 367 | sub labelsToFlags(@) | ||||||||||||||||||||||||||||
| 368 | 7 | ▶ | { my $thing = shift; | ||||||||||||||||||||||||||
|
Subroutine
labelsToFlags: called CC=10 SCAR=23.1
Pod
documented
| |||||||||||||||||||||||||||||
| 369 | 7 | my @set; | |||||||||||||||||||||||||||
| 370 | 7 | ▶ | if(@_==1) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 371 | 2 | { my $labels = shift; | |||||||||||||||||||||||||||
| 372 | 2 | ▶ | while(my ($label, $value) = each %$labels) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 373 | 6 | ▶ | { if(my $r = $labels2flags{$label}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 374 | 6 | ▶ | { push @set, $r->[0] if ($value ? $r->[1] : !$r->[1]); | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||
| 378 | else | ||||||||||||||||||||||||||||
| 379 | 5 | ▶ | { while(@_) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 380 | 20 | { my ($label, $value) = (shift, shift); | |||||||||||||||||||||||||||
| 381 | 20 | ▶ | if(my $r = $labels2flags{$label}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 382 | 20 | ▶ | { push @set, $r->[0] if ($value ? $r->[1] : !$r->[1]); | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||
| 387 | 7 | join " ", sort @set; | |||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||
| 391 | sub flagsToLabels($@) | ||||||||||||||||||||||||||||
| 392 | 3 | ▶ | { my ($thing, $what) = (shift, shift); | ||||||||||||||||||||||||||
|
Subroutine
flagsToLabels: called CC=8 SCAR=21.7
Pod
documented
| |||||||||||||||||||||||||||||
| 393 | 3 | my %labels; | |||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||
| 395 | 3 | my $clear = $what eq 'CLEAR'; | |||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||
| 397 | 3 | foreach my $f (@_) | |||||||||||||||||||||||||||
| 398 | 9 | ▶ | { if(my $lab = $flags2labels{$f}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 399 | 9 | ▶ | { $labels{$lab->[0]} = $clear ? not($lab->[1]) : $lab->[1]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||
| 401 | else | ||||||||||||||||||||||||||||
| 402 | 0 | { (my $lab = $f) =~ s,^\\,,; | |||||||||||||||||||||||||||
| 403 | 0 | $labels{$lab}++; | |||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||
| 407 | 3 | ▶ | if($what eq 'REPLACE') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 408 | 3 | { my %found = map { ($_ => 1) } @_; | |||||||||||||||||||||||||||
| 409 | 3 | foreach my $f (keys %flags2labels) | |||||||||||||||||||||||||||
| 410 | 21 | ▶ | { next if $found{$f}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 411 | 12 | my $lab = $flags2labels{$f}; | |||||||||||||||||||||||||||
| 412 | 12 | $labels{$lab->[0]} = not $lab->[1]; | |||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||
| 416 | 3 | ▶ | wantarray ? %labels : \%labels; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||
| 420 | sub getFields($@) | ||||||||||||||||||||||||||||
| 421 | 0 | ▶ | { my ($self, $id) = (shift, shift); | ||||||||||||||||||||||||||
|
Subroutine
getFields: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 422 | 0 | ▶ | my $imap = $self->imapClient or return (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 423 | 0 | ▶ | my $parsed = $imap->parse_headers($id, @_) or return (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||
| 425 | 0 | my @fields; | |||||||||||||||||||||||||||
| 426 | 0 | ▶ | while(my($n,$c) = each %$parsed) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 427 | 0 | { push @fields, map { Mail::Message::Field::Fast->new($n, $_) } @$c; | |||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||
| 430 | 0 | @fields; | |||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||
| 434 | sub getMessageAsString($) | ||||||||||||||||||||||||||||
| 435 | 0 | ▶ | { my $imap = shift->imapClient or return; | ||||||||||||||||||||||||||
|
Subroutine
getMessageAsString: not called CC=3 SCAR=24.8
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 436 | 0 | ▶ | my $uid = ref $_[0] ? shift->unique : shift; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 437 | 0 | $imap->message_string($uid); | |||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||
| 441 | sub fetch($@) | ||||||||||||||||||||||||||||
| 442 | 0 | ▶ | { my ($self, $msgs, @info) = @_; | ||||||||||||||||||||||||||
|
Subroutine
fetch: not called CC=11 SCAR=48.8
Pod
documented
| |||||||||||||||||||||||||||||
| 443 | 0 | ▶ | return () unless @$msgs; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 444 | 0 | ▶ | my $imap = $self->imapClient or return (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||
| 446 | 0 | my %msgs = map { ($_->unique => {message => $_} ) } @$msgs; | |||||||||||||||||||||||||||
| 447 | 0 | my $lines = $imap->fetch( [keys %msgs], @info ); | |||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||
| 449 | # It's a pity that Mail::IMAPClient::fetch_hash cannot be used for | ||||||||||||||||||||||||||||
| 450 | # single messages... now I had to reimplement the decoding... | ||||||||||||||||||||||||||||
| 451 | 0 | ▶ | while(@$lines) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 452 | 0 | { my $line = shift @$lines; | |||||||||||||||||||||||||||
| 453 | 0 | ▶ | next unless $line =~ /\(.*?UID\s+(\d+)/i; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 454 | 0 | my $id = $+; | |||||||||||||||||||||||||||
| 455 | 0 | ▶ | my $info = $msgs{$id} or next; # wrong uid | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||
| 457 | 0 | ▶ | if($line =~ s/^[^(]* \( \s* //x ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 458 | 0 | ▶ | { while($line =~ s/(\S+) # field | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 459 | \s+ | ||||||||||||||||||||||||||||
| 460 | (?: # value | ||||||||||||||||||||||||||||
| 461 | \" ( (?:\\.|[^"])+ ) \" | ||||||||||||||||||||||||||||
| 462 | | \( ( (?:\\.|[^)])+ ) \) | ||||||||||||||||||||||||||||
| 463 | | (\w+) | ||||||||||||||||||||||||||||
| 464 | )//xi) | ||||||||||||||||||||||||||||
| 465 | 0 | { $info->{uc $1} = $+; | |||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||
| 468 | 0 | ▶ | if( $line =~ m/^\s* (\S+) [ ]*$/x ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 469 | { # Text block expected | ||||||||||||||||||||||||||||
| 470 | 0 | my ($key, $value) = (uc $1, ''); | |||||||||||||||||||||||||||
| 471 | 0 | ▶ | while(@$lines) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 472 | 0 | { my $extra = shift @$lines; | |||||||||||||||||||||||||||
| 473 | 0 | $extra =~ s/\r\n$/\n/; | |||||||||||||||||||||||||||
| 474 | 0 | ▶ | last if $extra eq ")\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 475 | 0 | $value .= $extra; | |||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||
| 477 | 0 | $info->{$key} = $value; | |||||||||||||||||||||||||||
| 478 | } | ||||||||||||||||||||||||||||
| 479 | } | ||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||
| 483 | 0 | values %msgs; | |||||||||||||||||||||||||||
| 484 | } | ||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||
| 487 | sub appendMessage($$) | ||||||||||||||||||||||||||||
| 488 | 0 | ▶ | { my ($self, $message, $foldername, $date) = @_; | ||||||||||||||||||||||||||
|
Subroutine
appendMessage: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 489 | 0 | ▶ | my $imap = $self->imapClient or return (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||
| 491 | 0 | ▶ | $date = $imap->Rfc_822($date) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$date and not $date =~ /\D/
MC/DC0%0/2
$date and not $date =~ /\D/
$date
not $date =~ /\D/
Truth table0%0/3
A and not(B)
A= $dateB= not $date =~ /\D/
| |||||||||||||||||||||||||||||
| 492 | if $date && $date !~ m/\D/; | ||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||
| 494 | 0 | $imap->append_string | |||||||||||||||||||||||||||
| 495 | ( $foldername, $message->string | ||||||||||||||||||||||||||||
| 496 | , $self->labelsToFlags($message->labels) | ||||||||||||||||||||||||||||
| 497 | , $date | ||||||||||||||||||||||||||||
| 498 | ); | ||||||||||||||||||||||||||||
| 499 | } | ||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||
| 502 | sub destroyDeleted($) | ||||||||||||||||||||||||||||
| 503 | 0 | ▶ | { my ($self, $folder) = @_; | ||||||||||||||||||||||||||
|
Subroutine
destroyDeleted: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 504 | 0 | ▶ | defined $folder or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||
| 506 | 0 | ▶ | my $imap = shift->imapClient or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 507 | 0 | $imap->expunge($folder); | |||||||||||||||||||||||||||
| 508 | } | ||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||
| 511 | sub createFolder($) | ||||||||||||||||||||||||||||
| 512 | 0 | ▶ | { my $imap = shift->imapClient or return (); | ||||||||||||||||||||||||||
|
Subroutine
createFolder: not called CC=2 SCAR=17.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 513 | 0 | $imap->create(shift); | |||||||||||||||||||||||||||
| 514 | } | ||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||
| 517 | sub deleteFolder($) | ||||||||||||||||||||||||||||
| 518 | 0 | ▶ | { my $imap = shift->imapClient or return (); | ||||||||||||||||||||||||||
|
Subroutine
deleteFolder: not called CC=2 SCAR=17.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 519 | 0 | $imap->delete(shift); | |||||||||||||||||||||||||||
| 520 | } | ||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||
| 522 | #------------------------------------------ | ||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||
| 524 | sub DESTROY() | ||||||||||||||||||||||||||||
| 525 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 526 | 0 | my $imap = $self->imapClient; | |||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||
| 528 | 0 | $self->SUPER::DESTROY; | |||||||||||||||||||||||||||
| 529 | 0 | ▶ | $imap->logout if defined $imap; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 530 | } | ||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||
| 532 | #------------------------------------------ | ||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||
| 534 | # Tied filehandle translates IMAP's debug system into Mail::Reporter | ||||||||||||||||||||||||||||
| 535 | # calls. | ||||||||||||||||||||||||||||
| 536 | sub Mail::IMAPClient::Debug::TIEHANDLE($) | ||||||||||||||||||||||||||||
| 537 | 0 | ▶ | { my ($class, $logger) = @_; | ||||||||||||||||||||||||||
|
Subroutine
TIEHANDLE: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 538 | 0 | bless \$logger, $class; | |||||||||||||||||||||||||||
| 539 | } | ||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||
| 541 | sub Mail::IMAPClient::Debug::PRINT(@) | ||||||||||||||||||||||||||||
| 542 | 0 | ▶ | { my $logger = ${ (shift) }; | ||||||||||||||||||||||||||
|
Subroutine
PRINT: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 543 | 0 | $logger->log(DEBUG => @_); | |||||||||||||||||||||||||||
| 544 | } | ||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||
| 546 | 3 | 1; | |||||||||||||||||||||||||||