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 93     93   88503 use v5.26;
  93         244  
3 93     93   353 use strict;
  93         119  
  93         1671  
4 93     93   279 use warnings;
  93         117  
  93         3425  
5 93     93   1937 use Sisimai::RFC791;
  93         99  
  93         39290  
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.3.6 250 Requested priority was changed:(RFC 6710)
166             # 251 The message was accepted for relay/delivery, but the requested priority (possibly
167             # the implied default) was not honored. The human readable text after the status
168             # code contains the new priority, followed by SP (space) and explanatory human
169             # readable text.
170             # -------------------------------------------------------------------------------------------------
171             # X.4.0 --- Other or undefined network or routing status:(RFC 3463)
172             # Something went wrong with the networking, but it is not clear what the problem is,
173             # or the problem cannot be well expressed with any of the other provided detail
174             # codes.
175             #
176             # X.4.1 451 No answer from host:(RFC 3463)
177             # The outbound connection attempt was not answered, because either the remote system
178             # was busy, or was unable to take a call. This is useful only as a persistent
179             # transient error.
180             #
181             # X.4.2 421 Bad connection:(RFC 3463)
182             # The outbound connection was established, but was unable to complete the message
183             # transaction, either because of time-out, or inadequate connection quality. This
184             # is useful only as a persistent transient error.
185             #
186             # X.4.3 451 Directory server failure:(RFC 3463)
187             # 550 The network system was unable to forward the message, because a directory server
188             # was unavailable. This is useful only as a persistent transient error. The
189             # inability to connect to an Internet DNS server is one example of the directory
190             # server failure error.
191             #
192             # X.4.4 --- Unable to route:(RFC 3463)
193             # The mail system was unable to determine the next hop for the message because the
194             # necessary routing information was unavailable from the directory server. This is
195             # useful for both permanent and persistent transient errors. A DNS lookup returning
196             # only an SOA (Start of Administration) record for a domain name is one example of
197             # the unable to route error.
198             #
199             # X.4.5 451 Mail system congestion:(RFC 3463)
200             # The mail system was unable to deliver the message because the mail system was
201             # congested. This is useful only as a persistent transient error.
202             #
203             # X.4.6 --- Routing loop detected:(RFC 3463)
204             # A routing loop caused the message to be forwarded too many times, either because
205             # of incorrect routing tables or a user-forwarding loop. This is useful only as a
206             # persistent transient error.
207             #
208             # X.4.7 --- Delivery time expired:(RFC 3463)
209             # The message was considered too old by the rejecting system, either because it
210             # remained on that host too long or because the time-to-live value specified by the
211             # sender of the message was exceeded. If possible, the code for the actual problem
212             # found when delivery was attempted should be returned rather than this code.
213             #
214             # X.4.8 421 Retry on IPv4
215             # 451 the mail system will not accept this message over IPv6 because it lacks some re-
216             # 456 quirments described in the full text of the rejection, however the sending mail
217             # system can retry immediately to submit the message over IPv4 only.
218             # https://datatracker.ietf.org/doc/html/draft-martin-smtp-ipv6-to-ipv4-fallback-00
219             #
220             # -------------------------------------------------------------------------------------------------
221             # X.5.0 220 Other or undefined protocol status:(RFC 3463)
222             # 250-253 Something was wrong with the protocol necessary to deliver the message to the next
223             # 451,452 hop and the problem cannot be well expressed with any of the other provided detail
224             # 454,458 codes.
225             # 459,554
226             # 501-503
227             #
228             # X.5.1 430 Invalid command:(RFC 3463)
229             # 500,501 A mail transaction protocol command was issued which was either out of sequence
230             # 503,530 or unsupported. This is useful only as a permanent error.
231             # 550,554
232             # 555
233             #
234             # X.5.2 500 Syntax error:(RFC 3463)
235             # 500,501 A mail transaction protocol command was issued which could not be interpreted,
236             # 502,550 either because the syntax was wrong or the command is unrecognized. This is useful
237             # 555 only as a permanent error.
238             #
239             # X.5.3 451 Too many recipients:(RFC 3463)
240             # More recipients were specified for the message than could have been delivered by
241             # the protocol. This error should normally result in the segmentation of the message
242             # into two, the remainder of the recipients to be delivered on a subsequent delivery
243             # attempt. It is included in this list in the event that such segmentation is not
244             # possible.
245             #
246             # X.5.4 451 Invalid command arguments:(RFC 3463)
247             # 501-504 A valid mail transaction protocol command was issued with invalid arguments,
248             # 550 either because the arguments were out of range or represented unrecognized
249             # 555 features. This is useful only as a permanent error.
250             #
251             # X.5.5 --- Wrong protocol version:(RFC 3463)
252             # A protocol version mis-match existed which could not be automatically resolved by
253             # the communicating parties.
254             #
255             # X.5.6 550 Authentication Exchange line is too long (RFC 4954)
256             # This enhanced status code SHOULD be returned when the server fails the AUTH
257             # command due to the client sending a [BASE64] response which is longer than the
258             # maximum buffer size available for the currently selected SASL mechanism. This is
259             # useful for both permanent and persistent transient errors.
260             # -------------------------------------------------------------------------------------------------
261             # X.6.0 --- Other or undefined media error:(RFC 3463)
262             # Something about the content of a message caused it to be considered undeliverable
263             # and the problem cannot be well expressed with any of the other provided detail
264             # codes.
265             #
266             # X.6.1 --- Media not supported:(RFC 3463)
267             # The media of the message is not supported by either the delivery protocol or the
268             # next system in the forwarding path. This is useful only as a permanent error.
269             #
270             # X.6.2 --- Conversion required and prohibited:(RFC 3463)
271             # The content of the message must be converted before it can be delivered and such
272             # conversion is not permitted. Such prohibitions may be the expression of the sender
273             # in the message itself or the policy of the sending host.
274             #
275             # X.6.3 554 Conversion required but not supported:(RFC 3463)
276             # The message content must be converted in order to be forwarded but such conversion
277             # is not possible or is not practical by a host in the forwarding path. This
278             # condition may result when an ESMTP gateway supports 8bit transport but is not able
279             # to downgrade the message to 7 bit as required for the next hop.
280             #
281             # X.6.4 250 Conversion with loss performed:(RFC 3463)
282             # This is a warning sent to the sender when message delivery was successfully but
283             # when the delivery required a conversion in which some data was lost. This may also
284             # be a permanent error if the sender has indicated that conversion with loss is
285             # prohibited for the message.
286             #
287             # X.6.5 --- Conversion Failed:(RFC 3463)
288             # A conversion was required but was unsuccessful. This may be useful as a permanent
289             # or persistent temporary notification.
290             #
291             # X.6.6 554 Message content not available (RFC 4468)
292             # The message content could not be fetched from a remote system. This may be useful
293             # as a permanent or persistent temporary notification.
294             #
295             # X.6.7 553 The ALT-ADDRESS is required but not specified:(RFC 6531)
296             # 550 This indicates the reception of a MAIL or RCPT command that non-ASCII addresses
297             # are not permitted
298             #
299             # X.6.8 252 UTF-8 string reply is required, but not permitted by the client:(RFC 6531)
300             # 553 This indicates that a reply containing a UTF-8 string is required to show the
301             # 550 mailbox name, but that form of response is not permitted by the SMTP client.
302             #
303             # X.6.9 550 UTF8SMTP downgrade failed:(RFC 6531)
304             # This indicates that transaction failed after the final "." of the DATA command.
305             #
306             # X.6.10 This is a duplicate of X.6.8 and is thus deprecated.
307             # -------------------------------------------------------------------------------------------------
308             # X.7.0 220 Other or undefined security status:(RFC 3463)
309             # 235 Something related to security caused the message to be returned, and the problem
310             # 450,454 cannot be well expressed with any of the other provided detail codes. This status
311             # 500,501 code may also be used when the condition cannot be further described because of
312             # 503,504 security policies in force.
313             # 530,535
314             # 550
315             #
316             # X.7.1 451 Delivery not authorized, message refused:(RFC 3463)
317             # 454,502 The sender is not authorized to send to the destination. This can be the result
318             # 503,533 of per-host or per-recipient filtering. This memo does not discuss the merits of
319             # 550,551 any such filtering, but provides a mechanism to report such. This is useful only
320             # as a permanent error.
321             #
322             # X.7.2 550 Mailing list expansion prohibited:(RFC 3463)
323             # The sender is not authorized to send a message to the intended mailing list. This
324             # is useful only as a permanent error.
325             #
326             # X.7.3 --- Security conversion required but not possible:(RFC 3463)
327             # A conversion from one secure messaging protocol to another was required for
328             # delivery and such conversion was not possible. This is useful only as a permanent
329             # error.
330             #
331             # X.7.4 504 Security features not supported:(RFC 3463)
332             # A message contained security features such as secure authentication that could not
333             # be supported on the delivery protocol. This is useful only as a permanent error.
334             #
335             # X.7.5 --- Cryptographic failure:(RFC 3463)
336             # A transport system otherwise authorized to validate or decrypt a message in
337             # transport was unable to do so because necessary information such as key was not
338             # available or such information was invalid.
339             #
340             # X.7.6 --- Cryptographic algorithm not supported:(RFC 3463)
341             # A transport system otherwise authorized to validate or decrypt a message was
342             # unable to do so because the necessary algorithm was not supported.
343              
344             # X.7.7 --- Message integrity failure:(RFC 3463)
345             # A transport system otherwise authorized to validate a message was unable to do so
346             # because the message was corrupted or altered. This may be useful as a permanent,
347             # transient persistent, or successful delivery code.
348             #
349             # X.7.8 535 Trust relationship required:(RFC 4954)
350             # 554 This response to the AUTH command indicates that the authentication failed due to
351             # invalid or insufficient authentication credentials. In this case, the client
352             # SHOULD ask the user to supply new credentials (such as by presenting a password
353             # dialog box).
354             #
355             # X.7.9 534 Authentication mechanism is too weak:(RFC 4954)
356             # This response to the AUTH command indicates that the selected authentication
357             # mechanism is weaker than server policy permits for that user. The client SHOULD
358             # retry with a new authentication mechanism.
359             #
360             # X.7.10 523 Encryption Needed:(RFC 5248)
361             # This indicates that external strong privacy layer is needed in order to use the
362             # requested authentication mechanism. This is primarily intended for use with clear
363             # text authentication mechanisms. A client which receives this may activate a
364             # security layer such as TLS prior to authenticating, or attempt to use a stronger
365             # mechanism.
366             #
367             # X.7.11 524 Encryption required for requested authentication mechanism:(RFC 4954)
368             # 538 This response to the AUTH command indicates that the selected authentication
369             # mechanism may only be used when the underlying SMTP connection is encrypted. Note
370             # that this response code is documented here for historical purposes only. Modern
371             # implementations SHOULD NOT advertise mechanisms that are not permitted due to lack
372             # of encryption, unless an encryption layer of sufficient strength is currently
373             # being employed.
374             #
375             # X.7.12 422 A password transition is needed:(RFC 4954)
376             # 432 This response to the AUTH command indicates that the user needs to transition to
377             # the selected authentication mechanism. This is typically done by authenticating
378             # once using the [PLAIN] authentication mechanism. The selected mechanism SHOULD
379             # then work for authentications in subsequent sessions.
380             #
381             # X.7.13 525 User Account Disabled:(RFC 5248)
382             # Sometimes a system administrator will have to disable a user's account (e.g., due
383             # to lack of payment, abuse, evidence of a break-in attempt, etc). This error code
384             # occurs after a successful authentication to a disabled account. This informs the
385             # client that the failure is permanent until the user contacts their system
386             # administrator to get the account re-enabled. It differs from a generic
387             # authentication failure where the client's best option is to present the passphrase
388             # entry dialog in case the user simply mistyped their passphrase.
389             #
390             # X.7.14 535 Trust relationship required:(RFC 5248)
391             # 554 The submission server requires a configured trust relationship with a third-party
392             # server in order to access the message content. This value replaces the prior use
393             # of X.7.8 for this error condition. thereby updating [RFC4468].
394             #
395             # X.7.15 450 Priority Level is too low:(RFC6710)
396             # 550 The specified priority level is below the lowest priority acceptable for the
397             # 4xx receiving SMTP server. This condition might be temporary, for example the server
398             # 5xx is operating in a mode where only higher priority messages are accepted for
399             # transfer and delivery, while lower priority messages are rejected.
400             #
401             # X.7.16 552 Message is too big for the specified priority:(RFC 6710)
402             # 4xx The message is too big for the specified priority. This condition might be
403             # 5xx temporary, for example the server is operating in a mode where only higher
404             # priority messages below certain size are accepted for transfer and delivery.
405             #
406             # X.7.17 5xx Mailbox 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 is
409             # able to determine that the intended recipient mailbox has not been under
410             # continuous ownership since the specified date-time.
411             #
412             # X.7.18 5xx Domain owner has changed:(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             # wishes to disclose that the owner of the domain name of the recipient has changed
416             # since the specified date-time.
417             #
418             # X.7.19 5xx RRVS test cannot be completed:(RFC 7293)
419             # This status code is returned when a message is received with a
420             # Require-Recipient-Valid-Since field or RRVS extension and the receiving system
421             # cannot complete the requested evaluation because the required timestamp was not
422             # recorded. The message originator needs to decide whether to reissue the message
423             # without RRVS protection.
424             #
425             # X.7.20 550 No passing DKIM signature found:(RFC 7372)
426             # This status code is returned when a message did not contain any passing DKIM
427             # signatures. (This violates the advice of Section 6.1 of [RFC6376].)
428             #
429             # X.7.21 550 No acceptable DKIM signature found:(RFC 7372, 6476)
430             # This status code is returned when a message contains one or more passing DKIM
431             # signatures, but none are acceptable. (This violates the advice of Section 6.1 of
432             # [RFC6376].)
433             #
434             # X.7.22 550 No valid author-matched DKIM signature found:(RFC 7372)
435             # This status code is returned when a message contains one or more passing DKIM
436             # signatures, but none are acceptable because none have an identifier(s) that
437             # matches the author address(es) found in the From header field. This is a special
438             # case of X.7.21. (This violates the advice of Section 6.1 of [RFC6376].)
439             #
440             # X.7.23 550 SPF validation failed:(RFC 7273, 7208)
441             # This status code is returned when a message completed an SPF check that produced
442             # a "fail" result, contrary to local policy requirements. Used in place of 5.7.1 as
443             # described in Section 8.4 of [RFC7208].
444             #
445             # X.7.24 451 SPF validation error:(RFC 7372, 7208)
446             # 550 This status code is returned when evaluation of SPF relative to an arriving
447             # message resulted in an error. Used in place of 4.4.3 or 5.5.2 as described in
448             # Sections 8.6 and 8.7 of [RFC7208].
449             #
450             # X.7.25 550 Reverse DNS validation failed:(RFC 7372, 7601)
451             # This status code is returned when an SMTP client's IP address failed a reverse
452             # DNS validation check, contrary to local policy requirements.
453             #
454             # X.7.26 550 Multiple authentication checks failed:(RFC 7372)
455             # This status code is returned when a message failed more than one message
456             # authentication check, contrary to local policy requirements. The particular
457             # mechanisms that failed are not specified.
458             #
459             # X.7.27 550 Sender address has null MX:(RFC 7505)
460             # This status code is returned when the associated sender address has a null MX,
461             # and the SMTP receiver is configured to reject mail from such sender
462             # (e.g., because it could not return a DSN).
463             # -------------------------------------------------------------------------------------------------
464             # SAMPLES
465             # 554 5.5.0 No recipients have been specified
466             # 503 5.5.0 Valid RCPT TO required before BURL
467             # 554 5.6.3 Conversion required but not supported
468             # 554 5.3.4 Message too big for system
469             # 554 5.7.8 URL resolution requires trust relationship
470             # 552 5.2.2 Mailbox full
471             # 554 5.6.6 IMAP URL resolution failed
472             # 250 2.5.0 Waiting for additional BURL or BDAT commands
473             # 451 4.4.1 IMAP server unavailable
474             # 250 2.5.0 Ok.
475             # 250 2.6.4 MIME header conversion with loss performed
476             # 235 2.7.0 Authentication Succeeded
477             # 432 4.7.12 A password transition is needed
478             # 454 4.7.0 Temporary authentication failure
479             # 534 5.7.9 Authentication mechanism is too weak
480             # 535 5.7.8 Authentication credentials invalid
481             # 500 5.5.6 Authentication Exchange line is too long
482             # 530 5.7.0 Authentication required
483             # 538 5.7.11 Encryption required for requested authentication
484             # 5.7.8 Authentication credentials invalid
485             # 5.7.9 Authentication mechanism is too weak
486             # 5.7.11 Encryption required for requested authentication mechanism
487             # -------------------------------------------------------------------------------------------------
488 93         23935 use constant StandardCode => {
489             '2.1.5' => 'delivered', # Successfully delivered
490             # ---------------------------------------------------------------------------------------------
491             '4.1.6' => 'hasmoved', # Destination mailbox has moved, No forwarding address
492             '4.1.7' => 'rejected', # Bad sender's mailbox address syntax
493             '4.1.8' => 'rejected', # Bad sender's system address
494             '4.1.9' => 'systemerror', # Message relayed to non-compliant mailer
495             '4.2.1' => 'suspend', # Mailbox disabled, not accepting messages
496             '4.2.2' => 'mailboxfull', # Mailbox full
497             '4.2.3' => 'emailtoolarge', # Message length exceeds administrative limit
498             '4.2.4' => 'systemerror', # Mailing list expansion problem
499             #'4.3.0' => 'systemerror', # Other or undefined mail system status
500             '4.3.1' => 'systemfull', # Mail system full
501             '4.3.2' => 'notaccept', # System not accepting network messages
502             '4.3.3' => 'systemerror', # System not capable of selected features
503             '4.3.5' => 'systemerror', # System incorrectly configured
504             #'4.4.0' => 'networkerror', # Other or undefined network or routing status
505             '4.4.1' => 'expired', # No answer from host
506             '4.4.2' => 'networkerror', # Bad connection
507             '4.4.3' => 'systemerror', # Directory server failure
508             '4.4.4' => 'networkerror', # Unable to route
509             '4.4.5' => 'systemfull', # Mail system congestion
510             '4.4.6' => 'networkerror', # Routing loop detected
511             '4.4.7' => 'expired', # Delivery time expired
512             '4.4.8' => 'networkerror', # Retry on IPv4
513             #'4.5.0' => 'networkerror', # Other or undefined protocol status
514             '4.5.3' => 'ratelimited', # Too many recipients
515             '4.5.5' => 'systemerror', # Wrong protocol version
516             '4.6.0' => 'contenterror', # Other or undefined media error
517             '4.6.2' => 'contenterror', # Conversion required and prohibited
518             '4.6.5' => 'contenterror', # Conversion Failed
519             #'4.7.0' => 'securityerror', # Other or undefined security status
520             '4.7.1' => 'blocked', # Delivery not authorized, message refused
521             '4.7.2' => 'rejected', # Mailing list expansion prohibited
522             '4.7.5' => 'securityerror', # Cryptographic failure
523             '4.7.6' => 'securityerror', # Cryptographic algorithm not supported
524             '4.7.7' => 'securityerror', # Message integrity failure
525             '4.7.12' => 'securityerror', # A password transition is needed
526             '4.7.15' => 'securityerror', # Priority Level is too low
527             '4.7.16' => 'emailtoolarge', # Message is too big for the specified priority
528             '4.7.24' => 'authfailure', # SPF validation error
529             '4.7.25' => 'requireptr', # Reverse DNS validation failed
530             '4.7.26' => 'authfailure', # Must pass either SPF or DKIM validation
531             # ---------------------------------------------------------------------------------------------
532             '5.1.0' => 'userunknown', # Other address status
533             '5.1.1' => 'userunknown', # Bad destination mailbox address
534             '5.1.2' => 'hostunknown', # Bad destination system address
535             '5.1.3' => 'userunknown', # Bad destination mailbox address syntax
536             '5.1.4' => 'filtered', # Destination mailbox address ambiguous
537             '5.1.6' => 'hasmoved', # Destination mailbox has moved, No forwarding address
538             '5.1.7' => 'rejected', # Bad sender's mailbox address syntax
539             '5.1.8' => 'rejected', # Bad sender's system address
540             '5.1.9' => 'systemerror', # Message relayed to non-compliant mailer
541             '5.1.10' => 'notaccept', # Recipient address has null MX
542             '5.2.0' => 'filtered', # Other or undefined mailbox status
543             '5.2.1' => 'filtered', # Mailbox disabled, not accepting messages
544             '5.2.2' => 'mailboxfull', # Mailbox full
545             '5.2.3' => 'emailtoolarge', # Message length exceeds administrative limit
546             '5.2.4' => 'systemerror', # Mailing list expansion problem
547             '5.3.0' => 'systemerror', # Other or undefined mail system status
548             '5.3.1' => 'systemfull', # Mail system full
549             '5.3.2' => 'notaccept', # System not accepting network messages
550             '5.3.3' => 'systemerror', # System not capable of selected features
551             '5.3.4' => 'emailtoolarge', # Message too big for system
552             '5.3.5' => 'systemerror', # System incorrectly configured
553             '5.4.0' => 'networkerror', # Other or undefined network or routing status
554             '5.4.3' => 'systemerror', # Directory server failure
555             '5.4.4' => 'hostunknown', # Unable to route
556             '5.5.2' => 'systemerror', # If the server cannot BASE64 decode any client response (AUTH)
557             '5.5.3' => 'ratelimited', # Too many recipients
558             '5.5.4' => 'systemerror', # Invalid command arguments
559             '5.5.5' => 'systemerror', # Wrong protocol version
560             '5.5.6' => 'syntaxerror', # Authentication Exchange line is too long
561             '5.6.0' => 'contenterror', # Other or undefined media error
562             '5.6.1' => 'contenterror', # Media not supported
563             '5.6.2' => 'contenterror', # Conversion required and prohibited
564             '5.6.3' => 'contenterror', # Conversion required but not supported
565             '5.6.5' => 'contenterror', # Conversion Failed
566             '5.6.6' => 'contenterror', # Message content not available
567             '5.6.7' => 'rejected', # Non-ASCII addresses not permitted for that sender/recipient
568             '5.6.8' => 'contenterror', # UTF-8 string reply is required, but not permitted by the SMTP client
569             '5.6.9' => 'contenterror', # UTF-8 header message cannot be transferred to one or more recipients
570             '5.7.0' => 'securityerror', # Other or undefined security status
571             '5.7.1' => 'securityerror', # Delivery not authorized, message refused
572             '5.7.2' => 'securityerror', # Mailing list expansion prohibited
573             '5.7.3' => 'securityerror', # Security conversion required but not possible
574             '5.7.4' => 'securityerror', # Security features not supported
575             '5.7.5' => 'securityerror', # Cryptographic failure
576             '5.7.6' => 'securityerror', # Cryptographic algorithm not supported
577             '5.7.7' => 'securityerror', # Message integrity failure
578             '5.7.8' => 'securityerror', # Authentication credentials invalid
579             '5.7.9' => 'securityerror', # Authentication mechanism is too weak
580             '5.7.10' => 'securityerror', # Encryption Needed
581             '5.7.11' => 'securityerror', # Encryption required for requested authentication mechanism
582             '5.7.13' => 'suspend', # User Account Disabled
583             '5.7.14' => 'securityerror', # Trust relationship required
584             '5.7.15' => 'securityerror', # Priority Level is too low
585             '5.7.16' => 'emailtoolarge', # Message is too big for the specified priority
586             '5.7.17' => 'hasmoved', # Mailbox owner has changed
587             '5.7.18' => 'hasmoved', # Domain owner has changed
588             '5.7.19' => 'systemerror', # RRVS test cannot be completed
589             '5.7.20' => 'authfailure', # No passing DKIM signature found
590             '5.7.21' => 'authfailure', # No acceptable DKIM signature found
591             '5.7.22' => 'authfailure', # No valid author-matched DKIM signature found
592             '5.7.23' => 'authfailure', # SPF validation failed
593             '5.7.24' => 'authfailure', # SPF validation error
594             '5.7.25' => 'requireptr', # Reverse DNS validation failed
595             '5.7.26' => 'authfailure', # Multiple authentication checks failed
596             '5.7.27' => 'notaccept', # MX resource record of a destination host is Null MX: RFC7505
597             '5.7.28' => 'spamdetected', # The message appears to be part of a mail flood of similar abusive messages.
598             '5.7.29' => 'authfailure', # This status code may be returned when a message fails ARC validation.
599             '5.7.30' => 'failedstarttls', # REQUIRETLS support required
600 93     93   599 };
  93         162  
