File Coverage

lib/Sisimai/Rhost/NTTDOCOMO.pm
Criterion Covered Total %
statement 28 29 96.5
branch 11 14 78.5
condition 7 11 63.6
subroutine 4 4 100.0
pod 0 1 0.0
total 50 59 84.7


line stmt bran cond sub pod time code
1             package Sisimai::Rhost::NTTDOCOMO;
2 5     5   1511 use feature ':5.10';
  5         11  
  5         444  
3 5     5   30 use strict;
  5         9  
  5         116  
4 5     5   24 use warnings;
  5         10  
  5         1954  
5              
6             sub get {
7             # Detect bounce reason from NTT DOCOMO
8             # @param [Sisimai::Data] argvs Parsed email object
9             # @return [String] The bounce reason for docomo.ne.jp
10             # @since v4.25.15
11 50     50 0 1010 my $class = shift;
12 50   100     180 my $argvs = shift // return undef;
13              
14 49         411 my $messagesof = {
15             'mailboxfull' => qr/552 too much mail data/,
16             'toomanyconn' => qr/552 too many recipients/,
17             'syntaxerror' => qr/(?:503 bad sequence of commands|504 command parameter not implemented)/,
18             };
19 49   50     1030 my $statuscode = $argvs->{'deliverystatus'} || '';
20 49   50     145 my $commandtxt = $argvs->{'smtpcommand'} || '';
21 49   50     208 my $esmtperror = lc $argvs->{'diagnosticcode'} || '';
22 49         79 my $reasontext = '';
23              
24             # Check the value of Status: field, an SMTP Reply Code, and the SMTP Command
25 49 100 66     320 if( $statuscode eq '5.1.1' || $statuscode eq '5.0.911' ) {
    100          
26             # ----- Transcript of session follows -----
27             # ... while talking to mfsmax.docomo.ne.jp.:
28             # >>> RCPT To:<***@docomo.ne.jp>
29             # <<< 550 Unknown user ***@docomo.ne.jp
30             # 550 5.1.1 <***@docomo.ne.jp>... User unknown
31             # >>> DATA
32             # <<< 503 Bad sequence of commands
33 4         7 $reasontext = 'userunknown';
34              
35             } elsif( $statuscode eq '5.2.0' ) {
36             # ----- The following addresses had permanent fatal errors -----
37             # <***@docomo.ne.jp>
38             # (reason: 550 Unknown user ***@docomo.ne.jp)
39             #
40             # ----- Transcript of session follows -----
41             # ... while talking to mfsmax.docomo.ne.jp.:
42             # >>> DATA
43             # <<< 550 Unknown user ***@docomo.ne.jp
44             # 554 5.0.0 Service unavailable
45             # ...
46             # Final-Recipient: RFC822; ***@docomo.ne.jp
47             # Action: failed
48             # Status: 5.2.0
49 14         34 $reasontext = 'filtered';
50              
51             } else {
52             # The value of "Diagnostic-Code:" field is not empty
53 31         124 for my $e ( keys %$messagesof ) {
54             # Try to match the value of "diagnosticcode"
55 76 100       394 next unless $esmtperror =~ $messagesof->{ $e };
56 19         39 $reasontext = $e;
57 19         34 last;
58             }
59             }
60 49 100       278 return $reasontext if length $reasontext;
61              
62             # A bounce reason did not decide from a status code, an error message.
63 12 50       44 if( $statuscode eq '5.0.0' ) {
64             # Status: 5.0.0
65 12 50       81 if( $commandtxt eq 'RCPT' ) {
    50          
66             # Your message to the following recipients cannot be delivered:
67             #
68             # <***@docomo.ne.jp>:
69             # mfsmax.docomo.ne.jp [203.138.181.112]:
70             # >>> RCPT TO:<***@docomo.ne.jp>
71             # <<< 550 Unknown user ***@docomo.ne.jp
72             # ...
73             #
74             # Final-Recipient: rfc822; ***@docomo.ne.jp
75             # Action: failed
76             # Status: 5.0.0
77             # Remote-MTA: dns; mfsmax.docomo.ne.jp [203.138.181.112]
78             # Diagnostic-Code: smtp; 550 Unknown user ***@docomo.ne.jp
79 0         0 $reasontext = 'userunknown';
80              
81             } elsif( $commandtxt eq 'DATA' ) {
82             # <***@docomo.ne.jp>: host mfsmax.docomo.ne.jp[203.138.181.240] said:
83             # 550 Unknown user ***@docomo.ne.jp (in reply to end of DATA
84             # command)
85             # ...
86             # Final-Recipient: rfc822; ***@docomo.ne.jp
87             # Original-Recipient: rfc822;***@docomo.ne.jp
88             # Action: failed
89             # Status: 5.0.0
90             # Remote-MTA: dns; mfsmax.docomo.ne.jp
91             # Diagnostic-Code: smtp; 550 Unknown user ***@docomo.ne.jp
92 12         32 $reasontext = 'rejected';
93              
94             } else {
95             # Rejected by other SMTP commands: AUTH, MAIL,
96             # もしもこのブロックを通過するNTTドコモからのエラーメッセージを見つけたら
97             # https://github.com/sisimai/p5-sisimai/issues からご連絡ねがいます。
98             #
99             # If you found a error message from mfsmax.docomo.ne.jp which passes this block,
100             # please open an issue at https://github.com/sisimai/p5-sisimai/issues .
101             }
102             } else {
103             # Status: field is neither 5.0.0 nor values defined in code above
104             # もしもこのブロックを通過するNTTドコモからのエラーメッセージを見つけたら
105             # https://github.com/sisimai/p5-sisimai/issues からご連絡ねがいます。
106             #
107             # If you found a error message from mfsmax.docomo.ne.jp which passes this block,
108             # please open an issue at https://github.com/sisimai/p5-sisimai .
109             }
110 12         67 return $reasontext;
111             }
112              
113             1;
114             __END__