1package Sisimai::Reason::NotAccept;
2use feature ':5.10';
3use strict;
4use warnings;
5
6sub text  { 'notaccept' }
7sub description { 'Delivery failed due to a destination mail server does not accept any email' }
8sub match {
9    # Try to match that the given text and regular expressions
10    # @param    [String] argv1  String to be matched with regular expressions
11    # @return   [Integer]       0: Did not match
12    #                           1: Matched
13    # @since v4.0.0
14    my $class = shift;
15    my $argv1 = shift // return undef;
16
17    # Destination mail server does not accept any message
18    state $index = [
19        'host/domain does not accept mail', # iCloud
20        'host does not accept mail',        # Sendmail
21        'name server: .: host not found',   # Sendmail
22        'no mx record found for domain=',   # Oath(Yahoo!)
23        'no route for current request',
24        'smtp protocol returned a permanent error',
25    ];
26    return 1 if grep { rindex($argv1, $_) > -1 } @$index;
27    return 0;
28}
29
30sub true {
31    # Remote host does not accept any message
32    # @param    [Sisimai::Data] argvs   Object to be detected the reason
33    # @return   [Integer]               1: Not accept
34    #                                   0: Accept
35    # @since v4.0.0
36    # @see http://www.ietf.org/rfc/rfc2822.txt
37    my $class = shift;
38    my $argvs = shift // return undef;
39    return 1 if $argvs->reason eq 'notaccept';
40
41    # SMTP Reply Code is 521, 554 or 556
42    return 1 if $argvs->replycode =~ /\A(?:521|554|556)\z/;
43    return 0 unless $argvs->smtpcommand eq 'MAIL';
44    return 1 if __PACKAGE__->match(lc $argvs->diagnosticcode);
45    return 0;
46}
47
481;
49__END__
50
51=encoding utf-8
52
53=head1 NAME
54
55Sisimai::Reason::NotAccept - Bounce reason is C<notaccept> or not.
56
57=head1 SYNOPSIS
58
59    use Sisimai::Reason::NotAccept;
60    print Sisimai::Reason::NotAccept->match('domain does not exist:');   # 1
61
62=head1 DESCRIPTION
63
64Sisimai::Reason::NotAccept checks the bounce reason is C<notaccept> or not.
65This class is called only Sisimai::Reason class.
66
67This is the error that a destination mail server does ( or can ) not accept any
68email. In many case, the server is high load or under the maintenance.  Sisimai
69will set C<notaccept> to the reason of email bounce if the value of Status:
70field in a bounce email is C<5.3.2> or the value of SMTP reply code is 556.
71
72=head1 CLASS METHODS
73
74=head2 C<B<text()>>
75
76C<text()> returns string: C<notaccept>.
77
78    print Sisimai::Reason::NotAccept->text;  # notaccept
79
80=head2 C<B<match(I<string>)>>
81
82C<match()> returns 1 if the argument matched with patterns defined in this class.
83
84    print Sisimai::Reason::NotAccept->match('domain does not exist:');   # 1
85
86=head2 C<B<true(I<Sisimai::Data>)>>
87
88C<true()> returns 1 if the bounce reason is C<notaccept>. The argument must be
89Sisimai::Data object and this method is called only from Sisimai::Reason class.
90
91=head1 AUTHOR
92
93azumakuniyuki
94
95=head1 COPYRIGHT
96
97Copyright (C) 2014-2016,2018,2020,2021 azumakuniyuki, All rights reserved.
98
99=head1 LICENSE
100
101This software is distributed under The BSD 2-Clause License.
102
103=cut
104