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