File Coverage

lib/Sisimai/SMTP/Status.pm
Criterion Covered Total %
statement 138 139 99.2
branch 92 104 88.4
condition 75 88 85.2
subroutine 13 13 100.0
pod 7 7 100.0
total 325 351 92.5


line stmt bran cond sub pod time code
1             package Sisimai::SMTP::Status;
2 91     91   200319 use v5.26;
  91         309  
3 91     91   467 use strict;
  91         145  
  91         2116  
4 91     91   378 use warnings;
  91         150  
  91         8466  
5 91     91   2252 use Sisimai::RFC791;
  91         176  
  91         51462  
6              
7             # http://www.iana.org/assignments/smtp-enhanced-status-codes/smtp-enhanced-status-codes.xhtml
8             # -------------------------------------------------------------------------------------------------
9             # [Class Sub-Codes]
10             # 2.X.Y Success
11             # 4.X.Y Persistent Transient Failure
12             # 5.X.Y Permanent Failure
13             #
14             # -------------------------------------------------------------------------------------------------
15             # [Subject Sub-Codes]
16             # X.0.X --- Other or Undefined Status
17             # There is no additional subject information available.
18             #
19             # X.1.X --- Addressing Status
20             # The address status reports on the originator or destination address. It may include
21             # address syntax or validity. These errors can generally be corrected by the sender and
22             # retried.
23             #
24             # X.2.X --- Mailbox Status
25             # Mailbox status indicates that something having to do with the mailbox has caused this
26             # DSN. Mailbox issues are assumed to be under the general control of the recipient.
27             #
28             # X.3.X --- Mail System Status
29             # Mail system status indicates that something having to do with the destination system
30             # has caused this DSN. System issues are assumed to be under the general control of the
31             # destination system administrator.
32             #
33             # X.4.X --- Network and Routing Status
34             # The networking or routing codes report status about the delivery system itself. These
35             # system components include any necessary infrastructure such as directory and routing
36             # services. Network issues are assumed to be under the control of the destination or
37             # intermediate system administrator.
38             #
39             # X.5.X --- Mail Delivery Protocol Status
40             # The mail delivery protocol status codes report failures involving the message delivery
41             # protocol. These failures include the full range of problems resulting from
42             # implementation errors or an unreliable connection.
43             #
44             # X.6.X --- Message Content or Media Status
45             # The message content or media status codes report failures involving the content of the
46             # message. These codes report failures due to translation, transcoding, or otherwise
47             # unsupported message media. Message content or media issues are under the control of both
48             # the sender and the receiver, both of which must support a common set of supported
49             # content-types.
50             #
51             # X.7.X --- Security or Policy Status
52             # The security or policy status codes report failures involving policies such as
53             # per-recipient or per-host filtering and cryptographic operations. Security and policy
54             # status issues are assumed to be under the control of either or both the sender and
55             # recipient. Both the sender and recipient must permit the exchange of messages and
56             # arrange the exchange of necessary keys and certificates for cryptographic operations.
57             #
58             # -------------------------------------------------------------------------------------------------
59             # [Enumerated Status Codes]
60             # X.0.0 Any Other undefined Status:(RFC 3463)
61             # Other undefined status is the only undefined error code. It should be used for all
62             # errors for which only the class of the error is known.
63             #
64             # X.1.0 --- Other address status:(RFC 3463)
65             # Something about the address specified in the message caused this DSN.
66             #
67             # X.1.1 451 Bad destination mailbox address:(RFC3463)
68             # 550 The mailbox specified in the address does not exist. For Internet mail names, this
69             # means the address portion to the the left of the "@" sign is invalid. This code is
70             # only useful for permanent failures.
71             #
72             # X.1.2 --- Bad destination system addres:
73             # The destination system specified in the address does not exist or is incapable of
74             # accepting mail. For Internet mail names, this means the address portion to the
75             # right of the "@" is invalid for mail. This code is only useful for permanent
76             # failures.
77             #
78             # X.1.3 501 Bad destination mailbox address syntax:
79             # The destination address was syntactically invalid. This can apply to any field in
80             # the address. This code is only useful for permanent failures.
81             #
82             # X.1.4 --- Destination mailbox address ambiguous:(RFC 3463)
83             # The mailbox address as specified matches one or more recipients on the destination
84             # system. This may result if a heuristic address mapping algorithm is used to map
85             # the specified address to a local mailbox name.
86             #
87             # X.1.5 250 Destination address valid:(RFC 3463)
88             # This mailbox address as specified was valid. This status code should be used for
89             # positive delivery reports.
90             #
91             # X.1.6 --- Destination mailbox has moved, No forwarding address:(RFC 3463)
92             # The mailbox address provided was at one time valid, but mail is no longer being
93             # accepted for that address. This code is only useful for permanent failures.
94             #
95             # X.1.7 --- Bad sender's mailbox address syntax:(RFC 3463)
96             # The sender's address was syntactically invalid. This can apply to any field in
97             # the address.
98             #
99             # X.1.8 451 Bad sender's system address:(RFC 3463)
100             # 501 The sender's system specified in the address does not exist or is incapable of
101             # accepting return mail. For domain names, this means the address portion to the
102             # right of the "@" is invalid for mail.
103             #
104             # X.1.9 --- Message relayed to non-compliant mailer:(RFC 5248, 3886)
105             # The mailbox address specified was valid, but the message has been relayed to a
106             # system that does not speak this protocol; no further information can be provided.
107             #
108             # X.1.10 --- Recipient address has null MX:(RFC 7505)
109             # This status code is returned when the associated address is marked as invalid
110             # using a null MX.
111             # -------------------------------------------------------------------------------------------------
112             # X.2.0 --- Other or undefined mailbox status:(RFC 3463)
113             # The mailbox exists, but something about the destination mailbox has caused the
114             # sending of this DSN.
115             #
116             # X.2.1 --- Mailbox disabled, not accepting messages:(RFC 3463)
117             # The mailbox exists, but is not accepting messages. This may be a permanent error
118             # if the mailbox will never be re-enabled or a transient error if the mailbox is
119             # only temporarily disabled.
120             #
121             # X.2.2 552 Mailbox full:(RFC 3463)
122             # The mailbox is full because the user has exceeded a per-mailbox administrative
123             # quota or physical capacity. The general semantics implies that the recipient can
124             # delete messages to make more space available. This code should be used as a
125             # persistent transient failure.
126             #
127             # X.2.3 552 Message length exceeds administrative limit:(RFC 3463)
128             # A per-mailbox administrative message length limit has been exceeded. This status
129             # code should be used when the per-mailbox message length limit is less than the
130             # general system limit. This code should be used as a permanent failure.
131             #
132             # X.2.4 450 Mailing list expansion problem:(RFC 3463)
133             # 452 The mailbox is a mailing list address and the mailing list was unable to be
134             # expanded. This code may represent a permanent failure or a persistent transient
135             # failure.
136             # -------------------------------------------------------------------------------------------------
137             # X.3.0 221 Other or undefined mail system status:(RFC 3463)
138             # 250 The destination system exists and normally accepts mail, but something about the
139             # 421,451 system has caused the generation of this DSN.
140             # 550,554
141             #
142             # X.3.1 452 Mail system full:(RFC 3463)
143             # Mail system storage has been exceeded. The general semantics imply that the
144             # individual recipient may not be able to delete material to make room for
145             # additional messages. This is useful only as a persistent transient error.
146             #
147             # X.3.2 453 System not accepting network messages:(RFC 3463)
148             # 521 The host on which the mailbox is resident is not accepting messages. Examples of
149             # such conditions include an imminent shutdown, excessive load, or system
150             # maintenance. This is useful for both permanent and persistent transient errors.
151             #
152             # X.3.3 --- System not capable of selected features:(RFC 3463)
153             # Selected features specified for the message are not supported by the destination
154             # system. This can occur in gateways when features from one domain cannot be mapped
155             # onto the supported feature in another.
156             #
157             # X.3.4 552 Message too big for system:(RFC 3463)
158             # 554 The message is larger than per-message size limit. This limit may either be for
159             # physical or administrative reasons. This is useful only as a permanent error.
160             #
161             # X.3.5 --- System incorrectly configured:(RFC 3463)
162             # The system is not configured in a manner that will permit it to accept this
163             # message.
164             # -------------------------------------------------------------------------------------------------
165             # X.4.0 --- Other or undefined network or routing status:(RFC 3463)
166             # Something went wrong with the networking, but it is not clear what the problem is,
167             # or the problem cannot be well expressed with any of the other provided detail
168             # codes.
169             #
170             # X.4.1 451 No answer from host:(RFC 3463)
171             # The outbound connection attempt was not answered, because either the remote system
172             # was busy, or was unable to take a call. This is useful only as a persistent
173             # transient error.
174             #
175             # X.4.2 421 Bad connection:(RFC 3463)
176             # The outbound connection was established, but was unable to complete the message
177             # transaction, either because of time-out, or inadequate connection quality. This
178             # is useful only as a persistent transient error.
179             #
180             # X.4.3 451 Directory server failure:(RFC 3463)
181             # 550 The network system was unable to forward the message, because a directory server
182             # was unavailable. This is useful only as a persistent transient error. The
183             # inability to connect to an Internet DNS server is one example of the directory
184             # server failure error.
185             #
186             # X.4.4 --- Unable to route:(RFC 3463)
187             # The mail system was unable to determine the next hop for the message because the
188             # necessary routing information was unavailable from the directory server. This is
189             # useful for both permanent and persistent transient errors. A DNS lookup returning
190             # only an SOA (Start of Administration) record for a domain name is one example of
191             # the unable to route error.
192             #
193             # X.4.5 451 Mail system congestion:(RFC 3463)
194             # The mail system was unable to deliver the message because the mail system was
195             # congested. This is useful only as a persistent transient error.
196             #
197             # X.4.6 --- Routing loop detected:(RFC 3463)
198             # A routing loop caused the message to be forwarded too many times, either because
199             # of incorrect routing tables or a user-forwarding loop. This is useful only as a
200             # persistent transient error.
201             #
202             # X.4.7 --- Delivery time expired:(RFC 3463)
203             # The message was considered too old by the rejecting system, either because it
204             # remained on that host too long or because the time-to-live value specified by the
205             # sender of the message was exceeded. If possible, the code for the actual problem
206             # found when delivery was attempted should be returned rather than this code.
207             #
208             # X.4.8 421 Retry on IPv4
209             # 451 the mail system will not accept this message over IPv6 because it lacks some re-
210             # 456 quirments described in the full text of the rejection, however the sending mail
211             # system can retry immediately to submit the message over IPv4 only.
212             # https://datatracker.ietf.org/doc/html/draft-martin-smtp-ipv6-to-ipv4-fallback-00
213             #
214             # -------------------------------------------------------------------------------------------------
215             # X.5.0 220 Other or undefined protocol status:(RFC 3463)
216             # 250-253 Something was wrong with the protocol necessary to deliver the message to the next
217             # 451,452 hop and the problem cannot be well expressed with any of the other provided detail
218             # 454,458 codes.
219             # 459,554
220             # 501-503
221             #
222             # X.5.1 430 Invalid command:(RFC 3463)
223             # 500,501 A mail transaction protocol command was issued which was either out of sequence
224             # 503,530 or unsupported. This is useful only as a permanent error.
225             # 550,554
226             # 555
227             #
228             # X.5.2 500 Syntax error:(RFC 3463)
229             # 500,501 A mail transaction protocol command was issued which could not be interpreted,
230             # 502,550 either because the syntax was wrong or the command is unrecognized. This is useful
231             # 555 only as a permanent error.
232             #
233             # X.5.3 451 Too many recipients:(RFC 3463)
234             # More recipients were specified for the message than could have been delivered by
235             # the protocol. This error should normally result in the segmentation of the message
236             # into two, the remainder of the recipients to be delivered on a subsequent delivery
237             # attempt. It is included in this list in the event that such segmentation is not
238             # possible.
239             #
240             # X.5.4 451 Invalid command arguments:(RFC 3463)
241             # 501-504 A valid mail transaction protocol command was issued with invalid arguments,
242             # 550 either because the arguments were out of range or represented unrecognized
243             # 555 features. This is useful only as a permanent error.
244             #
245             # X.5.5 --- Wrong protocol version:(RFC 3463)
246             # A protocol version mis-match existed which could not be automatically resolved by
247             # the communicating parties.
248             #
249             # X.5.6 550 Authentication Exchange line is too long (RFC 4954)
250             # This enhanced status code SHOULD be returned when the server fails the AUTH
251             # command due to the client sending a [BASE64] response which is longer than the
252             # maximum buffer size available for the currently selected SASL mechanism. This is
253             # useful for both permanent and persistent transient errors.
254             # -------------------------------------------------------------------------------------------------
255             # X.6.0 --- Other or undefined media error:(RFC 3463)
256             # Something about the content of a message caused it to be considered undeliverable
257             # and the problem cannot be well expressed with any of the other provided detail
258             # codes.
259             #
260             # X.6.1 --- Media not supported:(RFC 3463)
261             # The media of the message is not supported by either the delivery protocol or the
262             # next system in the forwarding path. This is useful only as a permanent error.
263             #
264             # X.6.2 --- Conversion required and prohibited:(RFC 3463)
265             # The content of the message must be converted before it can be delivered and such
266             # conversion is not permitted. Such prohibitions may be the expression of the sender
267             # in the message itself or the policy of the sending host.
268             #
269             # X.6.3 554 Conversion required but not supported:(RFC 3463)
270             # The message content must be converted in order to be forwarded but such conversion
271             # is not possible or is not practical by a host in the forwarding path. This
272             # condition may result when an ESMTP gateway supports 8bit transport but is not able
273             # to downgrade the message to 7 bit as required for the next hop.
274             #
275             # X.6.4 250 Conversion with loss performed:(RFC 3463)
276             # This is a warning sent to the sender when message delivery was successfully but
277             # when the delivery required a conversion in which some data was lost. This may also
278             # be a permanent error if the sender has indicated that conversion with loss is
279             # prohibited for the message.
280             #
281             # X.6.5 --- Conversion Failed:(RFC 3463)
282             # A conversion was required but was unsuccessful. This may be useful as a permanent
283             # or persistent temporary notification.
284             #
285             # X.6.6 554 Message content not available (RFC 4468)
286             # The message content could not be fetched from a remote system. This may be useful
287             # as a permanent or persistent temporary notification.
288             #
289             # X.6.7 553 The ALT-ADDRESS is required but not specified:(RFC 6531)
290             # 550 This indicates the reception of a MAIL or RCPT command that non-ASCII addresses
291             # are not permitted
292             #
293             # X.6.8 252 UTF-8 string reply is required, but not permitted by the client:(RFC 6531)
294             # 553 This indicates that a reply containing a UTF-8 string is required to show the
295             # 550 mailbox name, but that form of response is not permitted by the SMTP client.
296             #
297             # X.6.9 550 UTF8SMTP downgrade failed:(RFC 6531)
298             # This indicates that transaction failed after the final "." of the DATA command.
299             #
300             # X.6.10 This is a duplicate of X.6.8 and is thus deprecated.
301             # -------------------------------------------------------------------------------------------------
302             # X.7.0 220 Other or undefined security status:(RFC 3463)
303             # 235 Something related to security caused the message to be returned, and the problem
304             # 450,454 cannot be well expressed with any of the other provided detail codes. This status
305             # 500,501 code may also be used when the condition cannot be further described because of
306             # 503,504 security policies in force.
307             # 530,535
308             # 550
309             #
310             # X.7.1 451 Delivery not authorized, message refused:(RFC 3463)
311             # 454,502 The sender is not authorized to send to the destination. This can be the result
312             # 503,533 of per-host or per-recipient filtering. This memo does not discuss the merits of
313             # 550,551 any such filtering, but provides a mechanism to report such. This is useful only
314             # as a permanent error.
315             #
316             # X.7.2 550 Mailing list expansion prohibited:(RFC 3463)
317             # The sender is not authorized to send a message to the intended mailing list. This
318             # is useful only as a permanent error.
319             #
320             # X.7.3 --- Security conversion required but not possible:(RFC 3463)
321             # A conversion from one secure messaging protocol to another was required for
322             # delivery and such conversion was not possible. This is useful only as a permanent
323             # error.
324             #
325             # X.7.4 504 Security features not supported:(RFC 3463)
326             # A message contained security features such as secure authentication that could not
327             # be supported on the delivery protocol. This is useful only as a permanent error.
328             #
329             # X.7.5 --- Cryptographic failure:(RFC 3463)
330             # A transport system otherwise authorized to validate or decrypt a message in
331             # transport was unable to do so because necessary information such as key was not
332             # available or such information was invalid.
333             #
334             # X.7.6 --- Cryptographic algorithm not supported:(RFC 3463)
335             # A transport system otherwise authorized to validate or decrypt a message was
336             # unable to do so because the necessary algorithm was not supported.
337              
338             # X.7.7 --- Message integrity failure:(RFC 3463)
339             # A transport system otherwise authorized to validate a message was unable to do so
340             # because the message was corrupted or altered. This may be useful as a permanent,
341             # transient persistent, or successful delivery code.
342             #
343             # X.7.8 535 Trust relationship required:(RFC 4954)
344             # 554 This response to the AUTH command indicates that the authentication failed due to
345             # invalid or insufficient authentication credentials. In this case, the client
346             # SHOULD ask the user to supply new credentials (such as by presenting a password
347             # dialog box).
348             #
349             # X.7.9 534 Authentication mechanism is too weak:(RFC 4954)
350             # This response to the AUTH command indicates that the selected authentication
351             # mechanism is weaker than server policy permits for that user. The client SHOULD
352             # retry with a new authentication mechanism.
353             #
354             # X.7.10 523 Encryption Needed:(RFC 5248)
355             # This indicates that external strong privacy layer is needed in order to use the
356             # requested authentication mechanism. This is primarily intended for use with clear
357             # text authentication mechanisms. A client which receives this may activate a
358             # security layer such as TLS prior to authenticating, or attempt to use a stronger
359             # mechanism.
360             #
361             # X.7.11 524 Encryption required for requested authentication mechanism:(RFC 4954)
362             # 538 This response to the AUTH command indicates that the selected authentication
363             # mechanism may only be used when the underlying SMTP connection is encrypted. Note
364             # that this response code is documented here for historical purposes only. Modern
365             # implementations SHOULD NOT advertise mechanisms that are not permitted due to lack
366             # of encryption, unless an encryption layer of sufficient strength is currently
367             # being employed.
368             #
369             # X.7.12 422 A password transition is needed:(RFC 4954)
370             # 432 This response to the AUTH command indicates that the user needs to transition to
371             # the selected authentication mechanism. This is typically done by authenticating
372             # once using the [PLAIN] authentication mechanism. The selected mechanism SHOULD
373             # then work for authentications in subsequent sessions.
374             #
375             # X.7.13 525 User Account Disabled:(RFC 5248)
376             # Sometimes a system administrator will have to disable a user's account (e.g., due
377             # to lack of payment, abuse, evidence of a break-in attempt, etc). This error code
378             # occurs after a successful authentication to a disabled account. This informs the
379             # client that the failure is permanent until the user contacts their system
380             # administrator to get the account re-enabled. It differs from a generic
381             # authentication failure where the client's best option is to present the passphrase
382             # entry dialog in case the user simply mistyped their passphrase.
383             #
384             # X.7.14 535 Trust relationship required:(RFC 5248)
385             # 554 The submission server requires a configured trust relationship with a third-party
386             # server in order to access the message content. This value replaces the prior use
387             # of X.7.8 for this error condition. thereby updating [RFC4468].
388             #
389             # X.7.15 450 Priority Level is too low:(RFC6710)
390             # 550 The specified priority level is below the lowest priority acceptable for the
391             # 4xx receiving SMTP server. This condition might be temporary, for example the server
392             # 5xx is operating in a mode where only higher priority messages are accepted for
393             # transfer and delivery, while lower priority messages are rejected.
394             #
395             # X.7.16 552 Message is too big for the specified priority:(RFC 6710)
396             # 4xx The message is too big for the specified priority. This condition might be
397             # 5xx temporary, for example the server is operating in a mode where only higher
398             # priority messages below certain size are accepted for transfer and delivery.
399             #
400             # X.7.17 5xx Mailbox owner has changed:(RFC 6710)
401             # This status code is returned when a message is received with a
402             # Require-Recipient-Valid-Since field or RRVS extension and the receiving system is
403             # able to determine that the intended recipient mailbox has not been under
404             # continuous ownership since the specified date-time.
405             #
406             # X.7.18 5xx Domain owner has changed:(RFC 7293)
407             # This status code is returned when a message is received with a
408             # Require-Recipient-Valid-Since field or RRVS extension and the receiving system
409             # wishes to disclose that the owner of the domain name of the recipient has changed
410             # since the specified date-time.
411             #
412             # X.7.19 5xx RRVS test cannot be completed:(RFC 7293)
413             # This status code is returned when a message is received with a
414             # Require-Recipient-Valid-Since field or RRVS extension and the receiving system
415             # cannot complete the requested evaluation because the required timestamp was not
416             # recorded. The message originator needs to decide whether to reissue the message
417             # without RRVS protection.
418             #
419             # X.7.20 550 No passing DKIM signature found:(RFC 7372)
420             # This status code is returned when a message did not contain any passing DKIM
421             # signatures. (This violates the advice of Section 6.1 of [RFC6376].)
422             #
423             # X.7.21 550 No acceptable DKIM signature found:(RFC 7372, 6476)
424             # This status code is returned when a message contains one or more passing DKIM
425             # signatures, but none are acceptable. (This violates the advice of Section 6.1 of
426             # [RFC6376].)
427             #
428             # X.7.22 550 No valid author-matched DKIM signature found:(RFC 7372)
429             # This status code is returned when a message contains one or more passing DKIM
430             # signatures, but none are acceptable because none have an identifier(s) that
431             # matches the author address(es) found in the From header field. This is a special
432             # case of X.7.21. (This violates the advice of Section 6.1 of [RFC6376].)
433             #
434             # X.7.23 550 SPF validation failed:(RFC 7273, 7208)
435             # This status code is returned when a message completed an SPF check that produced
436             # a "fail" result, contrary to local policy requirements. Used in place of 5.7.1 as
437             # described in Section 8.4 of [RFC7208].
438             #
439             # X.7.24 451 SPF validation error:(RFC 7372, 7208)
440             # 550 This status code is returned when evaluation of SPF relative to an arriving
441             # message resulted in an error. Used in place of 4.4.3 or 5.5.2 as described in
442             # Sections 8.6 and 8.7 of [RFC7208].
443             #
444             # X.7.25 550 Reverse DNS validation failed:(RFC 7372, 7601)
445             # This status code is returned when an SMTP client's IP address failed a reverse
446             # DNS validation check, contrary to local policy requirements.
447             #
448             # X.7.26 550 Multiple authentication checks failed:(RFC 7372)
449             # This status code is returned when a message failed more than one message
450             # authentication check, contrary to local policy requirements. The particular
451             # mechanisms that failed are not specified.
452             #
453             # X.7.27 550 Sender address has null MX:(RFC 7505)
454             # This status code is returned when the associated sender address has a null MX,
455             # and the SMTP receiver is configured to reject mail from such sender
456             # (e.g., because it could not return a DSN).
457             # -------------------------------------------------------------------------------------------------
458             # SAMPLES
459             # 554 5.5.0 No recipients have been specified
460             # 503 5.5.0 Valid RCPT TO required before BURL
461             # 554 5.6.3 Conversion required but not supported
462             # 554 5.3.4 Message too big for system
463             # 554 5.7.8 URL resolution requires trust relationship
464             # 552 5.2.2 Mailbox full
465             # 554 5.6.6 IMAP URL resolution failed
466             # 250 2.5.0 Waiting for additional BURL or BDAT commands
467             # 451 4.4.1 IMAP server unavailable
468             # 250 2.5.0 Ok.
469             # 250 2.6.4 MIME header conversion with loss performed
470             # 235 2.7.0 Authentication Succeeded
471             # 432 4.7.12 A password transition is needed
472             # 454 4.7.0 Temporary authentication failure
473             # 534 5.7.9 Authentication mechanism is too weak
474             # 535 5.7.8 Authentication credentials invalid
475             # 500 5.5.6 Authentication Exchange line is too long
476             # 530 5.7.0 Authentication required
477             # 538 5.7.11 Encryption required for requested authentication
478             # 5.7.8 Authentication credentials invalid
479             # 5.7.9 Authentication mechanism is too weak
480             # 5.7.11 Encryption required for requested authentication mechanism
481             # -------------------------------------------------------------------------------------------------
482 91         32150 use constant StandardCode => {
483             '2.1.5' => 'delivered', # Successfully delivered
484             # ---------------------------------------------------------------------------------------------
485             '4.1.6' => 'hasmoved', # Destination mailbox has moved, No forwarding address
486             '4.1.7' => 'rejected', # Bad sender's mailbox address syntax
487             '4.1.8' => 'rejected', # Bad sender's system address
488             '4.1.9' => 'systemerror', # Message relayed to non-compliant mailer
489             '4.2.1' => 'suspend', # Mailbox disabled, not accepting messages
490             '4.2.2' => 'mailboxfull', # Mailbox full
491             '4.2.3' => 'emailtoolarge', # Message length exceeds administrative limit
492             '4.2.4' => 'systemerror', # Mailing list expansion problem
493             #'4.3.0' => 'systemerror', # Other or undefined mail system status
494             '4.3.1' => 'systemfull', # Mail system full
495             '4.3.2' => 'notaccept', # System not accepting network messages
496             '4.3.3' => 'systemerror', # System not capable of selected features
497             '4.3.5' => 'systemerror', # System incorrectly configured
498             #'4.4.0' => 'networkerror', # Other or undefined network or routing status
499             '4.4.1' => 'expired', # No answer from host
500             '4.4.2' => 'networkerror', # Bad connection
501             '4.4.3' => 'systemerror', # Directory server failure
502             '4.4.4' => 'networkerror', # Unable to route
503             '4.4.5' => 'systemfull', # Mail system congestion
504             '4.4.6' => 'networkerror', # Routing loop detected
505             '4.4.7' => 'expired', # Delivery time expired
506             '4.4.8' => 'networkerror', # Retry on IPv4
507             #'4.5.0' => 'networkerror', # Other or undefined protocol status
508             '4.5.3' => 'ratelimited', # Too many recipients
509             '4.5.5' => 'systemerror', # Wrong protocol version
510             '4.6.0' => 'contenterror', # Other or undefined media error
511             '4.6.2' => 'contenterror', # Conversion required and prohibited
512             '4.6.5' => 'contenterror', # Conversion Failed
513             #'4.7.0' => 'securityerror', # Other or undefined security status
514             '4.7.1' => 'blocked', # Delivery not authorized, message refused
515             '4.7.2' => 'rejected', # Mailing list expansion prohibited
516             '4.7.5' => 'securityerror', # Cryptographic failure
517             '4.7.6' => 'securityerror', # Cryptographic algorithm not supported
518             '4.7.7' => 'securityerror', # Message integrity failure
519             '4.7.12' => 'securityerror', # A password transition is needed
520             '4.7.15' => 'securityerror', # Priority Level is too low
521             '4.7.16' => 'emailtoolarge', # Message is too big for the specified priority
522             '4.7.24' => 'authfailure', # SPF validation error
523             '4.7.25' => 'requireptr', # Reverse DNS validation failed
524             '4.7.26' => 'authfailure', # Must pass either SPF or DKIM validation
525             # ---------------------------------------------------------------------------------------------
526             '5.1.0' => 'userunknown', # Other address status
527             '5.1.1' => 'userunknown', # Bad destination mailbox address
528             '5.1.2' => 'hostunknown', # Bad destination system address
529             '5.1.3' => 'userunknown', # Bad destination mailbox address syntax
530             '5.1.4' => 'filtered', # Destination mailbox address ambiguous
531             '5.1.6' => 'hasmoved', # Destination mailbox has moved, No forwarding address
532             '5.1.7' => 'rejected', # Bad sender's mailbox address syntax
533             '5.1.8' => 'rejected', # Bad sender's system address
534             '5.1.9' => 'systemerror', # Message relayed to non-compliant mailer
535             '5.1.10' => 'notaccept', # Recipient address has null MX
536             '5.2.0' => 'filtered', # Other or undefined mailbox status
537             '5.2.1' => 'filtered', # Mailbox disabled, not accepting messages
538             '5.2.2' => 'mailboxfull', # Mailbox full
539             '5.2.3' => 'emailtoolarge', # Message length exceeds administrative limit
540             '5.2.4' => 'systemerror', # Mailing list expansion problem
541             '5.3.0' => 'systemerror', # Other or undefined mail system status
542             '5.3.1' => 'systemfull', # Mail system full
543             '5.3.2' => 'notaccept', # System not accepting network messages
544             '5.3.3' => 'systemerror', # System not capable of selected features
545             '5.3.4' => 'emailtoolarge', # Message too big for system
546             '5.3.5' => 'systemerror', # System incorrectly configured
547             '5.4.0' => 'networkerror', # Other or undefined network or routing status
548             '5.4.3' => 'systemerror', # Directory server failure
549             '5.4.4' => 'hostunknown', # Unable to route
550             '5.5.2' => 'systemerror', # If the server cannot BASE64 decode any client response (AUTH)
551             '5.5.3' => 'ratelimited', # Too many recipients
552             '5.5.4' => 'systemerror', # Invalid command arguments
553             '5.5.5' => 'systemerror', # Wrong protocol version
554             '5.5.6' => 'syntaxerror', # Authentication Exchange line is too long
555             '5.6.0' => 'contenterror', # Other or undefined media error
556             '5.6.1' => 'contenterror', # Media not supported
557             '5.6.2' => 'contenterror', # Conversion required and prohibited
558             '5.6.3' => 'contenterror', # Conversion required but not supported
559             '5.6.5' => 'contenterror', # Conversion Failed
560             '5.6.6' => 'contenterror', # Message content not available
561             '5.6.7' => 'rejected', # Non-ASCII addresses not permitted for that sender/recipient
562             '5.6.8' => 'contenterror', # UTF-8 string reply is required, but not permitted by the SMTP client
563             '5.6.9' => 'contenterror', # UTF-8 header message cannot be transferred to one or more recipients
564             '5.7.0' => 'securityerror', # Other or undefined security status
565             '5.7.1' => 'securityerror', # Delivery not authorized, message refused
566             '5.7.2' => 'securityerror', # Mailing list expansion prohibited
567             '5.7.3' => 'securityerror', # Security conversion required but not possible
568             '5.7.4' => 'securityerror', # Security features not supported
569             '5.7.5' => 'securityerror', # Cryptographic failure
570             '5.7.6' => 'securityerror', # Cryptographic algorithm not supported
571             '5.7.7' => 'securityerror', # Message integrity failure
572             '5.7.8' => 'securityerror', # Authentication credentials invalid
573             '5.7.9' => 'securityerror', # Authentication mechanism is too weak
574             '5.7.10' => 'securityerror', # Encryption Needed
575             '5.7.11' => 'securityerror', # Encryption required for requested authentication mechanism
576             '5.7.13' => 'suspend', # User Account Disabled
577             '5.7.14' => 'securityerror', # Trust relationship required
578             '5.7.15' => 'securityerror', # Priority Level is too low
579             '5.7.16' => 'emailtoolarge', # Message is too big for the specified priority
580             '5.7.17' => 'hasmoved', # Mailbox owner has changed
581             '5.7.18' => 'hasmoved', # Domain owner has changed
582             '5.7.19' => 'systemerror', # RRVS test cannot be completed
583             '5.7.20' => 'authfailure', # No passing DKIM signature found
584             '5.7.21' => 'authfailure', # No acceptable DKIM signature found
585             '5.7.22' => 'authfailure', # No valid author-matched DKIM signature found
586             '5.7.23' => 'authfailure', # SPF validation failed
587             '5.7.24' => 'authfailure', # SPF validation error
588             '5.7.25' => 'requireptr', # Reverse DNS validation failed
589             '5.7.26' => 'authfailure', # Multiple authentication checks failed
590             '5.7.27' => 'notaccept', # MX resource record of a destination host is Null MX: RFC7505
591             '5.7.28' => 'spamdetected', # The message appears to be part of a mail flood of similar abusive messages.
592             '5.7.29' => 'authfailure', # This status code may be returned when a message fails ARC validation.
593             '5.7.30' => 'failedstarttls', # REQUIRETLS support required
594 91     91   800 };
  91         181  
