lib/AnyEvent/MCP/IMAP/Providers.pm

filter: Statementstmt 91.6% 154 / 168 Branchbran 64.4% 89 / 138 Conditioncond 50.0% 37 / 74 MC/DCmcdc 15.3% 6 / 39 Subroutinesub 92.3% 12 / 13 Podpod 0.0% 0 / 10 totaltotal 67.4% 298 / 442 CC 107 SCAR 39.4
CC
107
Cov
74%
run
100.5
parse_oauth
36.6
parse_ispdb
17.6
CRAP 51.2
« blib/lib/AnyEvent/MCP/Server/Permissions.pm ↑ Summary blib/lib/AnyEvent/MCP.pm »
1 package AnyEvent::MCP::IMAP::Providers;
2  
3 5 ▶use common::sense;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use HTTP::Tiny ();
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use JSON::XS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 5 my $oauth_source = "https://raw.githubusercontent.com/mozilla/releases-comm-central/master/mailnews/base/src/OAuth2Providers.sys.mjs";
8 5 my $ispdb = "https://autoconfig.thunderbird.net/";
9  
10 4 ▶sub read_file {
Subroutine read_file: called CC=2 SCAR=7.0
Pod undocumented
11 4 my ($file) = @_;
12 4 ▶ open my $fh, "<:raw", $file or die "$file: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<:raw", $file or die "${file}: $!\n" 4 0 4
13 4 local $/;
14 <$fh>
15 4 }
16  
17 0 ▶sub download {
Subroutine download: not called CC=2 SCAR=17.9
Pod undocumented
18 0 my ($url) = @_;
19 0 my $res = HTTP::Tiny->new (
20 timeout => 8, verify_SSL => 1, max_redirect => 0, max_size => 1_000_000,
21 )->get ($url);
22 $res->{success} ? $res->{content} : undef
23 0 ▶}
Branch: 1 branch
BranchTrueFalseTotal
$res->{'success'} ? : 0 0 0
24  
25 2 ▶sub parse_index {
Subroutine parse_index: called CC=4 SCAR=14.5
Pod undocumented
26 2 my ($json) = @_;
27 2 my $domains = JSON::XS::decode_json ($json);
28 2 ▶ ref $domains eq "ARRAY" or die "Invalid Thunderbird ISPDB index\n";
Branch: 1 branch
BranchTrueFalseTotal
ref $domains eq "ARRAY" or die "Invalid Thunderbird ISPDB index\n" 2 0 2
29 2 ▶ [grep !ref && valid_domain ($_) && !/\.test\z/, @$domains]
Condition66%4/6
!ref($_) && valid_domain($_) && !/\.test\z/u
!ll&&!rl&&r
204
not ref $_ and valid_domain($_)
!ll&&!rl&&r
024
MC/DC33%1/3
!ref($_) && valid_domain($_) && !/\.test\z/u
not ref $_ valid_domain($_) !/\.test\z/u
Truth table50%2/4
not(A) and B && not(C)
A= not ref $_B= valid_domain($_)C= !/\.test\z/u
ABCresult
0XX0
10X0
1100
1111
30 }
31  
32 # Only recognize Thunderbird's declarative literal data; never execute JavaScript.
33 7 ▶sub parse_oauth {
Subroutine parse_oauth: called CC=25 SCAR=36.0
Pod undocumented
34 7 my ($source) = @_;
35  
36 7 my %scopes;
37 7 ▶ while ($source =~ /^const\s+([A-Z_]+_SCOPES)\s*=\s*(\{.*?^\};|"[^"]*";)/msg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($source =~ /^const\s+([A-Z_]+_SCOPES)\s*=\s*(\{.*?^\};|"[^"]*";)/gmsu) 5 7 12
38 5 my ($name, $value) = ($1, $2);
39 5 ▶ if ($value =~ /^\{/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ /^\{/u) { } 5 0 5
40 5 my %scope = $value =~ /\b(imap|extra)\s*:\s*"([^"]*)"/g;
41 5 $scopes{$name} = \%scope;
42 } else {
43 0 ($scopes{$name}) = $value =~ /^"([^"]*)"/;
44 }
45 }
46  
47 7 ▶ my ($hostnames) = $source =~ /\bvar\s+kHostnames\s*=\s*new Map\(\[\s*(.*?)^\]\);/ms
Branch: 1 branch
BranchTrueFalseTotal
my($hostnames) = $source =~ /\bvar\s+kHostnames\s*=\s*new Map\(\[\s*(.*?)^\]\);/msu or die "Thunderbird kHostnames layout changed\n" 5 2 7
48 or die "Thunderbird kHostnames layout changed\n";
49 5 ▶ my ($issuers) = $source =~ /\bvar\s+kIssuers\s*=\s*new Map\(\[\s*(.*?)^\]\);/ms
Branch: 1 branch
BranchTrueFalseTotal
my($issuers) = $source =~ /\bvar\s+kIssuers\s*=\s*new Map\(\[\s*(.*?)^\]\);/msu or die "Thunderbird kIssuers layout changed\n" 5 0 5
50 or die "Thunderbird kIssuers layout changed\n";
51  
52 5 my %issuer;
53 5 ▶ while ($issuers =~ /\[\s*"([^"]+)"\s*,\s*\{\s*(.*?)^\s*\},?\s*\]/msg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($issuers =~ /\[\s*"([^"]+)"\s*,\s*\{\s*(.*?)^\s*\},?\s*\]/gmsu) 5 5 10
54 5 my ($name, $fields) = ($1, $2);
55 5 my %fields;
56 5 ▶ while ($fields =~ /\b(clientId|clientSecret|authorizationEndpoint|tokenEndpoint|redirectionEndpoint|usePKCE)\s*:\s*(?:"([^"]*)"|\x60([^\x60]*)\x60|(true|false))/g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fields =~ /\b(clientId|clientSecret|authorizationEndpoint|tokenEndpoint|redirectionEndpoint|usePKCE)\s*:\s*(?:"([^"]*)"|\x60([^\x60]*)\x60|(true|false))/gu) 20 5 25
57 20 ▶ $fields{$1} = defined $2 ? $2 : defined $3 ? $3 : $4;
Branch: 2 branches
BranchTrueFalseTotal
defined $2 ? : 15 5 20
defined $3 ? : 0 5 5
58 }
59 5 $issuer{$name} = \%fields;
60 }
61 5 ▶ %issuer or die "Thunderbird kIssuers entries not recognized\n";
Branch: 1 branch
BranchTrueFalseTotal
%issuer or die "Thunderbird kIssuers entries not recognized\n" 5 0 5
62  
63 5 my %result;
64 5 ▶ while ($hostnames =~ /\[\s*"([^"]+)"\s*,\s*\[\s*"([^"]+)"\s*,\s*(?:"([^"]*)"|([A-Z_]+_SCOPES)(?:\.(\w+))?)\s*\]\s*\]/mg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hostnames =~ /\[\s*"([^"]+)"\s*,\s*\[\s*"([^"]+)"\s*,\s*(?:"([^"]*)"|([A-Z_]+_SCOPES)(?:\.(\w+))?)\s*\]\s*\]/gmu) 15 5 20
65 15 my ($host, $name, $literal, $constant, $field) = ($1, $2, $3, $4, $5);
66 15 ▶ my $scope = defined $literal ? $literal : $scopes{$constant};
Branch: 1 branch
BranchTrueFalseTotal
defined $literal ? : 5 10 15
67 15 ▶ $scope = $scope->{$field || "imap"} . (defined $scope->{extra} ? " $scope->{extra}" : "")
Branch: 2 branches
BranchTrueFalseTotal
if ref $scope eq "HASH" and !$field || $field eq "imap" 10 5 15
defined $scope->{'extra'} ? : 10 0 10
Condition50%4/8
ref $scope eq "HASH" and !$field || $field eq "imap"
!ll&&!rl&&r
5010
not $field or $field eq "imap"
l!l&&r!l&&!r
1000
$field || 'imap'
l!l
010
MC/DC33%1/3
ref $scope eq "HASH" and !$field || $field eq "imap"
ref $scope eq "HASH" not $field $field eq "imap"
MC/DC0%0/1
$field || 'imap'
$field
Truth table50%2/4
A and not(B) or C
A= ref $scope eq "HASH"B= not $fieldC= $field eq "imap"
ABCresult
0XX0
1000
11X1
1011
Truth table50%1/2
A
A= $field
Aresult
11
00
68 if ref $scope eq "HASH" && (!$field || $field eq "imap");
69 15 ▶ next if ref $scope || !defined $scope || !length $scope;
Branch: 1 branch
BranchTrueFalseTotal
if ref $scope or not defined $scope or not length $scope 0 15 15
Condition33%2/6
ref $scope or not defined $scope or not length $scope
l!l&&r!l&&!r
0015
ref $scope or not defined $scope
l!l&&r!l&&!r
0015
MC/DC0%0/3
ref $scope or not defined $scope or not length $scope
ref $scope not defined $scope not length $scope
Truth table25%1/4
A or not(B) or not(C)
A= ref $scopeB= not defined $scopeC= not length $scope
ABCresult
1XX1
01X1
0011
0000
70 15 ▶ my $data = $issuer{$name} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $data = $issuer{$name} or next 15 0 15
71 15 ▶ $data->{clientId} && $data->{authorizationEndpoint} && $data->{tokenEndpoint} or next;
Branch: 1 branch
BranchTrueFalseTotal
$data->{"clientId"} and $data->{"authorizationEndpoint"} and $data->{"tokenEndpoint"} or next 15 0 15
Condition33%2/6
$data->{"clientId"} and $data->{"authorizationEndpoint"} and $data->{"tokenEndpoint"}
!ll&&!rl&&r
0015
$data->{"clientId"} and $data->{"authorizationEndpoint"}
!ll&&!rl&&r
0015
MC/DC0%0/3
$data->{"clientId"} and $data->{"authorizationEndpoint"} and $data->{"tokenEndpoint"}
$data->{"clientId"} $data->{"authorizationEndpoint"} $data->{"tokenEndpoint"}
Truth table25%1/4
A and B and C
A= $data->{"clientId"}B= $data->{"authorizationEndpoint"}C= $data->{"tokenEndpoint"}
ABCresult
0XX0
10X0
1100
1111
72 15 $result{$host} = { %$data, issuer => $name, scope => $scope };
73 }
74  
75 5 ▶ %result or die "Thunderbird hostname/scope entries not recognized\n";
Branch: 1 branch
BranchTrueFalseTotal
%result or die "Thunderbird hostname/scope entries not recognized\n" 5 0 5
76 5 \%result
77 }
78  
79 6 ▶sub parse_ispdb {
Subroutine parse_ispdb: called CC=16 SCAR=28.7
Pod undocumented
80 6 my ($xml, $email) = @_;
81 6 require XML::LibXML;
82 6 ▶ length $xml <= 1_000_000 or die "Autoconfig XML too large\n";
Branch: 1 branch
BranchTrueFalseTotal
length $xml <= 1000000 or die "Autoconfig XML too large\n" 6 0 6
83 6 my $doc = XML::LibXML->load_xml (
84 string => $xml, no_network => 1, load_ext_dtd => 0, expand_entities => 0,
85 );
86 6 ▶ $doc->documentElement->nodeName eq "clientConfig"
Branch: 1 branch
BranchTrueFalseTotal
$doc->documentElement->nodeName eq "clientConfig" or die "Not a Thunderbird autoconfig document\n" 6 0 6
87 or die "Not a Thunderbird autoconfig document\n";
88  
89 6 my @servers;
90 6 for my $server ($doc->findnodes ("/clientConfig/emailProvider/incomingServer[\@type='imap']")) {
91 7 my %info = (
92 server => $server->findvalue ("./hostname"),
93 port => $server->findvalue ("./port"),
94 tls => $server->findvalue ("./socketType"),
95 user => $server->findvalue ("./username"),
96 );
97 7 my @auth = map $_->textContent, $server->findnodes ("./authentication");
98 7 my @methods;
99 7 ▶ push @methods, "oauth2" if grep $_ eq "OAuth2", @auth;
Branch: 1 branch
BranchTrueFalseTotal
if grep(($_ eq "OAuth2"), @auth) 5 2 7
100 7 ▶ push @methods, "password" if grep $_ eq "password-cleartext", @auth;
Branch: 1 branch
BranchTrueFalseTotal
if grep(($_ eq "password-cleartext"), @auth) 7 0 7
101 7 ▶ next unless @methods;
Branch: 1 branch
BranchTrueFalseTotal
unless @methods 0 7 7
102 7 ▶ $info{tls} = $info{tls} eq "SSL" ? "ssl" : $info{tls} eq "STARTTLS" ? "starttls" : next;
Branch: 2 branches
BranchTrueFalseTotal
$info{'tls'} eq 'SSL' ? : 6 1 7
$info{'tls'} eq 'STARTTLS' ? : 1 0 1
103 7 ▶ $info{port} =~ /^\d+$/ && $info{port} >= 1 && $info{port} <= 65535 or next;
Branch: 1 branch
BranchTrueFalseTotal
$info{"port"} =~ /^\d+$/u and $info{"port"} >= 1 and $info{"port"} <= 65535 or next 7 0 7
Condition33%2/6
$info{"port"} =~ /^\d+$/u and $info{"port"} >= 1 and $info{"port"} <= 65535
!ll&&!rl&&r
007
$info{"port"} =~ /^\d+$/u and $info{"port"} >= 1
!ll&&!rl&&r
007
MC/DC0%0/3
$info{"port"} =~ /^\d+$/u and $info{"port"} >= 1 and $info{"port"} <= 65535
$info{"port"} =~ /^\d+$/u $info{"port"} >= 1 $info{"port"} <= 65535
Truth table25%1/4
A and B and C
A= $info{"port"} =~ /^\d+$/uB= $info{"port"} >= 1C= $info{"port"} <= 65535
ABCresult
0XX0
10X0
1100
1111
104 7 ▶ if (defined $email) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $email) 5 2 7
105 5 my ($local, $domain) = split /\@/, $email, 2;
106 5 for my $key (qw(server user)) {
107 10 $info{$key} =~ s/%EMAILADDRESS%/$email/g;
108 10 $info{$key} =~ s/%EMAILLOCALPART%/$local/g;
109 10 $info{$key} =~ s/%EMAILDOMAIN%/$domain/g;
110 }
111 }
112 7 ▶ delete $info{user} if $info{user} =~ /%/;
Branch: 1 branch
BranchTrueFalseTotal
if $info{"user"} =~ /%/u 2 5 7
113 7 ▶ next if $info{server} !~ /\A[A-Za-z0-9.-]+\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $info{"server"} =~ /\A[A-Za-z0-9.-]+\z/u 2 5 7
114 5 $info{methods} = \@methods;
115 5 push @servers, \%info;
116 }
117 +{
118 6 name => scalar $doc->findvalue ("/clientConfig/emailProvider/displayName"),
119 servers => \@servers,
120 notes => [map $_->textContent, $doc->findnodes ("/clientConfig/emailProvider/enable/instruction[not(\@lang)]")],
121 links => [map $_->getAttribute ("visiturl"), $doc->findnodes ("/clientConfig/emailProvider/enable[\@visiturl]")],
122 }
123 }
124  
125 7 ▶sub valid_domain {
Subroutine valid_domain: called CC=1 SCAR=0.0
Pod undocumented
126 7 $_[0] =~ /\A(?=.{1,253}\z)[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?(?:\.[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?)+\z/
127 }
128  
129 2 ▶sub find_oauth {
Subroutine find_oauth: called CC=6 SCAR=24.5
Pod undocumented
130 2 my ($all, @hosts) = @_;
131 2 for my $host (@hosts) {
132 2 ▶ next unless defined $host;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $host 0 2 2
133 2 ▶ return $all->{$host} if $all->{$host};
Branch: 1 branch
BranchTrueFalseTotal
if $all->{$host} 2 0 2
134 0 for my $name (keys %$all) {
135 0 ▶ return $all->{$name} if $host eq "imap.$name";
Branch: 1 branch
BranchTrueFalseTotal
if $host eq "imap.$name" 0 0 0
136 }
137 }
138 undef
139 0 }
140  
141 21 ▶sub quote {
Subroutine quote: called CC=2 SCAR=6.9
Pod undocumented
142 21 my ($s) = @_;
143 21 ▶ return $s if $s =~ /\A[-A-Za-z0-9_@%+=:,\.\/]+\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $s =~ m[\A[-A-Za-z0-9_\@%+=:,\./]+\z]u 17 4 21
144 4 $s =~ s/'/'\\''/g;
145 4 "'$s'"
146 }
147  
148 2 ▶sub print_login {
Subroutine print_login: called CC=12 SCAR=25.8
Pod undocumented
149 2 my ($name, $server, $method, $oauth) = @_;
150 2 my @kv = (method => $method);
151 2 for my $key (qw(server tls port user)) {
152 8 ▶ push @kv, $key => $server->{$key} if defined $server->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if defined $server->{$key} 8 0 8
153 }
154 2 ▶ if ($method eq "oauth2") {
Branch: 1 branch
BranchTrueFalseTotal
if ($method eq "oauth2") 1 1 2
155 1 push @kv, "oauth-client-id" => $oauth->{clientId};
156 1 ▶ push @kv, "oauth-client-secret" => $oauth->{clientSecret} if defined $oauth->{clientSecret};
Branch: 1 branch
BranchTrueFalseTotal
if defined $oauth->{"clientSecret"} 0 1 1
157 1 push @kv, "oauth-authorization-endpoint" => $oauth->{authorizationEndpoint};
158 1 push @kv, "oauth-token-endpoint" => $oauth->{tokenEndpoint};
159 1 push @kv, "oauth-scope" => $oauth->{scope};
160 1 ▶ push @kv, "oauth-pkce" => $oauth->{usePKCE} && $oauth->{usePKCE} eq "true" ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$oauth->{'usePKCE'} && $oauth->{'usePKCE'} eq 'true' ? : 1 0 1
Condition33%1/3
$oauth->{"usePKCE"} and $oauth->{"usePKCE"} eq "true"
!ll&&!rl&&r
001
MC/DC0%0/2
$oauth->{"usePKCE"} and $oauth->{"usePKCE"} eq "true"
$oauth->{"usePKCE"} $oauth->{"usePKCE"} eq "true"
Truth table33%1/3
A and B
A= $oauth->{"usePKCE"}B= $oauth->{"usePKCE"} eq "true"
ABresult
0X0
100
111
161 1 ▶ my $redirect = $oauth->{redirectionEndpoint} || "http://127.0.0.1";
Condition50%1/2
$oauth->{'redirectionEndpoint'} || 'http://127.0.0.1'
l!l
01
MC/DC0%0/1
$oauth->{'redirectionEndpoint'} || 'http://127.0.0.1'
$oauth->{'redirectionEndpoint'}
Truth table50%1/2
A
A= $oauth->{'redirectionEndpoint'}
Aresult
11
00
162 1 ▶ $redirect .= ":1" if $redirect =~ m{\Ahttp://(?:127\.0\.0\.1|localhost)\z};
Branch: 1 branch
BranchTrueFalseTotal
if $redirect =~ m[\Ahttp://(?:127\.0\.0\.1|localhost)\z]u 1 0 1
163 1 push @kv, "oauth-redirect-uri" => $redirect;
164 }
165 2 ▶ print "mcp-imap --name ", quote ($name), " login", @kv ? " \\\n" : "\n";
Branch: 1 branch
BranchTrueFalseTotal
@kv ? : 2 0 2
166 2 ▶ while (@kv) {
Branch: 1 branch
BranchTrueFalseTotal
if (@kv) 16 2 18
167 16 my ($key, $value) = splice @kv, 0, 2;
168 16 ▶ print " $key ", quote ($value), @kv ? " \\\n" : "\n";
Branch: 1 branch
BranchTrueFalseTotal
@kv ? : 14 2 16
169 }
170 }
171  
172 3 ▶sub run {
Subroutine run: called CC=46 SCAR=46.1
Pod undocumented
173 3 my ($name, $provider_file, $ispdb_file, @args) = @_;
174 3 ▶ @args <= 1 or die "Usage: mcp-imap [OPTION]... providers [SEARCH]\n";
Branch: 1 branch
BranchTrueFalseTotal
@args <= 1 or die "Usage: mcp-imap [OPTION]... providers [SEARCH]\n" 3 0 3
175 3 my $search = $args[0];
176 3 my $email;
177 3 ▶ if (defined $search && $search =~ /\A([^\s\@]+)\@([A-Za-z0-9.-]+)\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $search and $search =~ /\A([^\s\@]+)\@([A-Za-z0-9.-]+)\z/u) 1 2 3
Condition100%3/3
defined $search and $search =~ /\A([^\s\@]+)\@([A-Za-z0-9.-]+)\z/u
!ll&&!rl&&r
111
MC/DC100%2/2
defined $search and $search =~ /\A([^\s\@]+)\@([A-Za-z0-9.-]+)\z/u
defined $search $search =~ /\A([^\s\@]+)\@([A-Za-z0-9.-]+)\z/u
Truth table100%3/3
A and B
A= defined $searchB= $search =~ /\A([^\s\@]+)\@([A-Za-z0-9.-]+)\z/u
ABresult
0X0
100
111
178 1 $email = $search;
179 1 $search = $2;
180 }
181  
182 3 ▶ my $source = defined $provider_file ? read_file ($provider_file) : download ($oauth_source);
Branch: 1 branch
BranchTrueFalseTotal
defined $provider_file ? : 3 0 3
183 3 ▶ my $oauth = defined $source ? parse_oauth ($source) : {};
Branch: 1 branch
BranchTrueFalseTotal
defined $source ? : 3 0 3
184 3 ▶ my $index = defined $provider_file || defined $ispdb_file ? [] :
Branch: 1 branch
BranchTrueFalseTotal
defined $provider_file || defined $ispdb_file ? : 3 0 3
Condition20%1/5
defined $provider_file or defined $ispdb_file
l!l&&r!l&&!r
300
download($ispdb . 'generated_files.json') || '[]'
l!l
00
MC/DC0%0/2
defined $provider_file or defined $ispdb_file
defined $provider_file defined $ispdb_file
MC/DC0%0/1
download($ispdb . 'generated_files.json') || '[]'
download($ispdb . 'generated_files.json')
Truth table33%1/3
A or B
A= defined $provider_fileB= defined $ispdb_file
ABresult
1X1
011
000
Truth table0%0/2
A
A= download($ispdb . 'generated_files.json')
Aresult
11
00
185 parse_index (download ($ispdb . "generated_files.json") || "[]");
186 3 my %known = map +($_ => 1), (@$index, keys %$oauth);
187 3 delete @known{grep /^(?:smtp|pop|pop3|carddav|carddav-personal|caldav|graph|www\.googleapis|apidata)\.|\.test\z/, keys %known};
188 my @domains = sort grep !defined $search
189 || index (lc $_, lc $search) >= 0
190 3 ▶ || ($oauth->{$_} && index (lc $oauth->{$_}{issuer}, lc $search) >= 0), keys %known;
Condition66%6/9
!defined($search) || index(lc $_, lc $search) != -1 || $oauth->{$_} && index(lc $oauth->{$_}{'issuer'}, lc $search) != -1
l!l&&r!l&&!r
510
not defined $search or index(lc $_, lc $search) != -1
l!l&&r!l&&!r
231
$oauth->{$_} and index(lc $oauth->{$_}{"issuer"}, lc $search) != -1
!ll&&!rl&&r
001
MC/DC0%0/4
!defined($search) || index(lc $_, lc $search) != -1 || $oauth->{$_} && index(lc $oauth->{$_}{'issuer'}, lc $search) != -1
not defined $search index(lc $_, lc $search) != -1 $oauth->{$_} index(lc $oauth->{$_}{"issuer"}, lc $search) != -1
Truth table60%3/5
not(A) or B || C and D
A= not defined $searchB= index(lc $_, lc $search) != -1C= $oauth->{$_}D= index(lc $oauth->{$_}{"issuer"}, lc $search) != -1
ABCDresult
1XXX1
01XX1
00111
000X0
00100
191  
192 3 ▶ my @exact = defined $search ? grep lc $_ eq lc $search, @domains : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $search ? : 2 1 3
193 3 ▶ @domains = @exact if @exact;
Branch: 1 branch
BranchTrueFalseTotal
if @exact 1 2 3
194 3 ▶ if (!defined $search || @domains > 1 || !@domains && !valid_domain ($search)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $search or @domains > 1 or not @domains || valid_domain($search)) 2 1 3
Condition66%6/9
not defined $search or @domains > 1 or not @domains || valid_domain($search)
l!l&&r!l&&!r
201
not defined $search or @domains > 1
l!l&&r!l&&!r
111
@domains || valid_domain($search)
l!l&&r!l&&!r
100
MC/DC50%2/4
not defined $search or @domains > 1 or not @domains || valid_domain($search)
not defined $search @domains > 1 @domains valid_domain($search)
Truth table60%3/5
not(A) or B or not(C || D)
A= not defined $searchB= @domains > 1C= @domainsD= valid_domain($search)
ABCDresult
1XXX1
01XX1
00001
001X0
00010
195 2 ▶ @domains or die "No matching providers\n";
Branch: 1 branch
BranchTrueFalseTotal
@domains or die "No matching providers\n" 2 0 2
196 2 print "Thunderbird mail providers (", scalar @domains, " matches):\n";
197 printf " %-32s %s\n", $_, $oauth->{$_} ? "OAuth: $oauth->{$_}{issuer}" : "ISPDB"
198 2 ▶ for @domains;
Branch: 1 branch
BranchTrueFalseTotal
$oauth->{$_} ? : 4 0 4
199 2 print "\nSpecify a domain or email address to generate login commands.\n";
200 2 return;
201 }
202 1 ▶ my $domain = @domains == 1 ? $domains[0] : $search;
Branch: 1 branch
BranchTrueFalseTotal
@domains == 1 ? : 1 0 1
203 1 ▶ valid_domain ($domain) or die "Invalid provider domain\n";
Branch: 1 branch
BranchTrueFalseTotal
valid_domain($domain) or die "Invalid provider domain\n" 1 0 1
204  
205 1 my ($xml, $origin);
206 1 ▶ if (defined $ispdb_file) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ispdb_file) { } 1 0 1
207 1 $xml = read_file ($ispdb_file);
208 1 $origin = "local XML ($ispdb_file)";
209 } else {
210 0 for my $url (
211 "https://autoconfig.$domain/mail/config-v1.1.xml",
212 "https://$domain/.well-known/autoconfig/mail/config-v1.1.xml",
213 $ispdb . "v1.1/$domain",
214 ) {
215 0 $xml = download ($url);
216 0 ▶ if (defined $xml) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $xml) 0 0 0
217 0 $origin = $url;
218 0 last;
219 }
220 }
221 }
222  
223 1 ▶ my $config = defined $xml ? parse_ispdb ($xml, $email) :
Branch: 1 branch
BranchTrueFalseTotal
defined $xml ? : 1 0 1
224 { name => "", servers => [], notes => [], links => [] };
225 1 ▶ print "Provider: $domain", $config->{name} ? " ($config->{name})" : "", "\n";
Branch: 1 branch
BranchTrueFalseTotal
$config->{'name'} ? : 0 1 1
226 1 ▶ print "IMAP configuration: ", $origin || "not found", "\n";
Condition50%1/2
$origin || 'not found'
l!l
10
MC/DC0%0/1
$origin || 'not found'
$origin
Truth table50%1/2
A
A= $origin
Aresult
11
00
227 print "OAuth reference: $oauth_source\n"
228 1 ▶ if find_oauth ($oauth, $domain, map $_->{server}, @{$config->{servers}});
Branch: 1 branch
BranchTrueFalseTotal
if find_oauth($oauth, $domain, map($_->{"server"}, @{$$config{"servers"};})) 1 0 1
229 print "No IMAP autoconfiguration found; server, TLS and port require manual setup.\n"
230 1 ▶ unless @{$config->{servers}};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$config->{"servers"};} 0 1 1
231 1 print "Setup: $_\n" for grep length, @{$config->{notes}};
232 1 print "Setup URL: $_\n" for grep length, @{$config->{links}};
233  
234 1 my @servers = @{$config->{servers}};
235 1 ▶ push @servers, { server => $domain =~ /^imap\./ ? $domain : undef,
Branch: 2 branches
BranchTrueFalseTotal
if not @servers and find_oauth($oauth, $domain) 0 1 1
$domain =~ /^imap\./u ? : 0 0 0
Condition33%1/3
not @servers and find_oauth($oauth, $domain)
!ll&&!rl&&r
100
MC/DC0%0/2
not @servers and find_oauth($oauth, $domain)
not @servers find_oauth($oauth, $domain)
Truth table33%1/3
not(A) and B
A= not @serversB= find_oauth($oauth, $domain)
ABresult
0X0
100
111
236 methods => ["oauth2"] }
237 if !@servers && find_oauth ($oauth, $domain);
238 1 ▶ @servers or die "No supported IMAP configuration for $domain\n";
Branch: 1 branch
BranchTrueFalseTotal
@servers or die "No supported IMAP configuration for $domain\n" 1 0 1
239  
240 1 for my $server (@servers) {
241 1 my $o = find_oauth ($oauth, $domain, $server->{server});
242 print "\nIMAP $server->{server}:$server->{port} ($server->{tls}), authentication: ",
243 1 join (", ", @{$server->{methods}}), "\n"
244 1 ▶ if defined $server->{server} && defined $server->{port};
Branch: 1 branch
BranchTrueFalseTotal
if defined $server->{"server"} and defined $server->{"port"} 1 0 1
Condition33%1/3
defined $server->{"server"} and defined $server->{"port"}
!ll&&!rl&&r
001
MC/DC0%0/2
defined $server->{"server"} and defined $server->{"port"}
defined $server->{"server"} defined $server->{"port"}
Truth table33%1/3
A and B
A= defined $server->{"server"}B= defined $server->{"port"}
ABresult
0X0
100
111
245 1 for my $method (@{$server->{methods}}) {
246 2 ▶ if ($method eq "oauth2" && !$o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($method eq "oauth2" and not $o) 0 2 2
Condition66%2/3
$method eq "oauth2" and not $o
!ll&&!rl&&r
110
MC/DC0%0/2
$method eq "oauth2" and not $o
$method eq "oauth2" not $o
Truth table66%2/3
A and not(B)
A= $method eq "oauth2"B= not $o
ABresult
0X0
100
111
247 0 print "OAuth2 advertised, but no usable Thunderbird client registration was found.\n";
248 0 next;
249 }
250 2 ▶ print "\n# ", $method eq "oauth2" ? "OAuth2" : "Password", ":\n";
Branch: 1 branch
BranchTrueFalseTotal
$method eq 'oauth2' ? : 1 1 2
251 2 ▶ print "# Thunderbird's OAuth client registration may not be authorized for other applications.\n"
Branch: 1 branch
BranchTrueFalseTotal
if $method eq "oauth2" 1 1 2
252 if $method eq "oauth2";
253 2 ▶ print "# OAuth2 requires a refresh token; provider-specific offline access parameters may be needed.\n"
Branch: 1 branch
BranchTrueFalseTotal
if $method eq "oauth2" 1 1 2
254 if $method eq "oauth2";
255 2 print_login ($name, $server, $method, $o);
256 }
257 }
258 }
259  
260 5 1;
« blib/lib/AnyEvent/MCP/Server/Permissions.pm ↑ Summary blib/lib/AnyEvent/MCP.pm »