File Coverage

lib/Sisimai/Rhost/Spectrum.pm
Criterion Covered Total %
statement 23 25 92.0
branch 11 12 91.6
condition 2 2 100.0
subroutine 4 4 100.0
pod 0 1 0.0
total 40 44 90.9


line stmt bran cond sub pod time code
1             package Sisimai::Rhost::Spectrum;
2 4     4   2812 use v5.26;
  4         15  
3 4     4   21 use strict;
  4         19  
  4         107  
4 4     4   18 use warnings;
  4         7  
  4         1677  
5              
6             sub find {
7             # Detect bounce reason from https://www.spectrum.com/
8             # @param [Sisimai::Fact] argvs Decoded email object
9             # @return [String] The bounce reason at Spectrum
10             # @since v4.25.8
11 10     10 0 628 my $class = shift;
12 10 100 100     35 my $argvs = shift // return ""; return "" unless $argvs->{'diagnosticcode'};
  9         58  
13              
14 8         40 state $errorcodes = [
15             # https://www.spectrumbusiness.net/support/internet/understanding-email-error-codes
16             # Error codes are placed in one of two categories: incoming or outgoing.
17             # 1. If you're trying to send an email to a Charter email address from
18             # a non-Charter email address (such as Gmail, Yahoo, Hotmail, etc.),
19             # you may receive an error that begins with AUP#I, followed by four numbers.
20             #
21             # 2. If you are trying to send an email from a Charter email address
22             # to an outgoing recipient, you may get an error code beginning with
23             # AUP#O, also followed by four numbers.
24             #
25             # 1000 Your IP address has been blocked due to suspicious activity. If you're a Spectrum
26             # customer using a Spectrum-issued IP, contact us. If you're using an IP address other
27             # than one provided by Spectrum, blocks will remain in place until they expire.
28             [1000, 0, 'blocked'],
29              
30             # 1010 This email account has been blocked from sending emails due to suspicious activity.
31             # Blocks will expire based on the nature of the activity. If you're a Spectrum customer,
32             # change all of your Spectrum passwords to secure your account and then contact us.
33             [1010, 0, 'rejected'],
34              
35             # 1020 This email account has limited access to send emails based on suspicious activity.
36             # 1080 Blocks will expire based on the nature of the activity.
37             # If you're a Spectrum customer, contact us to remove the block.
38             [1020, 1080, 'rejected'],
39              
40             # 1090 The email you're trying to send can't be processed. Try sending again at a later time.
41             [1090, 0, 'systemerror'],
42              
43             # 1100 The IP address you're trying to connect from has an issue with the Domain Name System.
44             # 1150 Spectrum requires a full circle DNS for emails to be allowed through. Verify the IP
45             # you're connecting from, and check the IP address to ensure a reverse DNS entry exists
46             # for the IP. If the IP address is a Spectrum-provided email address, contact us.
47             [1100, 1150, 'requireptr'],
48              
49             # 1160 The email you tried to send goes against your domain's security policies.
50             # 1190 Please contact the email administrators of your domain.
51             [1160, 1190, 'policyviolation'],
52              
53             # 1200 The IP address you're trying to send from has been flagged by Cloudmark CSI as
54             # 1210 potential spam. Have your IP administrator request a reset.
55             # Note: Cloudmark has sole discretion whether to remove the sending IP address from
56             # their lists.
57             [1200, 1210, 'blocked'],
58              
59             # 1220 Your IP address has been blacklisted by Spamhaus. The owner of the IP address must
60             # 1250 contact Spamhaus to be removed from the list.
61             # Note: Spamhaus has sole discretion whether to remove the sending IP address from
62             # their lists.
63             [1220, 1250, 'blokced'],
64              
65             # 1260 Spectrum doesn't process IPV6 addresses. Connect with an IPv4 address and try again.
66             [1260, 0, 'networkerror'],
67              
68             # 1300 Spectrum limits the number of concurrent connections from a sender, as well as the
69             # 1340 total number of connections allowed. Limits vary based on the reputation of the IP
70             # address. Reduce your number of connections and try again later.
71             [1300, 1340, 'ratelimited'],
72              
73             # 1350 Spectrum limits emails by the number of messages sent, amount of recipients,
74             # 1490 potential for spam and invalid recipients.
75             [1350, 1490, 'ratelimited'],
76              
77             # 1500 Your email was rejected for attempting to send as a different email address than you
78             # signed in under. Check that you're sending emails from the address you signed in with.
79             [1500, 0, 'rejected'],
80              
81             # 1520 Your email was rejected for attempting to send as a different email address than a
82             # domain that we host. Check the outgoing email address and try again.
83             [1520, 0, 'rejected'],
84              
85             # 1530 Your email was rejected because it's larger than the maximum size of 20MB.
86             [1530, 0, 'emailtoolarge'],
87              
88             # 1540 Your emails were deferred for attempting to send too many in a single session.
89             # Reconnect and try reducing the number of emails you send at one time.
90             [1540, 0, 'ratelimited'],
91              
92             # 1550 Your email was rejected for having too many recipients in one message. Reduce the
93             # number of recipients and try again later.
94             [1550, 0, 'ratelimited'],
95              
96             # 1560 Your email was rejected for having too many invalid recipients. Check your outgoing
97             # email addresses and try again later.
98             [1560, 0, 'ratelimited'],
99              
100             # 1580 You've tried to send messages to too many recipients in a short period of time.
101             # Wait a little while and try again later.
102             [1580, 0, 'ratelimited'],
103             ];
104 8         20 my $issuedcode = $argvs->{'diagnosticcode'};
105 8 100       79 my $codenumber = $issuedcode =~ m/AUP#[-A-Za-z]*(\d{4})/ ? int $1 : 0;
106 8         18 my $reasontext = '';
107              
108 8         54 for my $e ( @$errorcodes ) {
109             # Try to find an error code matches with the code in the value of $diagnosticcode
110 96 50       171 if( $codenumber == $e->[0] ) {
111             # [1500, 0, 'reason'] or [1500, 1550, 'reason']
112 0         0 $reasontext = $e->[2];
113 0         0 last;
114              
115             } else {
116             # Check the code number is inlcuded the range like [1500, 1550, 'reason']
117 96 100       153 next if $e->[1] == 0;
118 50 100       97 next if $codenumber < $e->[0];
119 36 100       88 next if $codenumber > $e->[1];
120              
121 6         17 $reasontext = $e->[2];
122 6         19 last;
123             }
124             }
125 8         42 return $reasontext;
126             }
127              
128             1;
129             __END__