595              
596 91         169049 use constant InternalCode => {
597             'authfailure' => ['5.9.130', '4.9.130'],
598             'badreputation' => ['5.9.132', '4.9.132'],
599             'blocked' => ['5.9.134', '4.9.134'],
600             'contenterror' => ['5.9.160', '4.9.160'],
601             'emailtoolarge' => ['5.9.161', '4.9.161'],
602             'expired' => ['5.9.340', '4.9.340'],
603             'failedstarttls' => ['5.9.350', '4.9.350'],
604             'filtered' => ['5.9.210', '4.9.210'],
605             'hasmoved' => ['5.9.211', ''],
606             'hostunknown' => ['5.9.212', ''],
607             'mailboxfull' => ['5.9.220', '4.9.220'],
608             'mailererror' => ['5.9.230', '4.9.230'],
609             'networkerror' => ['5.9.341', '4.9.341'],
610             'norelaying' => ['5.9.214', '4.9.214'],
611             'notaccept' => ['5.9.215', '4.9.215'],
612             'notcompliantrfc' => ['5.9.162', '4.9.162'],
613             'onhold' => ['5.9.301', '4.9.301'],
614             'policyviolation' => ['5.9.371', '4.9.371'],
615             'ratelimited' => ['5.9.131', '4.9.131'],
616             'rejected' => ['5.9.110', '4.9.110'],
617             'requireptr' => ['5.9.133', '4.9.133'],
618             'securityerror' => ['5.9.370', '4.9.370'],
619             'spamdetected' => ['5.9.164', '4.9.164'],
620             'suppressed' => ['5.9.310', '4.9.310'],
621             'suspend' => ['5.9.221', '4.9.221'],
622             'syntaxerror' => ['5.9.351', '4.9.351'],
623             'systemerror' => ['5.9.231', '4.9.231'],
624             'systemfull' => ['5.9.232', '4.9.232'],
625             'undefined' => ['5.9.300', '4.9.300'],
626             'userunknown' => ['5.9.213', ''],
627             'virusdetected' => ['5.9.165', '4.9.165'],
628 91     91   707 };
  91         212  