601              
602 93         119888 use constant InternalCode => {
603             'authfailure' => ['5.9.130', '4.9.130'],
604             'badreputation' => ['5.9.132', '4.9.132'],
605             'blocked' => ['5.9.134', '4.9.134'],
606             'contenterror' => ['5.9.160', '4.9.160'],
607             'emailtoolarge' => ['5.9.161', '4.9.161'],
608             'expired' => ['5.9.340', '4.9.340'],
609             'failedstarttls' => ['5.9.350', '4.9.350'],
610             'filtered' => ['5.9.210', '4.9.210'],
611             'hasmoved' => ['5.9.211', ''],
612             'hostunknown' => ['5.9.212', ''],
613             'mailboxfull' => ['5.9.220', '4.9.220'],
614             'mailererror' => ['5.9.230', '4.9.230'],
615             'networkerror' => ['5.9.341', '4.9.341'],
616             'norelaying' => ['5.9.214', '4.9.214'],
617             'notaccept' => ['5.9.215', '4.9.215'],
618             'notcompliantrfc' => ['5.9.162', '4.9.162'],
619             'onhold' => ['5.9.301', '4.9.301'],
620             'policyviolation' => ['5.9.371', '4.9.371'],
621             'ratelimited' => ['5.9.131', '4.9.131'],
622             'rejected' => ['5.9.110', '4.9.110'],
623             'requireptr' => ['5.9.133', '4.9.133'],
624             'securityerror' => ['5.9.370', '4.9.370'],
625             'spamdetected' => ['5.9.164', '4.9.164'],
626             'suppressed' => ['5.9.310', '4.9.310'],
627             'suspend' => ['5.9.221', '4.9.221'],
628             'syntaxerror' => ['5.9.351', '4.9.351'],
629             'systemerror' => ['5.9.231', '4.9.231'],
630             'systemfull' => ['5.9.232', '4.9.232'],
631             'undefined' => ['5.9.300', '4.9.300'],
632             'userunknown' => ['5.9.213', ''],
633             'virusdetected' => ['5.9.165', '4.9.165'],
634 93     93   474 };
  93         179  
