File Coverage

lib/Sisimai/SMTP/Reply.pm
Criterion Covered Total %
statement 18 18 100.0
branch 5 6 83.3
condition 5 5 100.0
subroutine 4 4 100.0
pod 1 1 100.0
total 33 34 97.0


line stmt bran cond sub pod time code
1             package Sisimai::SMTP::Reply;
2 78     78   59404 use feature ':5.10';
  78         156  
  78         4876  
3 78     78   394 use strict;
  78         143  
  78         1670  
4 78     78   475 use warnings;
  78         161  
  78         21081  
5              
6             # http://www.ietf.org/rfc/rfc5321.txt
7             # 4.2.1. Reply Code Severities and Theory
8             # 2yz Positive Completion reply
9             # 3yz Positive Intermediate reply
10             # 4yz Transient Negative Completion reply
11             # 5yz Permanent Negative Completion reply
12             #
13             # x0z Syntax: These replies refer to syntax errors, syntactically
14             # correct commands that do not fit any functional category, and
15             # unimplemented or superfluous commands.
16             # x1z Information: These are replies to requests for information, such
17             # as status or help.
18             # x2z Connections: These are replies referring to the transmission
19             # channel.
20             # x3z Unspecified.
21             # x4z Unspecified.
22             # x5z Mail system: These replies indicate the status of the receiver
23             # mail system vis-a-vis the requested transfer or other mail system
24             # action.
25             #
26             # 4.2.3. Reply Codes in Numeric Order
27             # 211 System status, or system help reply
28             # 214 Help message (Information on how to use the receiver or the
29             # meaning of a particular non-standard command; this reply is useful
30             # only to the human user)
31             # 220 Service ready
32             # 221 Service closing transmission channel
33             # 250 Requested mail action okay, completed
34             # 251 User not local; will forward to (See Section 3.4)
35             # 252 Cannot VRFY user, but will accept message and attempt delivery
36             # (See Section 3.5.3)
37             # 354 Start mail input; end with .
38             # 421 Service not available, closing transmission channel
39             # (This may be a reply to any command if the service knows it must
40             # shut down)
41             # 450 Requested mail action not taken: mailbox unavailable (e.g.,
42             # mailbox busy or temporarily blocked for policy reasons)
43             # 451 Requested action aborted: local error in processing
44             # 452 Requested action not taken: insufficient system storage
45             # 455 Server unable to accommodate parameters
46             # 500 Syntax error, command unrecognized (This may include errors such
47             # as command line too long)
48             # 501 Syntax error in parameters or arguments
49             # 502 Command not implemented (see Section 4.2.4)
50             # 503 Bad sequence of commands
51             # 504 Command parameter not implemented
52             # 550 Requested action not taken: mailbox unavailable (e.g., mailbox
53             # not found, no access, or command rejected for policy reasons)
54             # 551 User not local; please try (See Section 3.4)
55             # 552 Requested mail action aborted: exceeded storage allocation
56             # 553 Requested action not taken: mailbox name not allowed (e.g.,
57             # mailbox syntax incorrect)
58             # 554 Transaction failed (Or, in the case of a connection-opening
59             # response, "No SMTP service here")
60             # 555 MAIL FROM/RCPT TO parameters not recognized or not implemented
61             #
62             sub find {
63             # Get an SMTP reply code from the given string
64             # @param [String] argv1 String including SMTP reply code like 550
65             # @return [String] SMTP reply code or empty if the first argument
66             # did not include SMTP Reply Code value
67             # @since v4.14.0
68 5168     5168 1 57894 my $class = shift;
69 5168   100     9992 my $argv1 = shift || return undef;
70 5115 50       14986 return '' if uc($argv1) =~ /X-UNIX;/;
71              
72 5115         6396 my $value = '';
73 5115         5861 state $ip4re = qr{\b
74             (?:\d|[01]?\d\d|2[0-4]\d|25[0-5])[.]
75             (?:\d|[01]?\d\d|2[0-4]\d|25[0-5])[.]
76             (?:\d|[01]?\d\d|2[0-4]\d|25[0-5])[.]
77             (?:\d|[01]?\d\d|2[0-4]\d|25[0-5])
78             \b}x;
79              
80              
81             # Convert found IPv4 addresses to '***.***.***.***' to avoid that the
82             # following code detects an octet of the IPv4 adress as an SMTP reply
83             # code.
84 5115 100       41216 $argv1 =~ s/$ip4re/***.***.***.***/g if $argv1 =~ $ip4re;
85              
86 5115 100 100     30510 if( $argv1 =~ /\b([45][0-5][0-9])\b/ || $argv1 =~ /\b(25[0-3])\b/ ) {
87             # 550, 447, or 250
88 2891         5390 $value = $1;
89             }
90 5115         15070 return $value;
91             }
92              
93             1;
94             __END__