629              
630             sub code {
631             # Convert from the reason string to the internal status code
632             # @param [String] argv1 Reason name
633             # @param [Integer] argv2 0: Permanent error
634             # 1: Temporary error
635             # @return [String] D.S.N. or empty if the 1st argument is missing
636             # @see name
637             # @since v4.14.0
638 898     898 1 450392 my $class = shift;
639 898   100     3428 my $argv1 = shift || return "";
640 897   100     2894 my $argv2 = shift // 0;
641 897   100     4093 my $pairs = InternalCode->{ $argv1 } || return "";
642 781 100       4458 return $argv2 ? $pairs->[1] : $pairs->[0];
643             }
644              
645             sub name {
646             # Convert from the status code to the reason string
647             # @param [String] argv1 Status code(DSN)
648             # @return [String] Reason name or empty if the first argument did
649             # not match with values in Sisimai's reason list
650             # @see code
651             # @since v4.14.0
652 15687     15687 1 55693 my $class = shift;
653 15687 100 100     49191 my $argv1 = shift || return ""; return '' unless __PACKAGE__->test($argv1);
  12487         26273  
654 12148   100     71406 return StandardCode->{ $argv1 } // '';
655             }
656              
657             sub test {
658             # Check whether a status code is a valid code or not
659             # @param [String] argv1 Status code(DSN)
660             # @return [Boolean] 0 = Invalid status code, 1 = Valid status code
661             # @see code
662             # @since v5.0.0
663 12817     12817 1 33599 my $class = shift;
664 12817 100 100     26047 my $argv1 = shift || return 0; return 0 if length $argv1 < 5 || length $argv1 > 7;
  12816   100     47716  
665              
666 12812         18353 my $token = []; push @$token, int $_ for split(/[.]/, $argv1);
  12812         80804  
667 12812 100       34596 return 0 unless scalar @$token == 3;
668 12811 100       31474 return 0 if $token->[0] < 2;
669 12810 100       30063 return 0 if $token->[0] == 3;
670 12809 100       25210 return 0 if $token->[0] > 5;
671 12808 100       27271 return 0 if $token->[1] < 0;
672 12807 100       29019 return 0 if $token->[1] > 7;
673 12467 100       26637 return 0 if $token->[2] < 0;
674 12466         35626 return 1;
675             }
676              
677             sub find {
678             # Get a DSN code value from given string including DSN
679             # @param [String] argv1 String including DSN
680             # @param [String] argv2 An SMTP Reply Code or 2 or 4 or 5
681             # @return [String] An SMTP Status Code
682             # @since v4.14.0
683 7502     7502 1 33729 my $class = shift;
684 7502 100 100     22152 my $argv1 = shift || return ""; return "" if length $argv1 < 7;
  7496         18879  
685 7252   100     27028 my $argv2 = shift || '';
686              
687 7252         14513 my $givenclass = substr($argv2, 0, 1);
688 7252 100 100     51865 my $eestatuses = $givenclass eq '2' || $givenclass eq '4' || $givenclass eq '5' ? [$givenclass.'.'] : ['5.', '4.', '2.'];
689 7252         17205 my $esmtperror = ' '.$argv1.' ';
690 7252         11925 my $lookingfor = {};
691              
692 7252         40675 for my $e ( Sisimai::RFC791->find($esmtperror)->@* ) {
693             # Rewrite an IPv4 address in the given string(argv1) with '***.***.***.***'
694 2595 50       6931 my $p0 = index($esmtperror, $e); next if $p0 == -1;
  2595         6207  
695 2595         8274 substr($esmtperror, $p0, length $e, '***.***.***.***');
696             }
697              
698 7252         18476 for my $e ( @$eestatuses ) {
699             # Count the number of "5.", "4.", and "2." in the error message
700 20844         26050 my $p0 = 0;
701 20844         26375 my $p1 = 0;
702 20844         39808 while($p0 > -1) {
703             # Find all of the "5." and "4." string and store its postion
704 26656 100       42330 $p0 = index($esmtperror, $e, $p1); last if $p0 == -1;
  26656         52176  
705 5812         25847 $lookingfor->{ sprintf("%04d", $p0) } = $e;
706 5812         12211 $p1 = $p0 + 5;
707             }
708             }
709 7252 100       42928 return '' unless scalar keys %$lookingfor;
710              
711 3204         6348 my $statuscode = []; # List of SMTP Status Code, Keep the order of appearances
712 3204         6593 my $anotherone = ''; # Alternative code
713 3204         6329 my $readbuffer = '';
714 3204         4959 my $characters = []; # Characters around the status code found by index()
715 3204         5049 my $indexofees = -1; # A position of SMTP status code found by the index()
716              
717 3204         17648 for my $e ( sort keys %$lookingfor ) {
718             # Try to find an SMTP Status Code from the given string
719 5812 50       15416 $indexofees = index($esmtperror, $lookingfor->{ $e }, int $e); next if $indexofees == -1;
  5812         12738  
720 5812   50     35744 $characters = [
      50        
      50        
721             ord(substr($esmtperror, $indexofees - 1, 1)) || 0, # [0] The previous character of the status
722             ord(substr($esmtperror, $indexofees + 2, 1)) || 0, # [1] The value of the "Subject", "5.[7].261"
723             ord(substr($esmtperror, $indexofees + 3, 1)) || 0, # [2] "." chacater, a separator of the Subject and the Detail
724             ];
725              
726 5812 100 100     23893 next if $characters->[0] > 45 && $characters->[0] < 58; # Previous character is a number
727 4030 50 33     16191 next if $characters->[0] == 86 || $characters->[0] == 118; # Avoid a version number("V" or "v")
728 4030 100 100     15169 next if $characters->[1] < 48 || $characters->[1] > 55; # The value of the subject is not a number(0-7)
729 3776 100       8607 next if $characters->[2] != 46; # It is not a "." character: a separator
730              
731 3734         10852 $readbuffer = $lookingfor->{ $e }.chr($characters->[1]).'.';
732 3734   50     32222 push @$characters, ord(substr($esmtperror, $indexofees + 4, 1)) || 0, # [3] The 1st digit of the detail
      50        
      50        
      100        
733             ord(substr($esmtperror, $indexofees + 5, 1)) || 0, # [4] The 2nd digit of the detail
734             ord(substr($esmtperror, $indexofees + 6, 1)) || 0, # [5] The 3rd digit of the detail
735             ord(substr($esmtperror, $indexofees + 7, 1)) || 0; # [6] The next character
736              
737 3734 100 66     15558 next if $characters->[3] < 48 || $characters->[3] > 57; # The 1st digit of the detail is not a number
738 3728         7866 $readbuffer .= chr $characters->[3];
739              
740 3728 100 100     11924 if( Sisimai::SMTP::Status->is_ambiguous($readbuffer) || $readbuffer eq "4.4.7" ) {
741             # Find another status code except *.0.0, 4.4.7
742 199         411 $anotherone = $readbuffer;
743 199         381 next;
744             }
745              
746 3529 100 100     18975 if( $characters->[4] < 48 || $characters->[4] > 57 ) {
747             # The 2nd digit of the detail is not a number
748 3030         6458 push @$statuscode, $readbuffer;
749 3030         6958 next;
750             }
751 499         939 $readbuffer .= chr $characters->[4]; # The 2nd digit of the detail is a number
752              
753 499 100 66     1870 if( $characters->[5] < 48 || $characters->[5] > 57 ) {
754             # The 3rd digit of the detail is not a number
755 359         833 push @$statuscode, $readbuffer;
756 359         633 next;
757             }
758 140         331 $readbuffer .= chr $characters->[5]; # The 3rd digit of the detail is a number
759              
760 140 50 33     506 next if $characters->[6] > 47 && $characters->[6] < 58;
761 140         378 push @$statuscode, $readbuffer;
762             }
763 3204 100       10252 push @$statuscode, $anotherone if length $anotherone;
764 3204 100       12826 return '' if scalar @$statuscode == 0;
765              
766             # Select one from picked status codes
767 2583         6670 my $cv = shift @$statuscode; for my $e ( @$statuscode ) { $cv = __PACKAGE__->prefer($cv, $e, "") }
  2583         5607  
  1135         3812  
768 2583         22084 return $cv;
769             }
770              
771             sub prefer {
772             # Return the preferred value selected from the arguments
773             # @param [String] argv0 The value of Status:
774             # @param [String] argv1 The delivery status picked from the error message
775             # @param [String] argv2 The value of An SMTP Reply Code
776             # @return [String] The preferred value
777             # @since v5.0.0
778 5000     5000 1 11223 my $class = shift;
779 5000   100     15165 my $argv0 = shift || '';
780 5000   100     16301 my $argv1 = shift || '';
781 5000   100     14667 my $argv2 = shift || '';
782              
783 5000 100 100     16465 my $statuscode = $argv0 || return $argv1; return $argv1 unless length $statuscode > 4;
  3511         8404  
784 3510 100 100     10005 my $codeinmesg = $argv1 || return $argv0; return $argv0 unless length $codeinmesg > 4;
  2525         5940  
785 2524 50       7942 return $codeinmesg if index($statuscode, '.9.') == 1;
786              
787 2524   100     7221 my $esmtpreply = $argv2 || 0;
788 2524         14368 my $the1stchar = {
789             'field' => int substr($statuscode, 0, 1),
790             'error' => int substr($codeinmesg, 0, 1),
791             'reply' => int substr($esmtpreply, 0, 1),
792             };
793              
794 2524 100 100     12846 if( $the1stchar->{'reply'} > 0 && $the1stchar->{'field'} != $the1stchar->{'error'} ) {
795             # There is the 3rd argument (an SMTP Reply Code)
796             # Returns the value of $argv0 or $argv1 which begins with the 1st character of $argv2
797 23 100       120 return $statuscode if $the1stchar->{'reply'} == $the1stchar->{'field'};
798 21 50       160 return $codeinmesg if $the1stchar->{'reply'} == $the1stchar->{'error'};
799             }
800 2501 100       12062 return $statuscode if $statuscode eq $codeinmesg;
801              
802 383         1376 my $zeroindex1 = {'field' => index($statuscode, '.0'), 'error' => index($codeinmesg, '.0') };
803 383         1387 my $zeroindex2 = {'field' => index($statuscode, '.0.0'), 'error' => index($codeinmesg, '.0.0')};
804              
805 383 100       1108 if( $zeroindex2->{'field'} > 0 ) {
806             # "Status:" field is "X.0.0"
807 75 50       542 return $codeinmesg if $zeroindex2->{'error'} < 0;
808 0         0 return $statuscode;
809             }
810              
811 308 100       794 if( $zeroindex1->{'field'} > 0 ) {
812             # "Status:" field is "X.Y.0" or "X.0.Z"
813 65 100       379 return $codeinmesg if $zeroindex1->{'error'} < 0;
814             }
815              
816 264 100       983 return $statuscode if $zeroindex2->{'error'} > 0; # An SMTP status code is "X.0.0"
817 202 100       835 return $codeinmesg if $statuscode eq '4.4.7'; # "4.4.7" is an ambiguous code
818 166 100       714 return $codeinmesg if $statuscode eq '4.7.0'; # "4.7.0" indicates "too many errors"
819 155 50       459 return $codeinmesg if index($statuscode, '5.3.') == 0; # "5.3.Z" is an error of a system
820 155 100       516 return $codeinmesg if index($statuscode, '.5.1') > 0; # "X.5.1" indicates an invalid command
821 144 50       444 return $codeinmesg if index($statuscode, '.5.2') > 0; # "X.5.2" indicates a syntax error
822 144 50       423 return $codeinmesg if index($statuscode, '.5.4') > 0; # "X.5.4" indicates an invalid command arguments
823 144 50       459 return $codeinmesg if index($statuscode, '.5.5') > 0; # "X.5.5" indicates a wrong protocol version
824              
825 144 100       732 if( $statuscode eq '5.1.1' ) {
    100          
826             # "5.1.1" is a code of "userunknown"
827 37 100 100     323 return $statuscode if index($codeinmesg, '5.5.') == 0 || $zeroindex1->{'error'} > 0;
828 10         70 return $codeinmesg;
829              
830             } elsif( $statuscode eq '5.1.3' ) {
831             # "5.1.3"
832 5 50       37 return $codeinmesg if index($codeinmesg, '5.7.') == 0;
833             }
834 102         539 return $statuscode;
835             }
836              
837             sub is_explicit {
838             # is_explicit() returns 0 when the argument is empty or is an internal status code
839             # @param string argv1 Delivery status code
840             # @return bool 0: The delivery status is not explicit
841 208     208 1 59003 my $class = shift;
842 208   100     796 my $argv1 = shift || return 0;
843              
844 207 100 66     1826 return 0 if length($argv1) == 7 && index($argv1, ".9.") == 1;
845 125         432 return 1;
846             }
847              
848             sub is_ambiguous {
849             # is_ambiguous() returns 1 when the argument is not empty and is ends with ".0.0".
850             # @param string argv1 Delivery status code
851             # @return bool 1: The delivery status is ambiguous
852 4542     4542 1 12885 my $class = shift;
853 4542   100     10861 my $argv1 = shift || return 1;
854 4354 100 100     23397 return 1 if length($argv1) == 5 && substr($argv1, -4, 4) eq ".0.0";
855 4002         17515 return 0
856             }
857              
858             1;
859             __END__