| 1 | # IMAP::Admin - perl module for helping ease the administration of imap servers | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | package IMAP::Admin; | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use IO::Select; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use IO::Socket; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | #use IO::Socket::INET; | ||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Cwd; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 1 | $VERSION = '1.6.8'; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 17 | 1 | my $class = shift; | |||||||||||||||||||||||||||
| 18 | 1 | my $self = {}; | |||||||||||||||||||||||||||
| 19 | 1 | my @defaults = ( | |||||||||||||||||||||||||||
| 20 | 'Port' => 143, | ||||||||||||||||||||||||||||
| 21 | 'Separator' => '.', | ||||||||||||||||||||||||||||
| 22 | 'CRAM' => 0, | ||||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 1 | bless $self, $class; | |||||||||||||||||||||||||||
| 26 | 1 | ▶ | if ((scalar(@_) % 2) != 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 0 | croak "$class called with incorrect number of arguments"; | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | 1 | unshift @_, @defaults; | |||||||||||||||||||||||||||
| 30 | 1 | %{$self} = @_; # set up parameters; | |||||||||||||||||||||||||||
| 31 | 1 | $self->{'CLASS'} = $class; | |||||||||||||||||||||||||||
| 32 | 1 | $self->_initialize; | |||||||||||||||||||||||||||
| 33 | 0 | return $self; | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 1 | ▶ | sub _initialize { | ||||||||||||||||||||||||||
|
Subroutine
_initialize: called CC=21 SCAR=60.3
| |||||||||||||||||||||||||||||
| 37 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 1 | ▶ | if (!defined($self->{'Server'})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 1 | croak "$self->{'CLASS'} not initialized properly : Server parameter missing"; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | 0 | ▶ | if (!defined($self->{'Login'})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | 0 | croak "$self->{'CLASS'} not initialized properly : Login parameter missing"; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | 0 | ▶ | if (!defined($self->{'Password'})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 0 | croak "$self->{'CLASS'} not initialized properly : Password parameter missing"; | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | 0 | ▶ | if ($self->{'CRAM'} != 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 0 | my $cram_try = "use Digest::HMAC; use Digest::MD5; use MIME::Base64;"; | |||||||||||||||||||||||||||
| 50 | 0 | eval $cram_try; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | 0 | ▶ | if (defined($self->{'SSL'})) { # attempt SSL connection instead | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | # construct array of ssl options | ||||||||||||||||||||||||||||
| 54 | 0 | my $cwd = cwd; | |||||||||||||||||||||||||||
| 55 | 0 | my %ssl_defaults = ( | |||||||||||||||||||||||||||
| 56 | 'SSL_use_cert' => 0, | ||||||||||||||||||||||||||||
| 57 | 'SSL_verify_mode' => 0x00, | ||||||||||||||||||||||||||||
| 58 | 'SSL_key_file' => $cwd."/certs/client-key.pem", | ||||||||||||||||||||||||||||
| 59 | 'SSL_cert_file' => $cwd."/certs/client-cert.pem", | ||||||||||||||||||||||||||||
| 60 | 'SSL_ca_path' => $cwd."/certs", | ||||||||||||||||||||||||||||
| 61 | 'SSL_ca_file' => $cwd."/certs/ca-cert.pem", | ||||||||||||||||||||||||||||
| 62 | ); | ||||||||||||||||||||||||||||
| 63 | 0 | my @ssl_options; | |||||||||||||||||||||||||||
| 64 | my $ssl_key; | ||||||||||||||||||||||||||||
| 65 | 0 | my $key; | |||||||||||||||||||||||||||
| 66 | 0 | foreach $ssl_key (keys(%ssl_defaults)) { | |||||||||||||||||||||||||||
| 67 | 0 | ▶ | if (!defined($self->{$ssl_key})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | 0 | $self->{$ssl_key} = $ssl_defaults{$ssl_key}; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | 0 | foreach $ssl_key (keys(%{$self})) { | |||||||||||||||||||||||||||
| 72 | 0 | ▶ | if ($ssl_key =~ /^SSL_/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | 0 | push @ssl_options, $ssl_key, $self->{$ssl_key}; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | 0 | my $SSL_try = "use IO::Socket::SSL"; | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 0 | eval $SSL_try; | |||||||||||||||||||||||||||
| 79 | # $IO::Socket::SSL::DEBUG = 1; | ||||||||||||||||||||||||||||
| 80 | 0 | ▶ | if (!eval { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | $self->{'Socket'} = | ||||||||||||||||||||||||||||
| 82 | IO::Socket::SSL->new(PeerAddr => $self->{'Server'}, | ||||||||||||||||||||||||||||
| 83 | 0 | PeerPort => $self->{'Port'}, | |||||||||||||||||||||||||||
| 84 | Proto => 'tcp', | ||||||||||||||||||||||||||||
| 85 | Reuse => 1, | ||||||||||||||||||||||||||||
| 86 | Timeout => 5, | ||||||||||||||||||||||||||||
| 87 | @ssl_options); }) { | ||||||||||||||||||||||||||||
| 88 | $self->_error("initialize", "couldn't establish SSL connection to", | ||||||||||||||||||||||||||||
| 89 | 0 | $self->{'Server'}, "[$!]"); | |||||||||||||||||||||||||||
| 90 | 0 | delete $self->{'Socket'}; | |||||||||||||||||||||||||||
| 91 | 0 | return; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | } else { | ||||||||||||||||||||||||||||
| 94 | 0 | ▶ | if ($self->{'Server'} =~ /^\//) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | 0 | ▶ | if (!eval { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | $self->{'Socket'} = | ||||||||||||||||||||||||||||
| 97 | 0 | IO::Socket::UNIX->new(Peer => $self->{'Server'}); }) | |||||||||||||||||||||||||||
| 98 | { | ||||||||||||||||||||||||||||
| 99 | 0 | delete $self->{'Socket'}; | |||||||||||||||||||||||||||
| 100 | $self->_error("initialize", "couldn't establish connection to", | ||||||||||||||||||||||||||||
| 101 | 0 | $self->{'Server'}); | |||||||||||||||||||||||||||
| 102 | 0 | return; | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | } else { | ||||||||||||||||||||||||||||
| 105 | 0 | ▶ | if (!eval { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | $self->{'Socket'} = | ||||||||||||||||||||||||||||
| 107 | IO::Socket::INET->new(PeerAddr => $self->{'Server'}, | ||||||||||||||||||||||||||||
| 108 | 0 | PeerPort => $self->{'Port'}, | |||||||||||||||||||||||||||
| 109 | Proto => 'tcp', | ||||||||||||||||||||||||||||
| 110 | Reuse => 1, | ||||||||||||||||||||||||||||
| 111 | Timeout => 5); }) | ||||||||||||||||||||||||||||
| 112 | { | ||||||||||||||||||||||||||||
| 113 | 0 | delete $self->{'Socket'}; | |||||||||||||||||||||||||||
| 114 | $self->_error("initialize", "couldn't establish connection to", | ||||||||||||||||||||||||||||
| 115 | 0 | $self->{'Server'}); | |||||||||||||||||||||||||||
| 116 | 0 | return; | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | 0 | my $fh = $self->{'Socket'}; | |||||||||||||||||||||||||||
| 121 | 0 | my $try = $self->_read; # get Banner | |||||||||||||||||||||||||||
| 122 | 0 | ▶ | if ($try !~ /\* OK/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | 0 | $self->close; | |||||||||||||||||||||||||||
| 124 | 0 | $self->_error("initialize", "bad response from", $self->{'Server'}, | |||||||||||||||||||||||||||
| 125 | "[", $try, "]"); | ||||||||||||||||||||||||||||
| 126 | 0 | return; | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | # this section was changed to accomodate motd's | ||||||||||||||||||||||||||||
| 129 | 0 | print $fh "try CAPABILITY\n"; | |||||||||||||||||||||||||||
| 130 | 0 | $try = $self->_read; | |||||||||||||||||||||||||||
| 131 | 0 | ▶ | while ($try !~ /^\* CAPABILITY/) { # we have a potential lockup, should alarm this | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 132 | 0 | $try = $self->_read; | |||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | 0 | $self->{'Capability'} = $try; | |||||||||||||||||||||||||||
| 135 | 0 | $try = $self->_read; | |||||||||||||||||||||||||||
| 136 | 0 | ▶ | if ($try !~ /^try OK/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 137 | 0 | $self->close; | |||||||||||||||||||||||||||
| 138 | 0 | $self->_error("initialize", "Couldn't do a capabilites check [", | |||||||||||||||||||||||||||
| 139 | $try, "]"); | ||||||||||||||||||||||||||||
| 140 | 0 | return; | |||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | 0 | ▶ | if ($self->{'CRAM'} > 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 143 | 0 | ▶ | if ($self->{'Capability'} =~ /CRAM-MD5/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 144 | 0 | _do_cram_login($self); | |||||||||||||||||||||||||||
| 145 | } else { | ||||||||||||||||||||||||||||
| 146 | 0 | ▶ | if ($self->{'CRAM'} > 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 147 | 0 | print $fh qq{try LOGIN "$self->{'Login'}" "$self->{'Password'}"\n}; | |||||||||||||||||||||||||||
| 148 | } else { | ||||||||||||||||||||||||||||
| 149 | 0 | $self->close; | |||||||||||||||||||||||||||
| 150 | 0 | $self->_error("initialize","CRAM not reported in Capability check and fallback to PLAIN not selected", $self->{'Server'}, "[", $self->{'Capability'}, "]"); | |||||||||||||||||||||||||||
| 151 | 0 | return; | |||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||
| 154 | } else { | ||||||||||||||||||||||||||||
| 155 | 0 | print $fh qq{try LOGIN "$self->{'Login'}" "$self->{'Password'}"\n}; | |||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||
| 157 | 0 | $try = $self->_read; | |||||||||||||||||||||||||||
| 158 | 0 | ▶ | if ($try !~ /^try OK/) { # should tr this response | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 159 | 0 | $self->close; | |||||||||||||||||||||||||||
| 160 | 0 | $self->_error("initialize", $try); | |||||||||||||||||||||||||||
| 161 | 0 | return; | |||||||||||||||||||||||||||
| 162 | } else { | ||||||||||||||||||||||||||||
| 163 | 0 | $self->{'Error'} = "No Errors"; | |||||||||||||||||||||||||||
| 164 | 0 | return; | |||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | # fall thru, can it be hit ? | ||||||||||||||||||||||||||||
| 167 | 0 | $self->{'Error'} = "No Errors"; | |||||||||||||||||||||||||||
| 168 | 0 | return; | |||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | # this routine uses evals to prevent errors regarding missing modules | ||||||||||||||||||||||||||||
| 172 | 0 | ▶ | sub _do_cram_login { | ||||||||||||||||||||||||||
|
Subroutine
_do_cram_login: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 173 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 174 | 0 | my $fh = $self->{'Socket'}; | |||||||||||||||||||||||||||
| 175 | 0 | my $ans; | |||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 0 | print $fh "try AUTHENTICATE CRAM-MD5\n"; | |||||||||||||||||||||||||||
| 178 | 0 | my $try = $self->_read; # gets back the postal string | |||||||||||||||||||||||||||
| 179 | 0 | ($ans) = (split(' ', $try, 2))[1]; | |||||||||||||||||||||||||||
| 180 | 0 | my $cram_eval = " | |||||||||||||||||||||||||||
| 181 | my \$hmac = Digest::HMAC->new(\$self->{'Password'}, 'Digest::MD5'); | ||||||||||||||||||||||||||||
| 182 | \$hmac->add(decode_base64(\$ans)); | ||||||||||||||||||||||||||||
| 183 | \$ans = encode_base64(\$self->{'Login'}.' '.\$hmac->hexdigest, ''); | ||||||||||||||||||||||||||||
| 184 | "; | ||||||||||||||||||||||||||||
| 185 | 0 | eval $cram_eval; | |||||||||||||||||||||||||||
| 186 | 0 | print $fh "$ans\n"; | |||||||||||||||||||||||||||
| 187 | 0 | return; | |||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | 0 | ▶ | sub _error { | ||||||||||||||||||||||||||
|
Subroutine
_error: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 191 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 192 | 0 | my $func = shift; | |||||||||||||||||||||||||||
| 193 | 0 | my @error = @_; | |||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | 0 | $self->{'Error'} = join(" ",$self->{'CLASS'}, "[", $func, "]:", @error); | |||||||||||||||||||||||||||
| 196 | 0 | return; | |||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | 0 | ▶ | sub error { | ||||||||||||||||||||||||||
|
Subroutine
error: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 200 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 201 | 0 | return $self->{'Error'}; | |||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | 0 | ▶ | sub _read { | ||||||||||||||||||||||||||
|
Subroutine
_read: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||
| 205 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 206 | 0 | my $buffer = ""; | |||||||||||||||||||||||||||
| 207 | 0 | my $char = ""; | |||||||||||||||||||||||||||
| 208 | 0 | my $bytes = 1; | |||||||||||||||||||||||||||
| 209 | 0 | ▶ | while ($bytes == 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 210 | 0 | $bytes = sysread $self->{'Socket'}, $char, 1; | |||||||||||||||||||||||||||
| 211 | 0 | ▶ | if ($bytes == 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 212 | 0 | ▶ | if (length ($buffer) != 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 213 | 0 | return $buffer; | |||||||||||||||||||||||||||
| 214 | } else { | ||||||||||||||||||||||||||||
| 215 | 0 | return; | |||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||
| 217 | } else { | ||||||||||||||||||||||||||||
| 218 | 0 | ▶ | if (($char eq "\n") or ($char eq "\r")) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$char eq "\n" or $char eq "\r"
MC/DC0%0/2
$char eq "\n" or $char eq "\r"
$char eq "\n"
$char eq "\r"
Truth table0%0/3
A or B
A= $char eq "\n"B= $char eq "\r"
| |||||||||||||||||||||||||||||
| 219 | 0 | ▶ | if (length($buffer) == 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 220 | # cr or nl left over, just eat it | ||||||||||||||||||||||||||||
| 221 | } else { | ||||||||||||||||||||||||||||
| 222 | 0 | return $buffer; | |||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||
| 224 | } else { | ||||||||||||||||||||||||||||
| 225 | # print "got char [$char]\n"; | ||||||||||||||||||||||||||||
| 226 | 0 | $buffer .= $char; | |||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | 0 | ▶ | sub close { | ||||||||||||||||||||||||||
|
Subroutine
close: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 233 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | 0 | ▶ | if (!defined($self->{'Socket'})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 236 | 0 | return 0; | |||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||
| 238 | 0 | my $fh = $self->{'Socket'}; | |||||||||||||||||||||||||||
| 239 | 0 | print $fh "try logout\n"; | |||||||||||||||||||||||||||
| 240 | 0 | my $try = $self->_read; | |||||||||||||||||||||||||||
| 241 | 0 | close($self->{'Socket'}); | |||||||||||||||||||||||||||
| 242 | 0 | delete $self->{'Socket'}; | |||||||||||||||||||||||||||
| 243 | 0 | return 0; | |||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | 0 | ▶ | sub create { | ||||||||||||||||||||||||||
|
Subroutine
create: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 247 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | 0 | ▶ | if (!defined($self->{'Socket'})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 250 | 0 | return 1; | |||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||
| 252 | 0 | ▶ | if ((scalar(@_) != 1) && (scalar(@_) != 2)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
scalar @_ != 1 and scalar @_ != 2
MC/DC0%0/2
scalar @_ != 1 and scalar @_ != 2
scalar @_ != 1
scalar @_ != 2
Truth table0%0/3
A and B
A= scalar @_ != 1B= scalar @_ != 2
| |||||||||||||||||||||||||||||
| 253 | 0 | $self->_error("create", "incorrect number of arguments"); | |||||||||||||||||||||||||||
| 254 | 0 | return 1; | |||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||
| 256 | 0 | my $mailbox = shift; | |||||||||||||||||||||||||||
| 257 | 0 | my $fh = $self->{'Socket'}; | |||||||||||||||||||||||||||
| 258 | 0 | ▶ | if (scalar(@_) == 1) { # a partition exists | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 259 | 0 | print $fh qq{try CREATE "$mailbox" $_[0]\n}; | |||||||||||||||||||||||||||
| 260 | } else { | ||||||||||||||||||||||||||||
| 261 | 0 | print $fh qq{try CREATE "$mailbox"\n}; | |||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||
| 263 | 0 | my $try = $self->_read; | |||||||||||||||||||||||||||
| 264 | 0 | ▶ | if ($try =~ /^try OK/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 265 | 0 | $self->{'Error'} = 'No Errors'; | |||||||||||||||||||||||||||
| 266 | 0 | return 0; | |||||||||||||||||||||||||||
| 267 | } else { | ||||||||||||||||||||||||||||
| 268 | 0 | $self->_error("create", "couldn't create", $mailbox, ":", $try); | |||||||||||||||||||||||||||
| 269 | 0 | return 1; | |||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||
| 273 | 0 | ▶ | sub rename { | ||||||||||||||||||||||||||
|
Subroutine
rename: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 274 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||
| 276 | 0 | ▶ | if (!defined($self->{'Socket'})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 277 | 0 | return 1; | |||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||
| 279 | 0 | ▶ | if ((scalar(@_) != 2) && (scalar(@_) != 3)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
scalar @_ != 2 and scalar @_ != 3
MC/DC0%0/2
scalar @_ != 2 and scalar @_ != 3
scalar @_ != 2
scalar @_ != 3
Truth table0%0/3
A and B
A= scalar @_ != 2B= scalar @_ != 3
| |||||||||||||||||||||||||||||
| 280 | 0 | $self->_error("rename", "incorrect number of arguments"); | |||||||||||||||||||||||||||
| 281 | 0 | return 1; | |||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||
| 283 | 0 | my $old_name = shift; | |||||||||||||||||||||||||||
| 284 | 0 | my $new_name = shift; | |||||||||||||||||||||||||||
| 285 | 0 | my $partition = shift; | |||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||
| 287 | 0 | my $fh = $self->{'Socket'}; | |||||||||||||||||||||||||||
| 288 | 0 | ▶ | if (defined $partition) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 289 | 0 | print $fh qq{try RENAME "$old_name" "$new_name" $partition\n}; | |||||||||||||||||||||||||||
| 290 | } else { | ||||||||||||||||||||||||||||
| 291 | 0 | print $fh qq{try RENAME "$old_name" "$new_name"\n}; | |||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||
| 293 | 0 | my $try = $self->_read; | |||||||||||||||||||||||||||
| 294 | 0 | ▶ | if (($try =~ /^try OK/) || ($try =~ /^\* OK/)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$try =~ /^try OK/ or $try =~ /^\* OK/
MC/DC0%0/2
$try =~ /^try OK/ or $try =~ /^\* OK/
$try =~ /^try OK/
$try =~ /^\* OK/
Truth table0%0/3
A or B
A= $try =~ /^try OK/B= $try =~ /^\* OK/
| |||||||||||||||||||||||||||||
| 295 | 0 | $self->{'Error'} = 'No Errors'; | |||||||||||||||||||||||||||
| 296 | 0 | return 0; | |||||||||||||||||||||||||||
| 297 | } else { | ||||||||||||||||||||||||||||
| 298 | 0 | $self->_error("rename", "couldn't rename", $old_name, "to", $new_name, | |||||||||||||||||||||||||||
| 299 | ":", $try); | ||||||||||||||||||||||||||||
| 300 | 0 | return 1; | |||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||
| 304 | 0 | ▶ | sub delete { | ||||||||||||||||||||||||||
|
Subroutine
delete: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 305 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||
| 307 | 0 | ▶ | if (!defined($self->{'Socket'})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 308 | 0 | return 1; | |||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||
| 310 | 0 | ▶ | if (scalar(@_) != 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 311 | 0 | $self->_error("delete", "incorrect number of arguments"); | |||||||||||||||||||||||||||
| 312 | 0 | return 1; | |||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||
| 314 | 0 | my $mailbox = shift; | |||||||||||||||||||||||||||
| 315 | 0 | my $fh = $self->{'Socket'}; | |||||||||||||||||||||||||||
| 316 | 0 | print $fh qq{try DELETE "$mailbox"\n}; | |||||||||||||||||||||||||||
| 317 | 0 | my $try = $self->_read; | |||||||||||||||||||||||||||
| 318 | 0 | ▶ | if ($try =~ /^try OK/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 319 | 0 | $self->{'Error'} = 'No Errors'; | |||||||||||||||||||||||||||
| 320 | 0 | return 0; | |||||||||||||||||||||||||||
| 321 | } else { | ||||||||||||||||||||||||||||
| 322 | 0 | $self->_error("delete", "couldn't delete", $mailbox, ":", $try); | |||||||||||||||||||||||||||
| 323 | 0 | return 1; | |||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||
| 327 | 0 | ▶ | sub h_delete { | ||||||||||||||||||||||||||
|
Subroutine
h_delete: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 328 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||
| 330 | 0 | ▶ | if (!defined($self->{'Socket'})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 331 | 0 | return 1; | |||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||
| 333 | 0 | ▶ | if (scalar(@_) != 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 334 | 0 | $self->_error("h_delete", "incorrect number of arguments"); | |||||||||||||||||||||||||||
| 335 | 0 | return 1; | |||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||
| 337 | 0 | my $mailbox = shift; | |||||||||||||||||||||||||||
| 338 | 0 | my $fh = $self->{'Socket'}; | |||||||||||||||||||||||||||
| 339 | # first get a list of all sub boxes then nuke them, accumulate errors | ||||||||||||||||||||||||||||
| 340 | # then do something intelligent with them (hmmmmm) | ||||||||||||||||||||||||||||
| 341 | 0 | my $box = join($self->{'Separator'}, $mailbox, "*"); | |||||||||||||||||||||||||||
| 342 | 0 | my @sub_boxes = $self->list($box); | |||||||||||||||||||||||||||
| 343 | 0 | push @sub_boxes, $mailbox; | |||||||||||||||||||||||||||
| 344 | # uncomment following line if you are sanity checking h_delete | ||||||||||||||||||||||||||||
| 345 | # print "h_delete: got this list of sub boxes [@sub_boxes]\n"; | ||||||||||||||||||||||||||||
| 346 | 0 | foreach $box (@sub_boxes) { | |||||||||||||||||||||||||||
| 347 | 0 | print $fh qq{try DELETE "$box"\n}; | |||||||||||||||||||||||||||
| 348 | 0 | my $try = $self->_read; | |||||||||||||||||||||||||||
| 349 | 0 | ▶ | if ($try =~ /^try OK/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 350 | 0 | $self->{'Error'} = 'No Errors'; | |||||||||||||||||||||||||||
| 351 | } else { | ||||||||||||||||||||||||||||
| 352 | 0 | $self->_error("h_delete", "couldn't delete", | |||||||||||||||||||||||||||
| 353 | $mailbox, ":", $try); | ||||||||||||||||||||||||||||
| 354 | 0 | return 1; # or just return on the first encountered error ? | |||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||
| 357 | 0 | return 0; | |||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||
| 360 | 0 | ▶ | sub get_quotaroot { # returns an array or undef | ||||||||||||||||||||||||||
|
Subroutine
get_quotaroot: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 361 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 362 | 0 | my (@quota, @info); | |||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||
| 364 | 0 | ▶ | if (!defined($self->{'Socket'})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 365 | 0 | return 1; | |||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||
| 367 | 0 | ▶ | if (!($self->{'Capability'} =~ /QUOTA/)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 368 | 0 | $self->_error("get_quotaroot", "QUOTA not listed in server's capabilities"); | |||||||||||||||||||||||||||
| 369 | 0 | return 1; | |||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||
| 371 | 0 | ▶ | if (scalar(@_) != 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 372 | 0 | $self->_error("get_quotaroot", "incorrect number of arguments"); | |||||||||||||||||||||||||||
| 373 | 0 | return 1; | |||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||
| 375 | 0 | my $mailbox = shift; | |||||||||||||||||||||||||||
| 376 | 0 | my $fh = $self->{'Socket'}; | |||||||||||||||||||||||||||
| 377 | 0 | print $fh qq{try GETQUOTAROOT "$mailbox"\n}; | |||||||||||||||||||||||||||
| 378 | 0 | my $try = $self->_read; | |||||||||||||||||||||||||||
| 379 | 0 | ▶ | while ($try =~ /^\* QUOTA/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 380 | 0 | ▶ | if ($try !~ /QUOTAROOT/) { # some imap servers give this extra line | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 381 | 0 | @info = ($try =~ /QUOTA\s(.*?)\s\(STORAGE\s(\d+)\s(\d+)/); | |||||||||||||||||||||||||||
| 382 | 0 | push @quota, @info; | |||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||
| 384 | 0 | $try = $self->_read; | |||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||
| 386 | 0 | ▶ | if ($try =~ /^try OK/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 387 | 0 | return @quota; | |||||||||||||||||||||||||||
| 388 | } else { | ||||||||||||||||||||||||||||
| 389 | 0 | $self->_error("get_quotaroot", "couldn't get quota for", $mailbox, ":", $try); | |||||||||||||||||||||||||||
| 390 | 0 | return; | |||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||
| 394 | 0 | ▶ | sub get_quota { # returns an array or undef | ||||||||||||||||||||||||||
|
Subroutine
get_quota: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 395 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 396 | 0 | my (@quota, @info); | |||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||
| 398 | 0 | ▶ | if (!defined($self->{'Socket'})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 399 | 0 | return; | |||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||
| 401 | 0 | ▶ | if (!($self->{'Capability'} =~ /QUOTA/)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 402 | 0 | $self->_error("get_quota", | |||||||||||||||||||||||||||
| 403 | "QUOTA not listed in server's capabilities"); | ||||||||||||||||||||||||||||
| 404 | 0 | return; | |||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||
| 406 | 0 | ▶ | if (scalar(@_) != 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 407 | 0 | $self->_error("get_quota", "incorrect number of arguments"); | |||||||||||||||||||||||||||
| 408 | 0 | return; | |||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||
| 410 | 0 | my $mailbox = shift; | |||||||||||||||||||||||||||
| 411 | 0 | my $fh = $self->{'Socket'}; | |||||||||||||||||||||||||||
| 412 | 0 | print $fh qq{try GETQUOTA "$mailbox"\n}; | |||||||||||||||||||||||||||
| 413 | 0 | my $try = $self->_read; | |||||||||||||||||||||||||||
| 414 | 0 | ▶ | while ($try =~ /^\* QUOTA/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 415 | 0 | @info = ($try =~ /QUOTA\s(.*?)\s\(STORAGE\s(\d+)\s(\d+)/); | |||||||||||||||||||||||||||
| 416 | 0 | push @quota, @info; | |||||||||||||||||||||||||||
| 417 | 0 | $try = $self->_read; | |||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||
| 419 | 0 | ▶ | if ($try =~ /^try OK/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 420 | 0 | return @quota; | |||||||||||||||||||||||||||
| 421 | } else { | ||||||||||||||||||||||||||||
| 422 | 0 | $self->_error("get_quota", "couldn't get quota for", $mailbox, ":", $try); | |||||||||||||||||||||||||||
| 423 | 0 | return; | |||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||
| 427 | 0 | ▶ | sub set_quota { | ||||||||||||||||||||||||||
|
Subroutine
set_quota: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 428 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||
| 430 | 0 | ▶ | if (!defined($self->{'Socket'})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 431 | 0 | return 1; | |||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||
| 433 | 0 | ▶ | if (!($self->{'Capability'} =~ /QUOTA/)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 434 | 0 | $self->_error("set_quota", "QUOTA not listed in server's capabilities"); | |||||||||||||||||||||||||||
| 435 | 0 | return 1; | |||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||
| 437 | 0 | ▶ | if (scalar(@_) != 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 438 | 0 | $self->_error("set_quota", "incorrect number of arguments"); | |||||||||||||||||||||||||||
| 439 | 0 | return 1; | |||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||
| 441 | 0 | my $mailbox = shift; | |||||||||||||||||||||||||||
| 442 | 0 | my $quota = shift; | |||||||||||||||||||||||||||
| 443 | 0 | my $fh = $self->{'Socket'}; | |||||||||||||||||||||||||||
| 444 | 0 | ▶ | if ($quota eq "none") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 445 | 0 | print $fh qq{try SETQUOTA "$mailbox" ()\n}; | |||||||||||||||||||||||||||
| 446 | } else { | ||||||||||||||||||||||||||||
| 447 | 0 | print $fh qq{try SETQUOTA "$mailbox" (STORAGE $quota)\n}; | |||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||
| 449 | 0 | my $try = $self->_read; | |||||||||||||||||||||||||||
| 450 | 0 | ▶ | if ($try =~ /^try OK/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 451 | 0 | $self->{'Error'} = "No Errors"; | |||||||||||||||||||||||||||
| 452 | 0 | return 0; | |||||||||||||||||||||||||||
| 453 | } else { | ||||||||||||||||||||||||||||
| 454 | 0 | $self->_error("set_quota", "couldn't set quota for", $mailbox, ":", $try); | |||||||||||||||||||||||||||
| 455 | 0 | return 1; | |||||||||||||||||||||||||||
| 456 | } | ||||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||
| 459 | 0 | ▶ | sub subscribe { | ||||||||||||||||||||||||||
|
Subroutine
subscribe: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 460 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||
| 462 | 0 | ▶ | if (!defined($self->{'Socket'})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 463 | 0 | return 1; | |||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||
| 465 | 0 | ▶ | if (scalar(@_) != 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 466 | 0 | $self->_error("subscribe", "incorrect number of arguments"); | |||||||||||||||||||||||||||
| 467 | 0 | return 1; | |||||||||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||||||||
| 469 | 0 | my $mailbox = shift; | |||||||||||||||||||||||||||
| 470 | 0 | my $fh = $self->{'Socket'}; | |||||||||||||||||||||||||||
| 471 | 0 | print $fh qq{try SUBSCRIBE "$mailbox"\n}; | |||||||||||||||||||||||||||
| 472 | 0 | my $try = $self->_read; | |||||||||||||||||||||||||||
| 473 | 0 | ▶ | if ($try !~ /^try OK/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 474 | 0 | $self->_error("subscribe", "couldn't suscribe ", $mailbox, ":", | |||||||||||||||||||||||||||
| 475 | $try); | ||||||||||||||||||||||||||||
| 476 | 0 | return 1; | |||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||
| 478 | 0 | $self->{'Error'} = 'No Errors'; | |||||||||||||||||||||||||||
| 479 | 0 | return 0; | |||||||||||||||||||||||||||
| 480 | } | ||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||
| 482 | 0 | ▶ | sub unsubscribe { | ||||||||||||||||||||||||||
|
Subroutine
unsubscribe: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 483 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||
| 485 | 0 | ▶ | if (!defined($self->{'Socket'})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 486 | 0 | return 1; | |||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||
| 488 | 0 | ▶ | if (scalar(@_) != 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 489 | 0 | $self->_error("unsubscribe", "incorrect number of arguments"); | |||||||||||||||||||||||||||
| 490 | 0 | return 1; | |||||||||||||||||||||||||||
| 491 | } | ||||||||||||||||||||||||||||
| 492 | 0 | my $mailbox = shift; | |||||||||||||||||||||||||||
| 493 | 0 | my $fh = $self->{'Socket'}; | |||||||||||||||||||||||||||
| 494 | 0 | print $fh qq{try UNSUBSCRIBE "$mailbox"\n}; | |||||||||||||||||||||||||||
| 495 | 0 | my $try = $self->_read; | |||||||||||||||||||||||||||
| 496 | 0 | ▶ | if ($try !~ /^try OK/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 497 | 0 | $self->_error("unsubscribe", "couldn't unsuscribe ", $mailbox, ":", | |||||||||||||||||||||||||||
| 498 | $try); | ||||||||||||||||||||||||||||
| 499 | 0 | return 1; | |||||||||||||||||||||||||||
| 500 | } | ||||||||||||||||||||||||||||
| 501 | 0 | $self->{'Error'} = 'No Errors'; | |||||||||||||||||||||||||||
| 502 | 0 | return 0; | |||||||||||||||||||||||||||
| 503 | } | ||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||
| 505 | 0 | ▶ | sub select { # returns an array or undef | ||||||||||||||||||||||||||
|
Subroutine
select: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 506 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 507 | 0 | my @info; | |||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||
| 509 | 0 | ▶ | if (!defined($self->{'Socket'})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 510 | 0 | return 1; | |||||||||||||||||||||||||||
| 511 | } | ||||||||||||||||||||||||||||
| 512 | 0 | ▶ | if (scalar(@_) != 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 513 | 0 | $self->_error("select", "incorrect number of arguments"); | |||||||||||||||||||||||||||
| 514 | 0 | return; | |||||||||||||||||||||||||||
| 515 | } | ||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||
| 517 | 0 | my $mailbox = shift; | |||||||||||||||||||||||||||
| 518 | 0 | my $fh = $self->{'Socket'}; | |||||||||||||||||||||||||||
| 519 | 0 | print $fh qq{try SELECT "$mailbox"\n}; | |||||||||||||||||||||||||||
| 520 | 0 | my $try = $self->_read; | |||||||||||||||||||||||||||
| 521 | 0 | ▶ | while ($try =~ /^\* (.*)/) { # danger danger (could lock up needs timeout) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 522 | 0 | push @info, $1; | |||||||||||||||||||||||||||
| 523 | 0 | $try = $self->_read; | |||||||||||||||||||||||||||
| 524 | } | ||||||||||||||||||||||||||||
| 525 | 0 | ▶ | if ($try =~ /^try OK/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 526 | 0 | return @info; | |||||||||||||||||||||||||||
| 527 | } else { | ||||||||||||||||||||||||||||
| 528 | 0 | $self->_error("select", "couldn't select", $mailbox, ":", $try); | |||||||||||||||||||||||||||
| 529 | 0 | return; | |||||||||||||||||||||||||||
| 530 | } | ||||||||||||||||||||||||||||
| 531 | } | ||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||
| 533 | 0 | ▶ | sub expunge { # returns an array or undef | ||||||||||||||||||||||||||
|
Subroutine
expunge: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 534 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 535 | 0 | my @info; | |||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||
| 537 | 0 | ▶ | if (!defined($self->{'Socket'})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 538 | 0 | return 1; | |||||||||||||||||||||||||||
| 539 | } | ||||||||||||||||||||||||||||
| 540 | 0 | ▶ | if (scalar(@_) != 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 541 | 0 | $self->_error("expunge", "incorrect number of arguments"); | |||||||||||||||||||||||||||
| 542 | 0 | return; | |||||||||||||||||||||||||||
| 543 | } | ||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||
| 545 | 0 | my $mailbox = shift; | |||||||||||||||||||||||||||
| 546 | 0 | my $fh = $self->{'Socket'}; | |||||||||||||||||||||||||||
| 547 | 0 | print $fh qq{try EXPUNGE\n}; | |||||||||||||||||||||||||||
| 548 | 0 | my $try = $self->_read; | |||||||||||||||||||||||||||
| 549 | 0 | ▶ | while ($try =~ /^\* (.*)/) { # danger danger (could lock up needs timeout) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 550 | 0 | push @info, $1; | |||||||||||||||||||||||||||
| 551 | 0 | $try = $self->_read; | |||||||||||||||||||||||||||
| 552 | } | ||||||||||||||||||||||||||||
| 553 | 0 | ▶ | if ($try =~ /^try OK/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 554 | 0 | return @info; | |||||||||||||||||||||||||||
| 555 | } else { | ||||||||||||||||||||||||||||
| 556 | 0 | $self->_error("expunge", "couldn't expunge", $mailbox, ":", $try); | |||||||||||||||||||||||||||
| 557 | 0 | return; | |||||||||||||||||||||||||||
| 558 | } | ||||||||||||||||||||||||||||
| 559 | } | ||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||
| 561 | 0 | ▶ | sub get_acl { # returns an array or undef | ||||||||||||||||||||||||||
|
Subroutine
get_acl: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 562 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||
| 564 | 0 | ▶ | if (!defined($self->{'Socket'})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 565 | 0 | return; | |||||||||||||||||||||||||||
| 566 | } | ||||||||||||||||||||||||||||
| 567 | 0 | ▶ | if (!($self->{'Capability'} =~ /ACL/)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 568 | 0 | $self->_error("get_acl", "ACL not listed in server's capabilities"); | |||||||||||||||||||||||||||
| 569 | 0 | return; | |||||||||||||||||||||||||||
| 570 | } | ||||||||||||||||||||||||||||
| 571 | 0 | ▶ | if (scalar(@_) != 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 572 | 0 | $self->_error("get_acl", "incorrect number of arguments"); | |||||||||||||||||||||||||||
| 573 | 0 | return; | |||||||||||||||||||||||||||
| 574 | } | ||||||||||||||||||||||||||||
| 575 | 0 | my $mailbox = shift; | |||||||||||||||||||||||||||
| 576 | 0 | my $fh = $self->{'Socket'}; | |||||||||||||||||||||||||||
| 577 | 0 | print $fh qq{try GETACL "$mailbox"\n}; | |||||||||||||||||||||||||||
| 578 | 0 | delete $self->{'acl'}; | |||||||||||||||||||||||||||
| 579 | 0 | my $try = $self->_read; | |||||||||||||||||||||||||||
| 580 | 0 | ▶ | while ($try =~ /^\*\s+ACL\s+/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 581 | 0 | my $acls = ($try =~ /^\* ACL\s+(?:\".*?\"|\S*)\s+(.*)/)[0]; # separate out the acls | |||||||||||||||||||||||||||
| 582 | 0 | my @acls = ($acls =~ /(\".*?\"|\S+)\s*/g); # split up over ws, unless quoted | |||||||||||||||||||||||||||
| 583 | 0 | push @{$self->{'acl'}}, @acls; | |||||||||||||||||||||||||||
| 584 | 0 | $try = $self->_read; | |||||||||||||||||||||||||||
| 585 | } | ||||||||||||||||||||||||||||
| 586 | 0 | ▶ | if ($try =~ /^try OK/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 587 | 0 | return @{$self->{'acl'}}; | |||||||||||||||||||||||||||
| 588 | } else { | ||||||||||||||||||||||||||||
| 589 | 0 | $self->_error("get_acl", "couldn't get acl for", $mailbox, ":", $try); | |||||||||||||||||||||||||||
| 590 | 0 | return; | |||||||||||||||||||||||||||
| 591 | } | ||||||||||||||||||||||||||||
| 592 | } | ||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||
| 594 | 0 | ▶ | sub set_acl { | ||||||||||||||||||||||||||
|
Subroutine
set_acl: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 595 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 596 | 0 | my ($id, $acl); | |||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||
| 598 | 0 | ▶ | if (!defined($self->{'Socket'})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 599 | 0 | return 1; | |||||||||||||||||||||||||||
| 600 | } | ||||||||||||||||||||||||||||
| 601 | 0 | ▶ | if (!($self->{'Capability'} =~ /ACL/)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 602 | 0 | $self->_error("set_acl", "ACL not listed in server's capabilities"); | |||||||||||||||||||||||||||
| 603 | 0 | return 1; | |||||||||||||||||||||||||||
| 604 | } | ||||||||||||||||||||||||||||
| 605 | 0 | ▶ | if (scalar(@_) < 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 606 | 0 | $self->_error("set_acl", "too few arguments"); | |||||||||||||||||||||||||||
| 607 | 0 | return 1; | |||||||||||||||||||||||||||
| 608 | } | ||||||||||||||||||||||||||||
| 609 | 0 | ▶ | if ((scalar(@_) % 2) == 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 610 | 0 | $self->_error("set_acl", "incorrect number of arguments"); | |||||||||||||||||||||||||||
| 611 | 0 | return 1; | |||||||||||||||||||||||||||
| 612 | } | ||||||||||||||||||||||||||||
| 613 | 0 | my $mailbox = shift; | |||||||||||||||||||||||||||
| 614 | 0 | my $fh = $self->{'Socket'}; | |||||||||||||||||||||||||||
| 615 | 0 | ▶ | while(@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 616 | 0 | $id = shift; | |||||||||||||||||||||||||||
| 617 | 0 | $acl = shift; | |||||||||||||||||||||||||||
| 618 | 0 | print $fh qq{try SETACL "$mailbox" "$id" "$acl"\n}; | |||||||||||||||||||||||||||
| 619 | 0 | my $try = $self->_read; | |||||||||||||||||||||||||||
| 620 | 0 | ▶ | if ($try !~ /^try OK/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 621 | 0 | $self->_error("set_acl", "couldn't set acl for", $mailbox, $id, | |||||||||||||||||||||||||||
| 622 | $acl, ":", $try); | ||||||||||||||||||||||||||||
| 623 | 0 | return 1; | |||||||||||||||||||||||||||
| 624 | } | ||||||||||||||||||||||||||||
| 625 | } | ||||||||||||||||||||||||||||
| 626 | 0 | $self->{'Error'} = 'No Errors'; | |||||||||||||||||||||||||||
| 627 | 0 | return 0; | |||||||||||||||||||||||||||
| 628 | } | ||||||||||||||||||||||||||||
| 629 | |||||||||||||||||||||||||||||
| 630 | 0 | ▶ | sub delete_acl { | ||||||||||||||||||||||||||
|
Subroutine
delete_acl: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 631 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 632 | 0 | my ($id, $acl); | |||||||||||||||||||||||||||
| 633 | |||||||||||||||||||||||||||||
| 634 | 0 | ▶ | if (!defined($self->{'Socket'})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 635 | 0 | return 1; | |||||||||||||||||||||||||||
| 636 | } | ||||||||||||||||||||||||||||
| 637 | 0 | ▶ | if (!($self->{'Capability'} =~ /ACL/)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 638 | 0 | $self->_error("delete_acl", "ACL not listed in server's capabilities"); | |||||||||||||||||||||||||||
| 639 | 0 | return 1; | |||||||||||||||||||||||||||
| 640 | } | ||||||||||||||||||||||||||||
| 641 | 0 | ▶ | if (scalar(@_) < 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 642 | 0 | $self->_error("delete_acl", "incorrect number of arguments"); | |||||||||||||||||||||||||||
| 643 | 0 | return 1; | |||||||||||||||||||||||||||
| 644 | } | ||||||||||||||||||||||||||||
| 645 | 0 | my $mailbox = shift; | |||||||||||||||||||||||||||
| 646 | 0 | my $fh = $self->{'Socket'}; | |||||||||||||||||||||||||||
| 647 | 0 | ▶ | while(@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 648 | 0 | $id = shift; | |||||||||||||||||||||||||||
| 649 | 0 | print $fh qq{try DELETEACL "$mailbox" "$id"\n}; | |||||||||||||||||||||||||||
| 650 | 0 | my $try = $self->_read; | |||||||||||||||||||||||||||
| 651 | 0 | ▶ | if ($try !~ /^try OK/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 652 | 0 | $self->_error("delete_acl", "couldn't delete acl for", $mailbox, | |||||||||||||||||||||||||||
| 653 | $id, $acl, ":", $try); | ||||||||||||||||||||||||||||
| 654 | 0 | return 1; | |||||||||||||||||||||||||||
| 655 | } | ||||||||||||||||||||||||||||
| 656 | } | ||||||||||||||||||||||||||||
| 657 | 0 | return 0; | |||||||||||||||||||||||||||
| 658 | } | ||||||||||||||||||||||||||||
| 659 | |||||||||||||||||||||||||||||
| 660 | 0 | ▶ | sub list { # wild cards are allowed, returns array or undef | ||||||||||||||||||||||||||
|
Subroutine
list: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 661 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 662 | 0 | my (@info, @mail); | |||||||||||||||||||||||||||
| 663 | |||||||||||||||||||||||||||||
| 664 | 0 | ▶ | if (!defined($self->{'Socket'})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 665 | 0 | return; | |||||||||||||||||||||||||||
| 666 | } | ||||||||||||||||||||||||||||
| 667 | 0 | ▶ | if (scalar(@_) != 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 668 | 0 | $self->_error("list", "incorrect number of arguments"); | |||||||||||||||||||||||||||
| 669 | 0 | return; | |||||||||||||||||||||||||||
| 670 | } | ||||||||||||||||||||||||||||
| 671 | 0 | my $list = shift; | |||||||||||||||||||||||||||
| 672 | 0 | my $fh = $self->{'Socket'}; | |||||||||||||||||||||||||||
| 673 | 0 | print $fh qq{try LIST "" "$list"\n}; | |||||||||||||||||||||||||||
| 674 | 0 | my $try = $self->_read; | |||||||||||||||||||||||||||
| 675 | 0 | ▶ | while ($try =~ /^\* LIST.*?\) \".\" \"*(.*?)\"*$/) { # danger danger (could lock up needs timeout) " <- this quote makes emacs happy | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 676 | 0 | push @mail, $1; | |||||||||||||||||||||||||||
| 677 | 0 | $try = $self->_read; | |||||||||||||||||||||||||||
| 678 | } | ||||||||||||||||||||||||||||
| 679 | 0 | ▶ | if ($try =~ /^try OK/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 680 | 0 | return @mail; | |||||||||||||||||||||||||||
| 681 | } else { | ||||||||||||||||||||||||||||
| 682 | 0 | $self->_error("list", "couldn't get list for", $list, ":", $try); | |||||||||||||||||||||||||||
| 683 | 0 | return; | |||||||||||||||||||||||||||
| 684 | } | ||||||||||||||||||||||||||||
| 685 | } | ||||||||||||||||||||||||||||
| 686 | |||||||||||||||||||||||||||||
| 687 | |||||||||||||||||||||||||||||
| 688 | # Autoload methods go after =cut, and are processed by the autosplit program. | ||||||||||||||||||||||||||||
| 689 | |||||||||||||||||||||||||||||
| 690 | 1 | 1; | |||||||||||||||||||||||||||
| 691 | __END__ | ||||||||||||||||||||||||||||