| 1 | package AnyEvent::MCP::Worker::IMAP; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use common::sense; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use Mail::IMAPTalk (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use IO::Socket::SSL (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use MIME::Base64 (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use MIME::QuotedPrint (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use Encode (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use JSON::XS (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # mboxo stores raw messages without reliably escaping From_ lines. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | # check the original bytes, not decoded MIME parts; never rewrite the message. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 28 | ▶ | sub mbox_from { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mbox_from: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 28 | my ($bytes) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 28 | ▶ | $bytes =~ /^From[ \t]+\S+[ \t]+[^\r\n]* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | (?: [0-9]{2} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | | \b(?i:Mon|Tue|Wed|Thu|Fri|Sat|Sun | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\b | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | )/mx or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 18 | 1 + ((substr $bytes, 0, $-[0]) =~ tr/\n//) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 3 | my ($imap, $config); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 8 | ▶ | sub imap_connect { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
imap_connect: called CC=13 SCAR=30.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 8 | my ($settings) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 8 | $config = $settings; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 8 | undef $imap; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | my %tls = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_PEER (), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | SSL_verifycn_name => $config->{server}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 8 | SSL_verifycn_scheme => "http", # DNS names and IP addresses, not a web protocol | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 8 | ▶ | if ($config->{tls} eq "ssl") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | $imap = Mail::IMAPTalk->new ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | Server => $config->{server}, Port => $config->{port}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 8 | UseSSL => 1, UseBlocking => 1, PreserveINBOX => 1, %tls, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | $imap = Mail::IMAPTalk->new ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | Server => $config->{server}, Port => $config->{port}, PreserveINBOX => 1, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | $imap or die "IMAP connection failed: $@\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | $imap->_imap_cmd ("starttls", 0, "") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | or die "IMAP STARTTLS rejected: " . $imap->get_last_error . "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | IO::Socket::SSL->start_SSL ($imap->{Socket}, %tls) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | or die "IMAP TLS handshake failed: " . IO::Socket::SSL::errstr () . "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | $imap->{UseBlocking} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | delete $imap->{Cache}{capability}; # TLS changes advertised mechanisms | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 8 | ▶ | $imap or die "IMAP connection failed: $@\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 8 | ▶ | if (($config->{method} || "password") eq "oauth2") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$config->{'method'} || 'password'
MC/DC100%1/1
$config->{'method'} || 'password'
$config->{'method'}
Truth table100%2/2
A
A= $config->{'method'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 2 | require AnyEvent::MCP::IMAP::OAuth2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 2 | require Authen::SASL; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 2 | ▶ | my $mechanism = uc ($config->{oauth}{"oauth-sasl"} || "xoauth2"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$config->{'oauth'}{'oauth-sasl'} || 'xoauth2'
MC/DC0%0/1
$config->{'oauth'}{'oauth-sasl'} || 'xoauth2'
$config->{'oauth'}{'oauth-sasl'}
Truth table50%1/2
A
A= $config->{'oauth'}{'oauth-sasl'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 2 | ▶ | $imap->capability->{"auth=" . lc $mechanism} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | or die "IMAP server does not advertise AUTH=$mechanism\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | my $token = $config->{access_token} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 2 | ▶ | || AnyEvent::MCP::IMAP::OAuth2::refresh ($config->{account_file}, $config->{oauth}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$config->{'access_token'} || AnyEvent::MCP::IMAP::OAuth2::refresh($config->{'account_file'}, $config->{'oauth'})
MC/DC0%0/2
$config->{'access_token'} || AnyEvent::MCP::IMAP::OAuth2::refresh($config->{'account_file'}, $config->{'oauth'})
$config->{'access_token'}
AnyEvent::MCP::IMAP::OAuth2::refresh($config->{'account_file'}, $config->{'oauth'})
Truth table66%2/3
A || B
A= $config->{'access_token'}B= AnyEvent::MCP::IMAP::OAuth2::refresh($config->{'account_file'}, $config->{'oauth'})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | my $sasl = Authen::SASL->new ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | mechanism => $mechanism, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 2 | callback => { user => $config->{user}, pass => $token }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 2 | ▶ | $imap->authenticate ($sasl) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | or die "IMAP OAuth authentication failed: " . $imap->get_last_error . "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | $imap->login ($config->{user}, $config->{password}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 6 | ▶ | or die "IMAP authentication failed: " . $imap->get_last_error . "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 8 | $imap->uid (1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 8 | $imap->parse_mode (DecodeUTF8 => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 8 | +{ connected => JSON::XS::true, capabilities => [sort keys %{$imap->capability}] } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 94 | ▶ | sub checked ($$) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
checked: called CC=5 SCAR=23.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 94 | my ($result, $what) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 94 | ▶ | defined $result && $result | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition12%1/8
defined $result and $result
$imap->get_last_error || $@ || 'IMAP command failed'
$imap->get_last_error or $@
MC/DC0%0/2
defined $result and $result
defined $result
$result
MC/DC0%0/2
$imap->get_last_error || $@ || 'IMAP command failed'
$imap->get_last_error
$@
Truth table33%1/3
A and B
A= defined $resultB= $result
Truth table0%0/3
A or B
A= $imap->get_last_errorB= $@
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | or die "$what: " . ($imap->get_last_error || $@ || "IMAP command failed") . "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 94 | $result | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 30 | ▶ | sub mailbox { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mailbox: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 30 | my ($name, $writable) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 30 | checked ($imap->select ($name, ReadOnly => !$writable), "Select $name"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 30 | my $validity = $imap->get_response_code ("uidvalidity"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 30 | ▶ | defined $validity or die "UIDVALIDITY not supplied for $name\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 30 | $validity | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 20 | ▶ | sub same_validity { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
same_validity: called CC=3 SCAR=12.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 20 | my ($args, $writable) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 20 | my $validity = mailbox ($args->{mailbox}, $writable); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 20 | ▶ | defined $args->{uidvalidity} && "$args->{uidvalidity}" eq "$validity" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $args->{"uidvalidity"} and qq[$args->{"uidvalidity"}] eq "$validity"
MC/DC0%0/2
defined $args->{"uidvalidity"} and qq[$args->{"uidvalidity"}] eq "$validity"
defined $args->{"uidvalidity"}
qq[$args->{"uidvalidity"}] eq "$validity"
Truth table33%1/3
A and B
A= defined $args->{"uidvalidity"}B= qq[$args->{"uidvalidity"}] eq "$validity"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | or die "UIDVALIDITY mismatch (current $validity); refresh message references\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 20 | $validity | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 10 | ▶ | sub uids { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
uids: called CC=8 SCAR=24.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 10 | my ($args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 10 | ▶ | ref $args->{uids} eq "ARRAY" && @{$args->{uids}} && @{$args->{uids}} <= 100 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
ref $args->{"uids"} eq "ARRAY" and @{$args->{"uids"};} and @{$args->{"uids"};} <= 100
ref $args->{"uids"} eq "ARRAY" and @{$args->{"uids"};}
MC/DC0%0/3
ref $args->{"uids"} eq "ARRAY" and @{$args->{"uids"};} and @{$args->{"uids"};} <= 100
ref $args->{"uids"} eq "ARRAY"
@{$args->{"uids"};}
@{$args->{"uids"};} <= 100
Truth table25%1/4
A and B and C
A= ref $args->{"uids"} eq "ARRAY"B= @{$args->{"uids"};}C= @{$args->{"uids"};} <= 100
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | or die "uids must contain 1..100 message UIDs\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 10 | for (@{$args->{uids}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 10 | ▶ | defined $_ && !ref $_ && /\A[1-9][0-9]*\z/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $_ and not ref $_ and /\A[1-9][0-9]*\z/u
defined $_ and not ref $_
MC/DC0%0/3
defined $_ and not ref $_ and /\A[1-9][0-9]*\z/u
defined $_
not ref $_
/\A[1-9][0-9]*\z/u
Truth table25%1/4
A and not(B) and C
A= defined $_B= not ref $_C= /\A[1-9][0-9]*\z/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | or die "Invalid UID\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 10 | join ",", @{$args->{uids}} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 2 | ▶ | sub message { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
message: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 2 | my ($args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 2 | my $validity = same_validity ($args, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 2 | my $uid = $args->{uid}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 2 | ▶ | my $f = checked ($imap->fetch ($uid, "(envelope flags internaldate rfc822.size bodystructure)"), "Fetch $uid")->{$uid} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | or die "Message $uid vanished\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 2 | +{ uid => 0 + $uid, uidvalidity => $validity, %$f } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 84 | ▶ | sub search_filter { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
search_filter: called CC=44 SCAR=40.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 84 | my ($filter, $depth, $nodes) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 84 | ▶ | ref $filter eq "HASH" && (!$depth || keys %$filter) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
ref $filter eq "HASH" and !$depth || keys %$filter
not $depth or keys %$filter
MC/DC66%2/3
ref $filter eq "HASH" and !$depth || keys %$filter
ref $filter eq "HASH"
not $depth
keys %$filter
Truth table75%3/4
A and not(B) or C
A= ref $filter eq "HASH"B= not $depthC= keys %$filter
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | or die "Invalid SEARCH filter group\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 80 | ▶ | ++$$nodes <= 100 && $depth <= 12 or die "SEARCH filter too complex\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
++$$nodes <= 100 and $depth <= 12
MC/DC50%1/2
++$$nodes <= 100 and $depth <= 12
++$$nodes <= 100
$depth <= 12
Truth table66%2/3
A and B
A= ++$$nodes <= 100B= $depth <= 12
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 78 | my @criteria; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 78 | for my $key (sort keys %$filter) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 88 | my $value = $filter->{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 88 | ▶ | if ($key eq "all" || $key eq "any") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 7 branches
Condition100%3/3
$key eq "all" or $key eq "any"
MC/DC100%2/2
$key eq "all" or $key eq "any"
$key eq "all"
$key eq "any"
Truth table100%3/3
A or B
A= $key eq "all"B= $key eq "any"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 12 | ▶ | ref $value eq "ARRAY" && @$value && @$value <= 100 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
ref $value eq "ARRAY" and @$value and @$value <= 100
ref $value eq "ARRAY" and @$value
MC/DC33%1/3
ref $value eq "ARRAY" and @$value and @$value <= 100
ref $value eq "ARRAY"
@$value
@$value <= 100
Truth table50%2/4
A and B and C
A= ref $value eq "ARRAY"B= @$valueC= @$value <= 100
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | or die "SEARCH $key requires a nonempty array of filters\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 10 | my @groups = map [search_filter ($_, $depth + 1, $nodes)], @$value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 6 | ▶ | if ($key eq "all") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 2 | push @criteria, @groups; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 4 | my $or = pop @groups; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 4 | ▶ | $or = ["OR", pop @groups, $or] while @groups; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 4 | push @criteria, @$or; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | } elsif ($key eq "not") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 32 | push @criteria, "NOT", [search_filter ($value, $depth + 1, $nodes)]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | } elsif ($key eq "header") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 6 | ▶ | ref $value eq "HASH" && keys %$value && keys %$value <= 20 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
ref $value eq "HASH" and keys %$value and keys %$value <= 20
ref $value eq "HASH" and keys %$value
MC/DC0%0/3
ref $value eq "HASH" and keys %$value and keys %$value <= 20
ref $value eq "HASH"
keys %$value
keys %$value <= 20
Truth table25%1/4
A and B and C
A= ref $value eq "HASH"B= keys %$valueC= keys %$value <= 20
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | or die "SEARCH header requires 1..20 header names\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 6 | for my $name (sort keys %$value) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 6 | ▶ | $name =~ /\A[A-Za-z0-9][A-Za-z0-9-]{0,62}\z/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | or die "Invalid SEARCH header name\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 4 | my $text = $value->{$name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 4 | ▶ | defined $text && !ref $text && length $text <= 500 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
defined $text and not ref $text and length $text <= 500
defined $text and not ref $text
MC/DC33%1/3
defined $text and not ref $text and length $text <= 500
defined $text
not ref $text
length $text <= 500
Truth table50%2/4
A and not(B) and C
A= defined $textB= not ref $textC= length $text <= 500
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | or die "Invalid SEARCH header value\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 2 | push @criteria, "HEADER", $name, { Quote => $text }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | } elsif ($key =~ /\A(?:from|to|cc|bcc|subject|body|text)\z/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 18 | ▶ | defined $value && !ref $value && length $value <= 500 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $value and not ref $value and length $value <= 500
defined $value and not ref $value
MC/DC0%0/3
defined $value and not ref $value and length $value <= 500
defined $value
not ref $value
length $value <= 500
Truth table25%1/4
A and not(B) and C
A= defined $valueB= not ref $valueC= length $value <= 500
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | or die "Invalid SEARCH $key value\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 18 | push @criteria, uc $key, { Quote => $value }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | } elsif ($key =~ /\A(?:since|before|on|sent_since|sent_before|sent_on)\z/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 6 | ▶ | defined $value && !ref $value && $value =~ /\A[0-9]{1,2}-[A-Za-z]{3}-[0-9]{4}\z/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
defined $value and not ref $value and $value =~ /\A[0-9]{1,2}-[A-Za-z]{3}-[0-9]{4}\z/u
defined $value and not ref $value
MC/DC33%1/3
defined $value and not ref $value and $value =~ /\A[0-9]{1,2}-[A-Za-z]{3}-[0-9]{4}\z/u
defined $value
not ref $value
$value =~ /\A[0-9]{1,2}-[A-Za-z]{3}-[0-9]{4}\z/u
Truth table50%2/4
A and not(B) and C
A= defined $valueB= not ref $valueC= $value =~ /\A[0-9]{1,2}-[A-Za-z]{3}-[0-9]{4}\z/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | or die "Invalid SEARCH $key date (D-Mon-YYYY)\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 4 | (my $command = uc $key) =~ tr/_//d; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 4 | push @criteria, $command, $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | ▶ | } elsif ($key eq "larger" || $key eq "smaller") { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$key eq "larger" or $key eq "smaller"
MC/DC50%1/2
$key eq "larger" or $key eq "smaller"
$key eq "larger"
$key eq "smaller"
Truth table66%2/3
A or B
A= $key eq "larger"B= $key eq "smaller"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 4 | ▶ | defined $value && !ref $value && $value =~ /\A[0-9]{1,10}\z/ && $value <= 4294967295 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition55%5/9
defined $value and not ref $value and $value =~ /\A[0-9]{1,10}\z/u and $value <= 4294967295
defined $value and not ref $value and $value =~ /\A[0-9]{1,10}\z/u
defined $value and not ref $value
MC/DC25%1/4
defined $value and not ref $value and $value =~ /\A[0-9]{1,10}\z/u and $value <= 4294967295
defined $value
not ref $value
$value =~ /\A[0-9]{1,10}\z/u
$value <= 4294967295
Truth table40%2/5
A and not(B) and C and D
A= defined $valueB= not ref $valueC= $value =~ /\A[0-9]{1,10}\z/uD= $value <= 4294967295
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | or die "Invalid SEARCH $key size\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 2 | push @criteria, uc $key, $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | } elsif ($key =~ /\A(?:seen|unseen|answered|unanswered|flagged|unflagged|deleted|undeleted|draft|undraft|recent|old|new)\z/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 8 | ▶ | defined $value && "$value" =~ /\A[01]\z/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $value and "$value" =~ /\A[01]\z/u
MC/DC50%1/2
defined $value and "$value" =~ /\A[01]\z/u
defined $value
"$value" =~ /\A[01]\z/u
Truth table66%2/3
A and B
A= defined $valueB= "$value" =~ /\A[01]\z/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | or die "Invalid SEARCH $key boolean\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 6 | ▶ | push @criteria, uc $key if $value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 2 | die "Unknown SEARCH filter: $key\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 32 | ▶ | @criteria or !$depth or die "Empty SEARCH filter group\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@criteria or not $depth
MC/DC0%0/2
@criteria or not $depth
@criteria
not $depth
Truth table66%2/3
A or not(B)
A= @criteriaB= not $depth
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | @criteria | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 32 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 10 | ▶ | sub messages { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
messages: called CC=50 SCAR=44.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 10 | my ($args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 10 | my $validity = mailbox ($args->{mailbox}, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 10 | ▶ | my $limit = $args->{limit} || 25; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args->{'limit'} || 25
MC/DC100%1/1
$args->{'limit'} || 25
$args->{'limit'}
Truth table100%2/2
A
A= $args->{'limit'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 10 | ▶ | $limit =~ /\A[1-9][0-9]*\z/ && $limit <= 100 or die "limit must be 1..100\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$limit =~ /\A[1-9][0-9]*\z/u and $limit <= 100
MC/DC0%0/2
$limit =~ /\A[1-9][0-9]*\z/u and $limit <= 100
$limit =~ /\A[1-9][0-9]*\z/u
$limit <= 100
Truth table33%1/3
A and B
A= $limit =~ /\A[1-9][0-9]*\z/uB= $limit <= 100
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 10 | my $cursor = $args->{cursor}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 10 | ▶ | if (defined $cursor) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | ref $cursor eq "HASH" && defined $cursor->{uidvalidity} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | && "$cursor->{uidvalidity}" eq "$validity" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 4 | ▶ | && defined $cursor->{before_uid} && $cursor->{before_uid} =~ /\A[1-9][0-9]*\z/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition58%7/12
ref $cursor eq "HASH" and defined $cursor->{"uidvalidity"} and qq[$cursor->{"uidvalidity"}] eq "$validity" and defined $cursor->{"before_uid"} and $cursor->{"before_uid"} =~ /\A[1-9][0-9]*\z/u
ref $cursor eq "HASH" and defined $cursor->{"uidvalidity"} and qq[$cursor->{"uidvalidity"}] eq "$validity" and defined $cursor->{"before_uid"}
ref $cursor eq "HASH" and defined $cursor->{"uidvalidity"} and qq[$cursor->{"uidvalidity"}] eq "$validity"
ref $cursor eq "HASH" and defined $cursor->{"uidvalidity"}
MC/DC20%1/5
ref $cursor eq "HASH" and defined $cursor->{"uidvalidity"} and qq[$cursor->{"uidvalidity"}] eq "$validity" and defined $cursor->{"before_uid"} and $cursor->{"before_uid"} =~ /\A[1-9][0-9]*\z/u
ref $cursor eq "HASH"
defined $cursor->{"uidvalidity"}
qq[$cursor->{"uidvalidity"}] eq "$validity"
defined $cursor->{"before_uid"}
$cursor->{"before_uid"} =~ /\A[1-9][0-9]*\z/u
Truth table33%2/6
A and B and C and D and E
A= ref $cursor eq "HASH"B= defined $cursor->{"uidvalidity"}C= qq[$cursor->{"uidvalidity"}] eq "$validity"D= defined $cursor->{"before_uid"}E= $cursor->{"before_uid"} =~ /\A[1-9][0-9]*\z/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | or die "Stale or invalid UID cursor\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 8 | my $nodes = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 8 | ▶ | my @criteria = search_filter ($args->{filter} // {}, 0, \$nodes); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args->{"filter"} // {}
MC/DC100%1/1
$args->{"filter"} // {}
$args->{"filter"}
Truth table100%2/2
A
A= $args->{"filter"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 8 | ▶ | my @fields = @{$args->{fields} || [qw(subject from date flags size)]}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args->{'fields'} || ['subject', 'from', 'date', 'flags', 'size']
MC/DC100%1/1
$args->{'fields'} || ['subject', 'from', 'date', 'flags', 'size']
$args->{'fields'}
Truth table100%2/2
A
A= $args->{'fields'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 8 | my %valid = map +($_ => 1), qw(uid from to subject date cc reply-to message-id flags size internaldate); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 8 | ▶ | $valid{$_} or die "Invalid summary field: $_\n" for @fields; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 8 | ▶ | my @headers = @{$args->{headers} || []}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args->{'headers'} || []
MC/DC0%0/1
$args->{'headers'} || []
$args->{'headers'}
Truth table50%1/2
A
A= $args->{'headers'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 8 | ▶ | @headers <= 20 or die "Too many headers\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 8 | for (@headers) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | ▶ | /\A[A-Za-z0-9][A-Za-z0-9-]{0,62}\z/ or die "Invalid header name: $_\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | # search in descending UID windows: ordinary UID SEARCH can otherwise return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | # millions of matches even when only one summary page was requested. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | # Mail::IMAPTalk caches SELECT, so UIDNEXT from that SELECT becomes stale. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 8 | my $status = checked ($imap->status ($args->{mailbox}, "(UIDNEXT UIDVALIDITY)"), "STATUS"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 8 | ▶ | "$status->{uidvalidity}" eq "$validity" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | or die "Mailbox UIDVALIDITY changed; restart mcp-imap\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 8 | my $uidnext = $status->{uidnext}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 8 | ▶ | defined $uidnext && $uidnext =~ /\A[1-9][0-9]*\z/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $uidnext and $uidnext =~ /\A[1-9][0-9]*\z/u
MC/DC0%0/2
defined $uidnext and $uidnext =~ /\A[1-9][0-9]*\z/u
defined $uidnext
$uidnext =~ /\A[1-9][0-9]*\z/u
Truth table33%1/3
A and B
A= defined $uidnextB= $uidnext =~ /\A[1-9][0-9]*\z/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | or die "Server did not provide UIDNEXT\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 8 | ▶ | my $hi = $cursor ? $cursor->{before_uid} - 1 : $uidnext - 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 8 | my @found; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 8 | my $scanned = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 8 | ▶ | while ($hi > 0 && $scanned < 20000 && @found <= $limit) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$hi > 0 and $scanned < 20000 and @found <= $limit
$hi > 0 and $scanned < 20000
MC/DC66%2/3
$hi > 0 and $scanned < 20000 and @found <= $limit
$hi > 0
$scanned < 20000
@found <= $limit
Truth table75%3/4
A and B and C
A= $hi > 0B= $scanned < 20000C= @found <= $limit
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 16 | ▶ | my $lo = $hi > 999 ? $hi - 999 : 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 16 | my $matches = checked ($imap->search ("$lo:$hi", @criteria), "UID SEARCH"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 16 | push @found, sort { $b <=> $a } @$matches; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 16 | $scanned += $hi - $lo + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 16 | $hi = $lo - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 8 | my $more = @found > $limit; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 8 | ▶ | splice @found, $limit if $more; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 8 | ▶ | my $incomplete = $hi > 0 && !$more; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$hi > 0 && !$more
MC/DC0%0/2
$hi > 0 && !$more
$hi > 0
!$more
Truth table66%2/3
A && not(B)
A= $hi > 0B= !$more
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 8 | my %selected = map +($_ => 1), @fields; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 8 | my @items = ("uid"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 8 | ▶ | push @items, "envelope" if grep $selected{$_}, qw(from to subject date cc reply-to message-id); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 8 | ▶ | push @items, "flags" if $selected{flags}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 8 | ▶ | push @items, "rfc822.size" if $selected{size}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 8 | ▶ | push @items, "internaldate" if $selected{internaldate}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 8 | ▶ | if (@headers) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | push @items, "body.peek[header.fields (" . (join " ", @headers) . ")]"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 8 | ▶ | my $data = @found | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | ? checked ($imap->fetch (\@found, "(" . join (" ", @items) . ")"), "Fetch summaries") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | : {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 8 | my %env = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | (map +($_ => ucfirst $_), qw(from to subject date cc)), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | "reply-to" => "Reply-To", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | "message-id" => "Message-ID", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 8 | my @messages; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 8 | for my $uid (@found) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 14 | ▶ | my $item = $data->{$uid} or next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 14 | my %row = (uid => 0 + $uid); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 14 | for my $field (@fields) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 58 | ▶ | next if $field eq "uid"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 58 | my $key = $env{$field}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | $row{$field} = $key ? $item->{envelope}{$key} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 58 | ▶ | : $field eq "size" ? $item->{"rfc822.size"} : $item->{$field}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 14 | ▶ | if (@headers) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | ▶ | $row{headers} = $item->{headers} || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$item->{'headers'} || {}
MC/DC0%0/1
$item->{'headers'} || {}
$item->{'headers'}
Truth table0%0/2
A
A= $item->{'headers'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | ▶ | length (JSON::XS->new->utf8->encode ($row{headers})) <= 65536 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | or die "Selected headers exceed 64 KiB\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 14 | push @messages, \%row; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 8 | ▶ | my $before = $incomplete ? $hi + 1 : @found ? $found[-1] : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | +{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 8 | ▶ | uidvalidity => $validity, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition66%4/6
$more || $incomplete and $before
$more or $incomplete
MC/DC33%1/3
$more || $incomplete and $before
$more
$incomplete
$before
Truth table40%2/5
A or B and C
A= $moreB= $incompleteC= $before
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | messages => \@messages, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | more => $more ? JSON::XS::true : JSON::XS::false, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | incomplete => $incomplete ? JSON::XS::true : JSON::XS::false, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | next_cursor => ($more || $incomplete) && $before | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | ? { uidvalidity => $validity, before_uid => $before } : undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 4 | ▶ | sub part { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
part: called CC=25 SCAR=38.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 4 | my ($args, $raw_message) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 4 | my $validity = same_validity ($args, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 4 | my $uid = $args->{uid}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 4 | ▶ | my $part = $raw_message ? "" : $args->{part}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 4 | ▶ | defined $part && $part =~ /\A(?:[1-9][0-9]*(?:\.[1-9][0-9]*)*)?\z/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $part and $part =~ /\A(?:[1-9][0-9]*(?:\.[1-9][0-9]*)*)?\z/u
MC/DC0%0/2
defined $part and $part =~ /\A(?:[1-9][0-9]*(?:\.[1-9][0-9]*)*)?\z/u
defined $part
$part =~ /\A(?:[1-9][0-9]*(?:\.[1-9][0-9]*)*)?\z/u
Truth table33%1/3
A and B
A= defined $partB= $part =~ /\A(?:[1-9][0-9]*(?:\.[1-9][0-9]*)*)?\z/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | or die "Invalid MIME part number\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 4 | ▶ | my $max = $args->{max_bytes} || 65536; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args->{'max_bytes'} || 65536
MC/DC0%0/1
$args->{'max_bytes'} || 65536
$args->{'max_bytes'}
Truth table50%1/2
A
A= $args->{'max_bytes'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 4 | ▶ | $max =~ /\A[1-9][0-9]*\z/ && $max <= 262144 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$max =~ /\A[1-9][0-9]*\z/u and $max <= 262144
MC/DC0%0/2
$max =~ /\A[1-9][0-9]*\z/u and $max <= 262144
$max =~ /\A[1-9][0-9]*\z/u
$max <= 262144
Truth table33%1/3
A and B
A= $max =~ /\A[1-9][0-9]*\z/uB= $max <= 262144
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | or die "max_bytes must be 1..262144\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 4 | my $f = checked ($imap->fetch ($uid, "body.peek[$part]<0." . ($max + 1) . ">"), "Fetch part $uid"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 4 | ▶ | my $item = $f->{$uid} or die "Message $uid vanished\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 4 | my $bytes = $item->{body}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 4 | ▶ | defined $bytes && !ref $bytes or die "Invalid part data\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $bytes and not ref $bytes
MC/DC0%0/2
defined $bytes and not ref $bytes
defined $bytes
not ref $bytes
Truth table33%1/3
A and not(B)
A= defined $bytesB= not ref $bytes
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 4 | my $truncated = length $bytes > $max; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 4 | ▶ | substr $bytes, $max, "" if $truncated; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 4 | ▶ | my $result = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | uid => 0 + $uid, uidvalidity => $validity, part => $part, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | data_base64 => MIME::Base64::encode_base64 ($bytes, ""), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | truncated => $truncated ? JSON::XS::true : JSON::XS::false, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 4 | ▶ | if ($args->{decode_text} && !$truncated && !$raw_message) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$args->{"decode_text"} and not $truncated and not $raw_message
$args->{"decode_text"} and not $truncated
MC/DC33%1/3
$args->{"decode_text"} and not $truncated and not $raw_message
$args->{"decode_text"}
not $truncated
not $raw_message
Truth table50%2/4
A and not(B) and not(C)
A= $args->{"decode_text"}B= not $truncatedC= not $raw_message
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 2 | my $bs = checked ($imap->fetch ($uid, "bodystructure"), "Fetch MIME structure")->{$uid}{bodystructure}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 2 | my @pending = ($bs); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 2 | my $node; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 2 | ▶ | while (@pending) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 2 | my $candidate = shift @pending; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 2 | ▶ | if (($candidate->{"IMAP-Partnum"} // "") eq $part && $candidate->{"MIME-Type"} eq "text") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition40%2/5
($candidate->{"IMAP-Partnum"} // "") eq $part and $candidate->{"MIME-Type"} eq "text"
$candidate->{"IMAP-Partnum"} // ""
MC/DC0%0/2
($candidate->{"IMAP-Partnum"} // "") eq $part and $candidate->{"MIME-Type"} eq "text"
$candidate->{"IMAP-Partnum"}
$candidate->{"MIME-Type"} eq "text"
Truth table33%1/3
A and B
A= $candidate->{"IMAP-Partnum"}B= $candidate->{"MIME-Type"} eq "text"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 2 | $node = $candidate; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 2 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | ▶ | push @pending, @{$candidate->{"MIME-Subparts"} || []}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$candidate->{'MIME-Subparts'} || []
MC/DC0%0/1
$candidate->{'MIME-Subparts'} || []
$candidate->{'MIME-Subparts'}
Truth table0%0/2
A
A= $candidate->{'MIME-Subparts'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 2 | ▶ | $node or die "Part is not a text MIME leaf\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 2 | ▶ | my $encoding = uc ($node->{"Content-Transfer-Encoding"} || ""); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$node->{'Content-Transfer-Encoding'} || ''
MC/DC0%0/1
$node->{'Content-Transfer-Encoding'} || ''
$node->{'Content-Transfer-Encoding'}
Truth table50%1/2
A
A= $node->{'Content-Transfer-Encoding'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 2 | ▶ | $bytes = MIME::Base64::decode_base64 ($bytes) if $encoding eq "BASE64"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 2 | ▶ | $bytes = MIME::QuotedPrint::decode_qp ($bytes) if $encoding eq "QUOTED-PRINTABLE"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 2 | ▶ | my $charset = $node->{"Content-Type"}{charset} || "us-ascii"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$node->{'Content-Type'}{'charset'} || 'us-ascii'
MC/DC0%0/1
$node->{'Content-Type'}{'charset'} || 'us-ascii'
$node->{'Content-Type'}{'charset'}
Truth table50%1/2
A
A= $node->{'Content-Type'}{'charset'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 2 | $result->{text} = Encode::decode ($charset, $bytes, Encode::FB_CROAK ()); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 2 | $result->{content_type} = $node->{"MIME-TxtType"}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | $result | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 4 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 74 | ▶ | sub run { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: called CC=50 SCAR=47.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 74 | my ($cmd, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 74 | my $result = eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 74 | ▶ | if ($cmd eq "connect") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 6 | return (1, imap_connect ($args)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 68 | ▶ | $imap && $imap->is_open or die "IMAP connection closed; restart mcp-imap\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$imap and $imap->is_open
MC/DC0%0/2
$imap and $imap->is_open
$imap
$imap->is_open
Truth table33%1/3
A and B
A= $imapB= $imap->is_open
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 68 | ▶ | if ($cmd eq "mailboxes" || $cmd eq "lsub") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 9 branches
Condition100%3/3
$cmd eq "mailboxes" or $cmd eq "lsub"
MC/DC100%2/2
$cmd eq "mailboxes" or $cmd eq "lsub"
$cmd eq "mailboxes"
$cmd eq "lsub"
Truth table100%3/3
A or B
A= $cmd eq "mailboxes"B= $cmd eq "lsub"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 4 | ▶ | my $method = $cmd eq "lsub" ? "lsub" : "list"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 4 | return (1, { mailboxes => checked ($imap->$method ("", "*"), uc $method) }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | } elsif ($cmd eq "messages") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 10 | return (1, messages ($args)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | } elsif ($cmd eq "message") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 2 | return (1, message ($args)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | ▶ | } elsif ($cmd eq "part" || $cmd eq "raw") { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$cmd eq "part" or $cmd eq "raw"
MC/DC100%2/2
$cmd eq "part" or $cmd eq "raw"
$cmd eq "part"
$cmd eq "raw"
Truth table100%3/3
A or B
A= $cmd eq "part"B= $cmd eq "raw"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 4 | return (1, part ($args, $cmd eq "raw")); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | } elsif ($cmd eq "flags") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 4 | my $validity = same_validity ($args, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 4 | my $uidset = uids ($args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 4 | ▶ | $args->{operation} =~ /\A(?:add|remove)\z/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | or die "Invalid flag operation\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 2 | my $flags = $args->{flags}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 2 | ▶ | ref $flags eq "ARRAY" && @$flags && @$flags <= 20 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
ref $flags eq "ARRAY" and @$flags and @$flags <= 20
ref $flags eq "ARRAY" and @$flags
MC/DC0%0/3
ref $flags eq "ARRAY" and @$flags and @$flags <= 20
ref $flags eq "ARRAY"
@$flags
@$flags <= 20
Truth table25%1/4
A and B and C
A= ref $flags eq "ARRAY"B= @$flagsC= @$flags <= 20
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | or die "flags must be an array of 1..20 flags\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 2 | for (@$flags) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 2 | ▶ | /\A(?:\\(?:Seen|Flagged|Answered|Deleted|Draft)|[A-Za-z][A-Za-z0-9_-]{0,63})\z/i | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | or die "Invalid IMAP flag\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 2 | ▶ | checked ($imap->store ($uidset, ($args->{operation} eq "add" ? "+" : "-") . "flags.silent", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | "(" . join (" ", @$flags) . ")"), "STORE"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 2 | return (1, { ok => JSON::XS::true, uidvalidity => $validity, uids => $args->{uids} }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | ▶ | } elsif ($cmd eq "copy" || $cmd eq "move") { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$cmd eq "copy" or $cmd eq "move"
MC/DC50%1/2
$cmd eq "copy" or $cmd eq "move"
$cmd eq "copy"
$cmd eq "move"
Truth table66%2/3
A or B
A= $cmd eq "copy"B= $cmd eq "move"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 4 | my $validity = same_validity ($args, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 4 | my $uidset = uids ($args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | $cmd ne "move" || $imap->capability->{move} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 4 | ▶ | or die "Server does not advertise MOVE; refusing unsafe fallback\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$cmd ne "move" or $imap->capability->{"move"}
MC/DC50%1/2
$cmd ne "move" or $imap->capability->{"move"}
$cmd ne "move"
$imap->capability->{"move"}
Truth table66%2/3
A or B
A= $cmd ne "move"B= $imap->capability->{"move"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 2 | checked ($imap->$cmd ($uidset, $args->{destination}), uc $cmd); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 2 | return (1, { ok => JSON::XS::true, uidvalidity => $validity, uids => $args->{uids} }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | } elsif ($cmd eq "append") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | defined $args->{data_base64} && !ref $args->{data_base64} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | && length $args->{data_base64} <= 1398112 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 32 | ▶ | && $args->{data_base64} =~ /\A(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?\z/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition44%4/9
defined $args->{"data_base64"} and not ref $args->{"data_base64"} and length $args->{"data_base64"} <= 1398112 and $args->{"data_base64"} =~ m[\A(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?\z]u
defined $args->{"data_base64"} and not ref $args->{"data_base64"} and length $args->{"data_base64"} <= 1398112
defined $args->{"data_base64"} and not ref $args->{"data_base64"}
MC/DC25%1/4
defined $args->{"data_base64"} and not ref $args->{"data_base64"} and length $args->{"data_base64"} <= 1398112 and $args->{"data_base64"} =~ m[\A(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?\z]u
defined $args->{"data_base64"}
not ref $args->{"data_base64"}
length $args->{"data_base64"} <= 1398112
$args->{"data_base64"} =~ m[\A(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?\z]u
Truth table40%2/5
A and not(B) and C and D
A= defined $args->{"data_base64"}B= not ref $args->{"data_base64"}C= length $args->{"data_base64"} <= 1398112D= $args->{"data_base64"} =~ m[\A(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?\z]u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | or die "Invalid or oversized Base64 message\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 30 | my $bytes = MIME::Base64::decode_base64 ($args->{data_base64}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 30 | ▶ | length $bytes <= 1048576 or die "APPEND limited to 1 MiB\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 30 | ▶ | $bytes =~ /\r\n/ or die "APPEND expects an RFC 5322 message with CRLF line endings\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 30 | ▶ | unless ($config->{allow_mbox_from}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 28 | my $line = mbox_from ($bytes); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 28 | ▶ | die "APPEND refused: raw message line $line resembles an unescaped mboxo From_ separator " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | . "(starts with 'From ' and has date-like text). Some mbox servers may mistake it " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | . "for a new message boundary. No APPEND attempted. Escape the line, or ask the " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | . "server operator to use --allow-mbox-from.\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | if $line; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | ref $args->{flags} eq "ARRAY" || !defined $args->{flags} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 12 | ▶ | or die "Invalid flags\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $args->{"flags"} eq "ARRAY" or not defined $args->{"flags"}
MC/DC0%0/2
ref $args->{"flags"} eq "ARRAY" or not defined $args->{"flags"}
ref $args->{"flags"} eq "ARRAY"
not defined $args->{"flags"}
Truth table33%1/3
A or not(B)
A= ref $args->{"flags"} eq "ARRAY"B= not defined $args->{"flags"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 12 | ▶ | for (@{$args->{flags} || []}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args->{'flags'} || []
MC/DC0%0/1
$args->{'flags'} || []
$args->{'flags'}
Truth table50%1/2
A
A= $args->{'flags'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | ▶ | defined $_ && !ref $_ && /\A(?:\\(?:Seen|Flagged|Answered|Deleted|Draft)|[A-Za-z][A-Za-z0-9_-]{0,63})\z/i | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined $_ and not ref $_ and /\A(?:\\(?:Seen|Flagged|Answered|Deleted|Draft)|[A-Za-z][A-Za-z0-9_-]{0,63})\z/iu
defined $_ and not ref $_
MC/DC0%0/3
defined $_ and not ref $_ and /\A(?:\\(?:Seen|Flagged|Answered|Deleted|Draft)|[A-Za-z][A-Za-z0-9_-]{0,63})\z/iu
defined $_
not ref $_
/\A(?:\\(?:Seen|Flagged|Answered|Deleted|Draft)|[A-Za-z][A-Za-z0-9_-]{0,63})\z/iu
Truth table0%0/4
A and not(B) and C
A= defined $_B= not ref $_C= /\A(?:\\(?:Seen|Flagged|Answered|Deleted|Draft)|[A-Za-z][A-Za-z0-9_-]{0,63})\z/iu
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | or die "Invalid IMAP flag\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | my @extra = $args->{flags} && @{$args->{flags}} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | ▶ | ? ("(" . (join " ", @{$args->{flags}}) . ")") : (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$args->{"flags"} and @{$args->{"flags"};}
MC/DC0%0/2
$args->{"flags"} and @{$args->{"flags"};}
$args->{"flags"}
@{$args->{"flags"};}
Truth table33%1/3
A and B
A= $args->{"flags"}B= @{$args->{"flags"};}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 12 | checked ($imap->append ($args->{mailbox}, @extra, { Literal => $bytes }), "APPEND"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 12 | return (1, { ok => JSON::XS::true }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | } elsif ($cmd eq "expunge") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 6 | my $validity = same_validity ($args, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 6 | ▶ | if ($args->{uids}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | $imap->capability->{uidplus} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 4 | ▶ | or die "Server lacks UIDPLUS; refusing whole-mailbox fallback\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 2 | checked ($imap->uidexpunge (uids ($args)), "UID EXPUNGE"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 2 | checked ($imap->expunge, "EXPUNGE"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 4 | return (1, { ok => JSON::XS::true, uidvalidity => $validity }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | } elsif ($cmd eq "mailbox") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 2 | my $op = $args->{operation}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 2 | ▶ | defined $op && $op =~ /\A(?:create|rename|delete|subscribe|unsubscribe)\z/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $op and $op =~ /\A(?:create|rename|delete|subscribe|unsubscribe)\z/u
MC/DC0%0/2
defined $op and $op =~ /\A(?:create|rename|delete|subscribe|unsubscribe)\z/u
defined $op
$op =~ /\A(?:create|rename|delete|subscribe|unsubscribe)\z/u
Truth table33%1/3
A and B
A= defined $opB= $op =~ /\A(?:create|rename|delete|subscribe|unsubscribe)\z/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | or die "Invalid mailbox operation\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | ▶ | my @params = $op eq "rename" ? @{$args}{qw(mailbox destination)} : ($args->{mailbox}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | checked ($imap->$op (@params), uc $op); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | return (1, { ok => JSON::XS::true }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | die "Unknown IMAP operation\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 74 | my $error = $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 74 | ▶ | $result ? (1, $result) : (0, $error || "IMAP operation failed\n") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||