File Coverage

lib/Sisimai/Rhost/Facebook.pm
Criterion Covered Total %
statement 22 22 100.0
branch 5 6 83.3
condition 2 2 100.0
subroutine 4 4 100.0
pod 0 1 0.0
total 33 35 94.2


line stmt bran cond sub pod time code
1             package Sisimai::Rhost::Facebook;
2 5     5   1350 use v5.26;
  5         19  
3 5     5   28 use strict;
  5         9  
  5         148  
4 5     5   21 use warnings;
  5         9  
  5         2158  
5              
6             sub find {
7             # Detect bounce reason for Facebook
8             # @param [Sisimai::Fact] argvs Decoded email object
9             # @return [String] Detected bounce reason
10             # @see https://www.facebook.com/postmaster/response_codes
11             # @since v5.2.0
12 17     17 0 1134 my $class = shift;
13 17   100     66 my $argvs = shift // return "";
14 16 100       70 return "" unless $argvs->{'diagnosticcode'};
15 15 50       64 return "" unless index($argvs->{'diagnosticcode'}, '-');
16              
17 15         93 state $errorcodes = {
18             # http://postmaster.facebook.com/response_codes
19             # NOT TESTD EXCEPT RCP-P2
20             "authfailure" => [
21             "POL-P7", # The message does not comply with Facebook's Domain Authentication requirements.
22             ],
23             "blocked" => [
24             "POL-P1", # Your mail server's IP Address is listed on the Spamhaus PBL.
25             "POL-P2", # Facebook will no longer accept mail from your mail server's IP Address.
26             "POL-P3", # Facebook is not accepting messages from your mail server. This will persist for 4 to 8 hours.
27             "POL-P4", # ". This will persist for 24 to 48 hours.
28             "POL-T1", # ", but they may be retried later. This will persist for 1 to 2 hours.
29             "POL-T2", # ", but they may be retried later. This will persist for 4 to 8 hours.
30             "POL-T3", # ", but they may be retried later. This will persist for 24 to 48 hours.
31             ],
32             "contenterror" => [
33             "MSG-P2", # The message contains an attachment type that Facebook does not accept.
34             ],
35             "emailtoolarge" => [
36             "MSG-P1", # The message exceeds Facebook's maximum allowed size.
37             "INT-P2", # The message exceeds Facebook's maximum allowed size.
38             ],
39             "filtered" => [
40             "RCP-P2", # The attempted recipient's preferences prevent messages from being delivered.
41             "RCP-P3", # The attempted recipient's privacy settings blocked the delivery.
42             ],
43             "mailboxfull" => [
44             "INT-P7", # The attempted recipient has exceeded their storage quota.
45             ],
46             "policyviolation" => [
47             "POL-P8", # The message does not comply with Facebook's abuse policies and will not be accepted.
48             ],
49             "notcompliantrfc" => [
50             "MSG-P3", # The message contains multiple instances of a header field that can only be present once.
51             ],
52             "ratelimited" => [
53             "CON-T1", # Facebook's mail server currently has too many connections open to allow another one.
54             "CON-T2", # Your mail server currently has too many connections open to Facebook's mail servers.
55             "CON-T3", # Your mail server has opened too many new connections to Facebook's mail servers in a short period of time.
56             "CON-T4", # Your mail server has exceeded the maximum number of recipients for its current connection.
57             "MSG-T1", # The number of recipients on the message exceeds Facebook's allowed maximum.
58             ],
59             "rejected" => [
60             "DNS-P1", # Your SMTP MAIL FROM domain does not exist.
61             "DNS-P2", # Your SMTP MAIL FROM domain does not have an MX record.
62             "DNS-T1", # Your SMTP MAIL FROM domain exists but does not currently resolve.
63             ],
64             "requireptr" => [
65             "DNS-P3", # Your mail server does not have a reverse DNS record.
66             "DNS-T2", # You mail server's reverse DNS record does not currently resolve.
67             ],
68             "spamdetected" => [
69             "POL-P6", # The message contains a url that has been blocked by Facebook.
70             ],
71             "suspend" => [
72             "RCP-T4", # The attempted recipient address is currently deactivated. The user may or may not reactivate it.
73             ],
74             "systemerror" => [
75             "RCP-T1", # The attempted recipient address is not currently available due to an internal system issue.
76             "INT-Tx", # These codes indicate a temporary issue internal to Facebook's system.
77             ],
78             "userunknown" => [
79             "RCP-P1", # The attempted recipient address does not exist.
80             "INT-P1", # The attempted recipient address does not exist.
81             "INT-P3", # The attempted recipient group address does not exist.
82             "INT-P4", # The attempted recipient address does not exist.
83             ],
84             "virusdetected" => [
85             "POL-P5", # The message contains a virus.
86             ],
87             };
88 15         40 my $errorindex = index($argvs->{'diagnosticcode'}, "-");
89 15         48 my $errorlabel = substr($argvs->{'diagnosticcode'}, $errorindex - 3, 6);
90 15         29 my $reasontext = "";
91              
92 15         105 for my $e ( keys %$errorcodes ) {
93             # The key is a bounce reason name
94 144 100       250 next unless grep { $errorlabel eq $_ } $errorcodes->{ $e }->@*;
  329         748  
95 13         25 $reasontext = $e; last
96 13         25 }
97 15         85 return $reasontext;
98             }
99              
100             1;
101             __END__