File Coverage

lib/Sisimai/Rhost/Spectrum.pm
Criterion Covered Total %
statement 23 23 100.0
branch 5 8 62.5
condition 3 4 75.0
subroutine 4 4 100.0
pod 0 1 0.0
total 35 40 87.5


line stmt bran cond sub pod time code
1             package Sisimai::Rhost::Spectrum;
2 4     4   1524 use feature ':5.10';
  4         9  
  4         379  
3 4     4   23 use strict;
  4         9  
  4         83  
4 4     4   20 use warnings;
  4         7  
  4         1189  
5              
6             sub get {
7             # Detect bounce reason from https://www.spectrum.com/
8             # @param [Sisimai::Data] argvs Parsed email object
9             # @return [String] The bounce reason at Spectrum
10             # @since v4.25.8
11 7     7 0 903 my $class = shift;
12 7   100     30 my $argvs = shift // return undef;
13              
14 6         36 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' => 'blocked', # Your IP address has been blocked due to suspicious activity.
26             '1010' => 'rejected', # This email account has been blocked from sending emails due to suspicious activity.
27             '1090' => 'systemerror', # The email you're trying to send can't be processed. Try sending again at a later time.
28             '1260' => 'networkerror', # Spectrum doesn't process IPV6 addresses. Connect with an IPv4 address and try again.
29             '1500' => 'rejected', # Your email was rejected for attempting to send as a different email address than you signed in under.
30             '1520' => 'rejected', # Your email was rejected for attempting to send as a different email address than a domain that we host.
31             '1530' => 'mesgtoobig', # Your email was rejected because it's larger than the maximum size of 20MB.
32             '1540' => 'toomanyconn', # Your emails were deferred for attempting to send too many in a single session.
33             '1550' => 'toomanyconn', # Your email was rejected for having too many recipients in one message.
34             '1560' => 'policyviolation', # Your email was rejected for having too many invalid recipients.
35             };
36 6         23 state $coderanges = [
37             [1020, 1080, 'rejected'], # This email account has limited access to send emails based on suspicious activity.
38             [1100, 1150, 'blocked'], # The IP address you're trying to connect from has an issue with the Domain Name System.
39             [1160, 1190, 'policyviolation'], # The email you tried to send goes against your domain's security policies.
40             [1200, 1210, 'blocked'], # The IP address you're trying to send from has been flagged by Cloudmark CSI as potential spam.
41             [1220, 1250, 'blokced'], # Your IP address has been blacklisted by Spamhaus.
42             [1300, 1340, 'toomanyconn'], # Spectrum limits the number of concurrent connections from a sender
43             [1350, 1490, 'toomanyconn'], # Spectrum limits emails by the number of messages sent, amount of recipients,...
44             ];
45 6         23 my $statusmesg = $argvs->diagnosticcode;
46 6 50       82 my $codenumber = $statusmesg =~ m/AUP#[-A-Za-z]*(\d{4})/ ? int $1 : 0;
47 6   50     34 my $reasontext = $errorcodes->{ $codenumber } || '';
48              
49 6 50       16 unless( $reasontext ) {
50             # The error code was not found in $errorcodes
51 6         17 for my $e ( @$coderanges ) {
52             # Check the code range
53 36 50       98 next if $codenumber < $e->[0];
54 36 100       68 next if $codenumber > $e->[1];
55 6         14 $reasontext = $e->[2];
56 6         11 last;
57             }
58             }
59 6         31 return $reasontext;
60             }
61              
62             1;
63             __END__