File Coverage

lib/Sisimai/Rhost/Zoho.pm
Criterion Covered Total %
statement 17 17 100.0
branch 4 4 100.0
condition 2 2 100.0
subroutine 4 4 100.0
pod 0 1 0.0
total 27 28 96.4


line stmt bran cond sub pod time code
1             package Sisimai::Rhost::Zoho;
2 7     7   2026 use v5.26;
  7         27  
3 7     7   43 use strict;
  7         10  
  7         183  
4 7     7   27 use warnings;
  7         14  
  7         1940  
5              
6             sub find {
7             # Detect bounce reason from Zoho Mail
8             # @param [Sisimai::Fact] argvs Decoded email object
9             # @return [String] The bounce reason for Zoho
10             # @see
11             # @since v5.5.0
12             # - Zoho Mail: https://www.zoho.com/mail/
13             # - Reasons an email is marked as Spam: https://www.zoho.com/mail/help/spam-reason.html
14             # - https://github.com/zoho/zohodesk-oas/blob/main/v1.0/EmailFailureAlert.json
15             # - Zoho SMTP Error Codes | SMTP Field Manual: https://smtpfieldmanual.com/provider/zoho
16 59     59 0 1041 my $class = shift;
17 59 100 100     198 my $argvs = shift // return ""; return '' unless length $argvs->{'diagnosticcode'};
  58         229  
18              
19 57         186 state $messagesof = {
20             'authfailure' => [
21             # - <*******@zoho.com>: host smtpin.zoho.com[204.141.33.23] said: 550 5.7.1 Email
22             # rejected per DMARC policy for zoho.com
23             "Email rejected per DMARC policy",
24             ],
25             'blocked' => [
26             # - mx.zoho.com[204.141.33.44]:25, delay=1202, delays=1200/0/0.91/0.30, dsn=4.7.1,
27             # status=deferred (host mx.zoho.com[204.141.33.44] said:
28             # 451 4.7.1 Greylisted, try again after some time (in reply to RCPT TO command))
29             "Greylisted, try again after some time",
30             ],
31             'rejected' => [
32             # - <*******@zoho.com>: host smtpin.zoho.com[204.141.33.23] said: 554 5.7.1 Email
33             # cannot be delivered. Reason: Email flagged as Spam. (in reply to RCPT TO command)
34             # - <***@zoho.com>: host mx.zoho.com[136.143.183.44] said: 541 5.4.1 Mail rejected
35             # by destination domain (in reply to RCPT TO command)
36             "Email cannot be delivered. Reason: Email flagged as Spam",
37             "Mail rejected by destination domain",
38             ],
39             'policyviolation' => [
40             # - <*******@zoho.com>: host smtpin.zoho.com[204.141.33.23] said: 554 5.7.7 Email
41             # policy violation detected (in reply to end of DATA command)
42             "Email policy violation detected",
43             "Mailbox delivery restricted by policy error",
44             ],
45             'systemerror' => [
46             # - https://github.com/zoho/zohodesk-oas/blob/main/v1.0/EmailFailureAlert.json#L168
47             # 452 4.3.1 Temporary System Error
48             "Temporary System Error",
49             ],
50             'userunknown' => [
51             # - <*******@zoho.com>: host smtpin.zoho.com[204.141.33.23] said:
52             # 550 5.1.1 User does not exist - <***@zoho.com> (in reply to RCPT TO command)
53             # - 552 5.1.1 <****@zoho.com> Mailbox delivery failure policy error
54             "User does not exist",
55             ],
56             'virusdetected' => [
57             # - 552 5.7.1 virus **** detected by Zoho Mail
58             " detected by Zoho Mail",
59             ],
60             };
61              
62 57         263 for my $e ( keys %$messagesof ) {
63             # Try to find the error message matches with the given error message string
64 292 100       504 next unless grep { index($argvs->{'diagnosticcode'}, $_) > -1 } $messagesof->{ $e }->@*;
  399         1034  
65 29         136 return $e;
66             }
67 28         153 return "";
68             }
69              
70             1;
71             __END__