635              
636             sub code {
637             # Convert from the reason string to the internal status code
638             # @param [String] argv1 Reason name
639             # @param [Integer] argv2 0: Permanent error
640             # 1: Temporary error
641             # @return [String] D.S.N. or empty if the 1st argument is missing
642             # @see name
643             # @since v4.14.0
644 898     898 1 245751 my $class = shift;
645 898   100     2000 my $argv1 = shift || return "";
646 897   100     3398 my $argv2 = shift // 0;
647 897   100     2709 my $pairs = InternalCode->{ $argv1 } || return "";
648 781 100       2662 return $argv2 ? $pairs->[1] : $pairs->[0];
649             }
650              
651             sub name {
652             # Convert from the status code to the reason string
653             # @param [String] argv1 Status code(DSN)
654             # @return [String] Reason name or empty if the first argument did
655             # not match with values in Sisimai's reason list
656             # @see code
657             # @since v4.14.0
658 16600     16600 1 33293 my $class = shift;
659 16600 100 100     33734 my $argv1 = shift || return ""; return '' unless __PACKAGE__->test($argv1);
  12402         18138  
660 12258   100     45548 return StandardCode->{ $argv1 } // '';
661             }
662              
663             sub test {
664             # Check whether a status code is a valid code or not
665             # @param [String] argv1 Status code(DSN)
666             # @return [Boolean] 0 = Invalid status code, 1 = Valid status code
667             # @see code
668             # @since v5.0.0
669 12732     12732 1 19295 my $class = shift;
670 12732 100 100     17634 my $argv1 = shift || return 0; return 0 if length $argv1 < 5 || length $argv1 > 7;
  12731   100     30371  
671              
672 12727         12615 my $token = []; push @$token, int $_ for split(/[.]/, $argv1);
  12727         63381  
673 12727 100       21425 return 0 unless scalar @$token == 3;
674 12726 100       17272 return 0 if $token->[0] < 2;
675 12725 100       15962 return 0 if $token->[0] == 3;
676 12724 100       17520 return 0 if $token->[0] > 5;
677 12723 100       15408 return 0 if $token->[1] < 0;
678 12722 100       15781 return 0 if $token->[1] > 7;
679 12577 100       15324 return 0 if $token->[2] < 0;
680 12576         22887 return 1;
681             }
682              
683             sub find {
684             # Get a DSN code value from given string including DSN
685             # @param [String] argv1 String including DSN
686             # @param [String] argv2 An SMTP Reply Code or 2 or 4 or 5
687             # @return [String] An SMTP Status Code
688             # @since v4.14.0
689 7516     7516 1 18836 my $class = shift;
690 7516 100 100     11899 my $argv1 = shift || return ""; return "" if length $argv1 < 7;
  7515         11714  
691 7271   100     16072 my $argv2 = shift || '';
692              
693 7271         9812 my $givenclass = substr($argv2, 0, 1);
694 7271 100 100     27812 my $eestatuses = $givenclass eq '2' || $givenclass eq '4' || $givenclass eq '5' ? [$givenclass.'.'] : ['5.', '4.', '2.'];
695 7271         12178 my $esmtperror = ' '.$argv1.' ';
696 7271         8628 my $lookingfor = {};
697              
698 7271         23517 for my $e ( Sisimai::RFC791->find($esmtperror)->@* ) {
699             # Rewrite an IPv4 address in the given string(argv1) with '***.***.***.***'
700 2916 50       5227 my $p0 = index($esmtperror, $e); next if $p0 == -1;
  2916         4686  
701 2916         5686 substr($esmtperror, $p0, length $e, '***.***.***.***');
702             }
703              
704 7271         21435 for my $e ( @$eestatuses ) {
705             # Count the number of "5.", "4.", and "2." in the error message
706 20901         17492 my $p0 = 0;
707 20901         17345 my $p1 = 0;
708 20901         24393 while($p0 > -1) {
709             # Find all of the "5." and "4." string and store its postion
710 26463 100       29125 $p0 = index($esmtperror, $e, $p1); last if $p0 == -1;
  26463         34910  
711 5562         17393 $lookingfor->{ sprintf("%04d", $p0) } = $e;
712 5562         8165 $p1 = $p0 + 5;
713             }
714             }
715 7271 100       25426 return '' unless scalar keys %$lookingfor;
716              
717 3065         4747 my $statuscode = []; # List of SMTP Status Code, Keep the order of appearances
718 3065         3392 my $anotherone = ''; # Alternative code
719 3065         2879 my $readbuffer = '';
720 3065         2893 my $characters = []; # Characters around the status code found by index()
721 3065         3066 my $indexofees = -1; # A position of SMTP status code found by the index()
722              
723 3065         8959 for my $e ( sort keys %$lookingfor ) {
724             # Try to find an SMTP Status Code from the given string
725 5562 50       9238 $indexofees = index($esmtperror, $lookingfor->{ $e }, int $e); next if $indexofees == -1;
  5562         7458  
726 5562   50     20967 $characters = [
      50        
      50        
727             ord(substr($esmtperror, $indexofees - 1, 1)) || 0, # [0] The previous character of the status
728             ord(substr($esmtperror, $indexofees + 2, 1)) || 0, # [1] The value of the "Subject", "5.[7].261"
729             ord(substr($esmtperror, $indexofees + 3, 1)) || 0, # [2] "." chacater, a separator of the Subject and the Detail
730             ];
731              
732 5562 100 100     13397 next if $characters->[0] > 45 && $characters->[0] < 58; # Previous character is a number
733 4040 50 33     10704 next if $characters->[0] == 86 || $characters->[0] == 118; # Avoid a version number("V" or "v")
734 4040 100 100     9763 next if $characters->[1] < 48 || $characters->[1] > 55; # The value of the subject is not a number(0-7)
735 3786 100       5232 next if $characters->[2] != 46; # It is not a "." character: a separator
736              
737 3744         7284 $readbuffer = $lookingfor->{ $e }.chr($characters->[1]).'.';
738 3744   50     18713 push @$characters, ord(substr($esmtperror, $indexofees + 4, 1)) || 0, # [3] The 1st digit of the detail
      50        
      50        
      100        
739             ord(substr($esmtperror, $indexofees + 5, 1)) || 0, # [4] The 2nd digit of the detail
740             ord(substr($esmtperror, $indexofees + 6, 1)) || 0, # [5] The 3rd digit of the detail
741             ord(substr($esmtperror, $indexofees + 7, 1)) || 0; # [6] The next character
742              
743 3744 100 66     9490 next if $characters->[3] < 48 || $characters->[3] > 57; # The 1st digit of the detail is not a number
744 3738         4993 $readbuffer .= chr $characters->[3];
745              
746 3738 100 100     7292 if( Sisimai::SMTP::Status->is_ambiguous($readbuffer) || $readbuffer eq "4.4.7" ) {
747             # Find another status code except *.0.0, 4.4.7
748 199         311 $anotherone = $readbuffer;
749 199         295 next;
750             }
751              
752 3539 100 100     7666 if( $characters->[4] < 48 || $characters->[4] > 57 ) {
753             # The 2nd digit of the detail is not a number
754 3040         4557 push @$statuscode, $readbuffer;
755 3040         3988 next;
756             }
757 499         632 $readbuffer .= chr $characters->[4]; # The 2nd digit of the detail is a number
758              
759 499 100 66     984 if( $characters->[5] < 48 || $characters->[5] > 57 ) {
760             # The 3rd digit of the detail is not a number
761 359         520 push @$statuscode, $readbuffer;
762 359         442 next;
763             }
764 140         192 $readbuffer .= chr $characters->[5]; # The 3rd digit of the detail is a number
765              
766 140 50 33     343 next if $characters->[6] > 47 && $characters->[6] < 58;
767 140         225 push @$statuscode, $readbuffer;
768             }
769 3065 100       6960 push @$statuscode, $anotherone if length $anotherone;
770 3065 100       6740 return '' if scalar @$statuscode == 0;
771              
772             # Select one from picked status codes
773 2582         3788 my $cv = shift @$statuscode; for my $e ( @$statuscode ) { $cv = __PACKAGE__->prefer($cv, $e, "") }
  2582         3980  
  1146         2136  
774 2582         12586 return $cv;
775             }
776              
777             sub prefer {
778             # Return the preferred value selected from the arguments
779             # @param [String] argv0 The value of Status:
780             # @param [String] argv1 The delivery status picked from the error message
781             # @param [String] argv2 The value of An SMTP Reply Code
782             # @return [String] The preferred value
783             # @since v5.0.0
784 5031     5031 1 6784 my $class = shift;
785 5031   100     9198 my $argv0 = shift || '';
786 5031   100     9228 my $argv1 = shift || '';
787 5031   100     8780 my $argv2 = shift || '';
788              
789 5031 100 100     8997 my $statuscode = $argv0 || return $argv1; return $argv1 unless length $statuscode > 4;
  3466         5085  
790 3465 100 100     7118 my $codeinmesg = $argv1 || return $argv0; return $argv0 unless length $codeinmesg > 4;
  2520         4060  
791 2519 50       4604 return $codeinmesg if index($statuscode, '.9.') == 1;
792              
793 2519   100     4190 my $esmtpreply = $argv2 || 0;
794 2519         9694 my $the1stchar = {
795             'field' => int substr($statuscode, 0, 1),
796             'error' => int substr($codeinmesg, 0, 1),
797             'reply' => int substr($esmtpreply, 0, 1),
798             };
799              
800 2519 100 100     7261 if( $the1stchar->{'reply'} > 0 && $the1stchar->{'field'} != $the1stchar->{'error'} ) {
801             # There is the 3rd argument (an SMTP Reply Code)
802             # Returns the value of $argv0 or $argv1 which begins with the 1st character of $argv2
803 23 100       75 return $statuscode if $the1stchar->{'reply'} == $the1stchar->{'field'};
804 21 50       115 return $codeinmesg if $the1stchar->{'reply'} == $the1stchar->{'error'};
805             }
806 2496 100       7300 return $statuscode if $statuscode eq $codeinmesg;
807              
808 383         897 my $zeroindex1 = {'field' => index($statuscode, '.0'), 'error' => index($codeinmesg, '.0') };
809 383         879 my $zeroindex2 = {'field' => index($statuscode, '.0.0'), 'error' => index($codeinmesg, '.0.0')};
810              
811 383 100       714 if( $zeroindex2->{'field'} > 0 ) {
812             # "Status:" field is "X.0.0"
813 75 50       394 return $codeinmesg if $zeroindex2->{'error'} < 0;
814 0         0 return $statuscode;
815             }
816              
817 308 100       595 if( $zeroindex1->{'field'} > 0 ) {
818             # "Status:" field is "X.Y.0" or "X.0.Z"
819 65 100       269 return $codeinmesg if $zeroindex1->{'error'} < 0;
820             }
821              
822 264 100       675 return $statuscode if $zeroindex2->{'error'} > 0; # An SMTP status code is "X.0.0"
823 202 100       603 return $codeinmesg if $statuscode eq '4.4.7'; # "4.4.7" is an ambiguous code
824 166 100       334 return $codeinmesg if $statuscode eq '4.7.0'; # "4.7.0" indicates "too many errors"
825 155 50       346 return $codeinmesg if index($statuscode, '5.3.') == 0; # "5.3.Z" is an error of a system
826 155 100       335 return $codeinmesg if index($statuscode, '.5.1') > 0; # "X.5.1" indicates an invalid command
827 144 50       323 return $codeinmesg if index($statuscode, '.5.2') > 0; # "X.5.2" indicates a syntax error
828 144 50       312 return $codeinmesg if index($statuscode, '.5.4') > 0; # "X.5.4" indicates an invalid command arguments
829 144 50       280 return $codeinmesg if index($statuscode, '.5.5') > 0; # "X.5.5" indicates a wrong protocol version
830              
831 144 100       427 if( $statuscode eq '5.1.1' ) {
    100          
832             # "5.1.1" is a code of "userunknown"
833 37 100 100     271 return $statuscode if index($codeinmesg, '5.5.') == 0 || $zeroindex1->{'error'} > 0;
834 10         53 return $codeinmesg;
835              
836             } elsif( $statuscode eq '5.1.3' ) {
837             # "5.1.3"
838 5 50       28 return $codeinmesg if index($codeinmesg, '5.7.') == 0;
839             }
840 102         330 return $statuscode;
841             }
842              
843             sub is_explicit {
844             # is_explicit() returns 0 when the argument is empty or is an internal status code
845             # @param string argv1 Delivery status code
846             # @return bool 0: The delivery status is not explicit
847 92     92 1 39408 my $class = shift;
848 92   100     225 my $argv1 = shift || return 0;
849              
850 91 100 66     227 return 0 if length($argv1) == 7 && index($argv1, ".9.") == 1;
851 89         198 return 1;
852             }
853              
854             sub is_ambiguous {
855             # is_ambiguous() returns 1 when the argument is not empty and is ends with ".0.0".
856             # @param string argv1 Delivery status code
857             # @return bool 1: The delivery status is ambiguous
858 4552     4552 1 6822 my $class = shift;
859 4552   100     6981 my $argv1 = shift || return 1;
860 4364 100 100     13272 return 1 if length($argv1) == 5 && substr($argv1, -4, 4) eq ".0.0";
861 4012         10383 return 0
862             }
863              
864             1;
865             __END__