File Coverage

lib/Sisimai/Rhost/GSuite.pm
Criterion Covered Total %
statement 26 26 100.0
branch 10 14 71.4
condition 9 20 45.0
subroutine 4 4 100.0
pod 0 1 0.0
total 49 65 75.3


line stmt bran cond sub pod time code
1             package Sisimai::Rhost::GSuite;
2 6     6   1412 use v5.26;
  6         44  
3 6     6   39 use strict;
  6         12  
  6         214  
4 6     6   31 use warnings;
  6         14  
  6         2515  
5              
6             sub find {
7             # Detect bounce reason from Google Workspace (formerly G Suite) https://workspace.google.com/
8             # @param [Sisimai::Fact] argvs Decoded email object
9             # @return [String] The bounce reason for GSuite
10             # @since v5.2.0
11 147     147 0 1426 my $class = shift;
12 147 100 100     584 my $argvs = shift // return ""; return '' unless length $argvs->{'diagnosticcode'};
  146         665  
13              
14 145         315 state $messagesof = {
15             "hostunknown" => [" responded with code NXDOMAIN", "Domain name not found"],
16             "networkerror" => [" had no relevant answers.", "responded with code NXDOMAIN", "Domain name not found"],
17             "notaccept" => ["Null MX"],
18             "userunknown" => ["because the address couldn't be found. Check for typos or unnecessary spaces and try again."],
19             };
20 145 100       346 my $statuscode = ""; $statuscode = substr($argvs->{'deliverystatus'}, 0, 1) if $argvs->{'deliverystatus'};
  145         850  
21 145 100       288 my $esmtpreply = ""; $esmtpreply = substr($argvs->{'replycode'}, 0, 1) if $argvs->{'replycode'};
  145         598  
22 145         266 my $reasontext = "";
23              
24 145         553 for my $e ( keys %$messagesof ) {
25             # The key is a bounce reason name
26 460 100       894 next unless grep { index($argvs->{'diagnosticcode'}, $_) > -1 } $messagesof->{ $e }->@*;
  782         1948  
27 117 50 33     511 next if $e eq "networkerror" && ($statuscode eq "5" || $esmtpreply eq "5");
      66        
28 117 50 33     417 next if $e eq "hostunknown" && ($statuscode eq "4" || $statuscode eq "");
      66        
29 88 0 0     247 next if $e eq "hostunknown" && ($esmtpreply eq "4" || $esmtpreply eq "");
      33        
30 88         167 $reasontext = $e; last;
  88         141  
31             }
32 145         600 return $reasontext;
33             }
34              
35             1;
36             __END__