Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eliottvincent committed Dec 20, 2023
1 parent 09a5340 commit 1fd7e57
Show file tree
Hide file tree
Showing 30 changed files with 724 additions and 16 deletions.
27 changes: 15 additions & 12 deletions lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ var ERROR_CODES_TYPES = {
"550 5.1.1" : "no_such_recipient",
"550 5.2.1" : "recipient_disabled_or_recipient_rate_limited",
"550 5.7.1" : "spam_content",
"550 5.7.26" : "authentication_failure",
"551" : "user_not_local",
"552" : "action_aborted_exceeded_storage_allocation",
"552 5.2.2" : "mailbox_over_quota",
"552 5.2.3" : "message_size_limit",
"553" : "action_not_taken_mailbox_name_not_allowed",
"553 5.1.2" : "no_such_recipient",
"554" : "transaction_failed",
"554 5.7.1" : "spam_content",
"555" : "parameters_not_recognized",
Expand Down Expand Up @@ -78,19 +80,20 @@ var REGEXES = {
/Message rejected by\:\s+([\S\.]+?)$/m, // Outlook error
/from (\S+) \[([\d\.]+)\](?:\:(\d+)\:)?/m,
/conversation with (\S+)\[([\d\.]+)\](?:\:(\d+)\:)? timed out/m,
/lost connection with (\S+)\[([\d\.]+)\](?:\:(\d+)\:)?/m, // "lost connection with mx.mail-data.net[134.244.220.69]"
/Generating server: (\S+)(?:\[([\d\.]+)\])?(?:\:(\d+)\:)?/m // "Generating server: PH7PR02MB9549495.namprd02.prod.outlook.com"
],

error : [
/said\: (\d{3}(?:[\s\-]\d\.\d\.\d{1,3})?) (.+) \(in reply to/,
/said\: (\d{3}(?:[\s\-]\d\.\d\.\d{1,3})?)-(.+)/,
/said\: (\d{3}(?:[\s\-\#\']{1,2}\d\.\d\.\d{1,3})?) (.+) \(in reply to/,
/said\: (\d{3}(?:[\s\-\#\']{1,2}\d\.\d\.\d{1,3})?)-(.+)/,
/(\d{3}\-\'\d\.\d\.\d{1,3}) (.+)/,
/LMTP error after .+?\:\<.+?\>\: (\d{3}(?:[\s\-]\d\.\d\.\d{1,3})?) <.+?\>(.+)$/m,
/remote server returned \'(\d{3}(?:[\s\-]\d\.\d\.\d{1,3})?) (.+)\'/i,
/The response from the remote server was:\s(\d{3}(?:[\s\-]\d\.\d\.\d{1,3})?) (.+)/,
/refused to talk to me\: (\d{3}(?:[\s\-]\d\.\d\.\d{1,3})?) (.+)/,
/(?:error|reason)\:\s*?(\d{3}(?:[\s\-]\d\.\d\.\d{1,3})?) (.+)/i,
/(\d{3}[\s\-]\d\.\d\.\d{1,3})/,
/LMTP error after .+?\:\<.+?\>\: (\d{3}(?:[\s\-\#\']{1,2}\d\.\d\.\d{1,3})?) <.+?\>(.+)$/m,
/remote server returned \'(\d{3}(?:[\s\-\#\']{1,2}\d\.\d\.\d{1,3})?) (.+)\'/i,
/The response from the remote server was:\s(\d{3}(?:[\s\-\#\']{1,2}\d\.\d\.\d{1,3})?) (.+)/,
/refused to talk to me\: (\d{3}(?:[\s\-\#\']{1,2}\d\.\d\.\d{1,3})?) (.+)/,
/(?:error|reason)\:\s*?(\d{3}(?:[\s\-\#\']{1,2}\d\.\d\.\d{1,3})?) (.+)/i,
/(\d{3}[\s\-\#\']{1,2}\d\.\d\.\d{1,3})/,
/(\d{3}\-\'\d\.\d\.\d{1,3})/
],

Expand Down Expand Up @@ -122,7 +125,7 @@ var REGEXES = {
],

temporary_safe : /(temporary|temporarily)/i,
blocked : /((?:is listed)|blocked|banned|denied|dnsbl)/i,
blocked : /((?:is listed)|blocked|block list|banned|denied|dnsbl)/i,
spam : /(spam)/i,

enhanced_types : {
Expand Down Expand Up @@ -150,13 +153,13 @@ var REGEXES = {
],

reputation : [
/(rate limited due to IP reputation)/i
/(rate limited due to IP reputation)/i,
/(new or untrusted IP)/i
]
},

error_code : [
/(\d{3})[\s\-](\d\.\d\.\d{1,3})/, // "550 5.4.1" or "550-5.4.1" or "550-5.4.11" or "550-5.4.110"
/(\d{3})\-\'(\d\.\d\.\d{1,3})/, // "550-'5.4.1" or "550-'5.4.11" or "550-'5.4.110"
/(\d{3})[\s\-\#\']{1,2}(\d\.\d\.\d{1,3})/, // "550 5.4.1" or "550 #5.4.1" or "550-5.4.1" or "550-'5.4.1"
/(\d{3})/ // "550"
]
};
Expand Down
16 changes: 16 additions & 0 deletions test/fixtures/421_4_7_0_deferred.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
This is the mail system at host mailer.acme.email.

I'm sorry to have to inform you that your message could not
be delivered to one or more recipients. It's attached below.

For further assistance, please send mail to postmaster.

If you do so, please include this problem report. You can
delete your own text from the attached returned message.

The mail system

<[email protected]>: host mta6.am0.yahoodns.net[76.159.240.37] said: 421
4.7.0 [TSS04] Messages from 39.177.48.16 temporarily deferred due to
unexpected volume or user complaints - 4.16.55.1; see
https://postmaster.yahooinc.com/error-codes (in reply to MAIL FROM command)
21 changes: 21 additions & 0 deletions test/fixtures/450_4_2_1_rate_limited.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
This is the mail system at host mailer.acme.email.

I'm sorry to have to inform you that your message could not
be delivered to one or more recipients. It's attached below.

For further assistance, please send mail to postmaster.

If you do so, please include this problem report. You can
delete your own text from the attached returned message.

The mail system

<[email protected]>: host alt1.gmail-smtp-in.l.google.com[124.215.9.62] said:
450-4.2.1 The user you are trying to contact is receiving mail at a rate
that 450-4.2.1 prevents additional messages from being delivered. Please
resend your 450-4.2.1 message at a later time. If the user is able to
receive mail at that 450-4.2.1 time, your message will be delivered. For
more information, please 450-4.2.1 visit 450 4.2.1
https://support.google.com/mail/?p=ReceivingRate
f15-20020a056402354f00b00548d4febb0bsi965249edd.614 - gsmtp (in reply to
RCPT TO command)
15 changes: 15 additions & 0 deletions test/fixtures/451_4_7_1_reputation.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
This is the mail system at host mailer.acme.email.

I'm sorry to have to inform you that your message could not
be delivered to one or more recipients. It's attached below.

For further assistance, please send mail to postmaster.

If you do so, please include this problem report. You can
delete your own text from the attached returned message.

The mail system

<[email protected]>: host mx2.emailsrvr.com[180.166.34.2] said: 451 4.7.1
Received too many messages from a new or untrusted IP: 93.177.84.61
(Z27/6DC2420) (G28) (in reply to RCPT TO command)
18 changes: 18 additions & 0 deletions test/fixtures/451_4_7_500_server_busy.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
This is the mail system at host mailer.acme.email.

I'm sorry to have to inform you that your message could not
be delivered to one or more recipients. It's attached below.

For further assistance, please send mail to postmaster.

If you do so, please include this problem report. You can
delete your own text from the attached returned message.

The mail system

<[email protected]>: host
etzzogal-com0i.mail.protection.outlook.com[140.74.42.63] said: 451 4.7.500
Server busy. Please try again later from [39.177.48.16]. (S77714)
[QE2FRA04FT039.eop-fra04.prod.protection.outlook.com
2023-11-23T18:53:22.058Z 10DSKD34941BC6NE] (in reply to end of DATA
command)
14 changes: 14 additions & 0 deletions test/fixtures/550_5_0_1_no_such_recipient.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
This is the mail system at host mailer.acme.email.

I'm sorry to have to inform you that your message could not
be delivered to one or more recipients. It's attached below.

For further assistance, please send mail to postmaster.

If you do so, please include this problem report. You can
delete your own text from the attached returned message.

The mail system

<[email protected]>: host mxb.mailgun.org[43.106.31.24] said:
550 5.0.1 Recipient rejected (in reply to RCPT TO command)
14 changes: 14 additions & 0 deletions test/fixtures/550_5_1_0_address_rejected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
This is the mail system at host mailer.acme.email.

I'm sorry to have to inform you that your message could not
be delivered to one or more recipients. It's attached below.

For further assistance, please send mail to postmaster.

If you do so, please include this problem report. You can
delete your own text from the attached returned message.

The mail system

<[email protected]>: host mx1.hc3459-45.iphmx.com[193.183.64.148] said:
550 #5.1.0 Address rejected. (in reply to RCPT TO command)
20 changes: 20 additions & 0 deletions test/fixtures/550_5_7_1_blocked.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
This is the mail system at host mailer.acme.email.

I'm sorry to have to inform you that your message could not
be delivered to one or more recipients. It's attached below.

For further assistance, please send mail to postmaster.

If you do so, please include this problem report. You can
delete your own text from the attached returned message.

The mail system

<[email protected]>: host
outlook-com.olc.protection.outlook.com[140.74.15.33] said: 550 5.7.1
Unfortunately, messages from [31.57.142.204] weren't sent. Please contact
your Internet service provider since part of their network is on our block
list (S3140). You can also refer your provider to
http://mail.live.com/mail/troubleshooting.aspx#errors.
[WP1FDK33EO054.eop-nam02.prod.protection.outlook.com
2023-01-01T00:00:00.001Z 03SDKS32D1WER234] (in reply to MAIL FROM command)
20 changes: 20 additions & 0 deletions test/fixtures/550_5_7_1_reputation_variant_1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
This is the mail system at host mailer.acme.email.

I'm sorry to have to inform you that your message could not
be delivered to one or more recipients. It's attached below.

For further assistance, please send mail to postmaster.

If you do so, please include this problem report. You can
delete your own text from the attached returned message.

The mail system

<[email protected]>: host
gmail-smtp-in.l.google.com[124.205.72.62] said: 550-5.7.1 [93.177.87.181
19] Gmail has detected that this message is likely 550-5.7.1 suspicious due
to the very low reputation of the sending domain. To 550-5.7.1 best protect
our users from spam, the message has been blocked. 550-5.7.1 Please visit
550 5.7.1 https://support.google.com/mail/answer/188131 for more
information. h6-20020a05640250c600b0054ab00d6afesi892868edb.356 - gsmtp (in
reply to end of DATA command)
15 changes: 15 additions & 0 deletions test/fixtures/550_5_7_1_service_refused.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
This is the mail system at host mailer.acme.email.

I'm sorry to have to inform you that your message could not
be delivered to one or more recipients. It's attached below.

For further assistance, please send mail to postmaster.

If you do so, please include this problem report. You can
delete your own text from the attached returned message.

The mail system

<[email protected]>: host smtpz4.laposte.net[106.29.142.66] said: 550 5.7.1
Service refuse. Veuillez essayer plus tard. service refused, please try
later. LPN007_510 (in reply to end of DATA command)
20 changes: 20 additions & 0 deletions test/fixtures/550_5_7_26_authentication_failure.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
This is the mail system at host mailer.acme.email.

I'm sorry to have to inform you that your message could not
be delivered to one or more recipients. It's attached below.

For further assistance, please send mail to postmaster.

If you do so, please include this problem report. You can
delete your own text from the attached returned message.

The mail system

<[email protected]>: host aspmx.l.google.com[124.205.72.62] said:
550-5.7.26 Unauthenticated email from acme.com is not accepted due to
domain's 550-5.7.26 DMARC policy. Please contact the administrator of
acme.com domain 550-5.7.26 if this was a legitimate mail. Please visit
550-5.7.26 https://support.google.com/mail/answer/2451690 to learn about
the 550 5.7.26 DMARC initiative.
v10-20020a170906488a11b0098d8390816asi945962ejq.756 - gsmtp (in reply to
end of DATA command)
15 changes: 15 additions & 0 deletions test/fixtures/554_5_2_3_policy_violation.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
This is the mail system at host mailer.acme.email.

I'm sorry to have to inform you that your message could not
be delivered to one or more recipients. It's attached below.

For further assistance, please send mail to postmaster.

If you do so, please include this problem report. You can
delete your own text from the attached returned message.

The mail system

<[email protected]>: host mx.zoho.eu[158.203.221.166] said: 554 5.2.3
MailPolicy violation Error delivering to mailboxes (in reply to end of DATA
command)
15 changes: 15 additions & 0 deletions test/fixtures/554_5_7_7_equal_headers.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
This is the mail system at host mailer.acme.email.

I'm sorry to have to inform you that your message could not
be delivered to one or more recipients. It's attached below.

For further assistance, please send mail to postmaster.

If you do so, please include this problem report. You can
delete your own text from the attached returned message.

The mail system

<[email protected]>: host spamrelay.zxcs.nl[158.140.82.21] said: 554 5.7.7 too
many equal X-headers (X-Original-Authentication-Results:) (in reply to end
of DATA command)
32 changes: 32 additions & 0 deletions test/fixtures/expected/421_4_7_0_deferred.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"bounce": true,
"email": {
"body": "This is the mail system at host mailer.acme.email.\n\nI'm sorry to have to inform you that your message could not be delivered to one or more recipients. It's attached below.\n\nFor further assistance, please send mail to postmaster.\n\nIf you do so, please include this problem report. You can delete your own text from the attached returned message.\n\nThe mail system\n\n<[email protected]>: host mta6.am0.yahoodns.net[76.159.240.37] said: 421 4.7.0 [TSS04] Messages from 39.177.48.16 temporarily deferred due to unexpected volume or user complaints - 4.16.55.1; see https://postmaster.yahooinc.com/error-codes (in reply to MAIL FROM command)",
"intro": "This is the mail system at host mailer.acme.email.\n\nI'm sorry to have to inform you that your message could not be delivered to one or more recipients. It's attached below.\n\nFor further assistance, please send mail to postmaster.\n\nIf you do so, please include this problem report. You can delete your own text from the attached returned message.\n\nThe mail system",
"error": "<[email protected]>: host mta6.am0.yahoodns.net[76.159.240.37] said: 421 4.7.0 [TSS04] Messages from 39.177.48.16 temporarily deferred due to unexpected volume or user complaints - 4.16.55.1; see https://postmaster.yahooinc.com/error-codes (in reply to MAIL FROM command)"
},
"data": {
"error": {
"code": {
"basic": "421",
"enhanced": "4.7.0"
},
"label": "[TSS04] Messages from 39.177.48.16 temporarily deferred due to unexpected volume or user complaints - 4.16.55.1; see https://postmaster.yahooinc.com/error-codes",
"type": "service_not_available",
"temporary": true,
"permanent": false,
"data": {
"type": null,
"blocked": false,
"spam": false
}
},
"recipient": "[email protected]",
"server": {
"hostname": "mta6.am0.yahoodns.net",
"ip": "76.159.240.37",
"port": null
},
"command": "MAIL FROM"
}
}
32 changes: 32 additions & 0 deletions test/fixtures/expected/450_4_2_1_rate_limited.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"bounce": true,
"email": {
"body": "This is the mail system at host mailer.acme.email.\n\nI'm sorry to have to inform you that your message could not be delivered to one or more recipients. It's attached below.\n\nFor further assistance, please send mail to postmaster.\n\nIf you do so, please include this problem report. You can delete your own text from the attached returned message.\n\nThe mail system\n\n<[email protected]>: host alt1.gmail-smtp-in.l.google.com[124.215.9.62] said: 450-4.2.1 The user you are trying to contact is receiving mail at a rate that 450-4.2.1 prevents additional messages from being delivered. Please resend your 450-4.2.1 message at a later time. If the user is able to receive mail at that 450-4.2.1 time, your message will be delivered. For more information, please 450-4.2.1 visit 450 4.2.1 https://support.google.com/mail/?p=ReceivingRate f15-20020a056402354f00b00548d4febb0bsi965249edd.614 - gsmtp (in reply to RCPT TO command)",
"intro": "This is the mail system at host mailer.acme.email.\n\nI'm sorry to have to inform you that your message could not be delivered to one or more recipients. It's attached below.\n\nFor further assistance, please send mail to postmaster.\n\nIf you do so, please include this problem report. You can delete your own text from the attached returned message.\n\nThe mail system",
"error": "<[email protected]>: host alt1.gmail-smtp-in.l.google.com[124.215.9.62] said: 450-4.2.1 The user you are trying to contact is receiving mail at a rate that 450-4.2.1 prevents additional messages from being delivered. Please resend your 450-4.2.1 message at a later time. If the user is able to receive mail at that 450-4.2.1 time, your message will be delivered. For more information, please 450-4.2.1 visit 450 4.2.1 https://support.google.com/mail/?p=ReceivingRate f15-20020a056402354f00b00548d4febb0bsi965249edd.614 - gsmtp (in reply to RCPT TO command)"
},
"data": {
"error": {
"code": {
"basic": "450",
"enhanced": "4.2.1"
},
"label": "The user you are trying to contact is receiving mail at a rate that 450-4.2.1 prevents additional messages from being delivered. Please resend your 450-4.2.1 message at a later time. If the user is able to receive mail at that 450-4.2.1 time, your message will be delivered. For more information, please 450-4.2.1 visit 450 4.2.1 https://support.google.com/mail/?p=ReceivingRate f15-20020a056402354f00b00548d4febb0bsi965249edd.614 - gsmtp",
"type": "action_not_taken_mailbox_unavailable",
"temporary": true,
"permanent": false,
"data": {
"type": "action_not_taken_mailbox_rate_limited",
"blocked": false,
"spam": false
}
},
"recipient": "[email protected]",
"server": {
"hostname": "alt1.gmail-smtp-in.l.google.com",
"ip": "124.215.9.62",
"port": null
},
"command": "RCPT TO"
}
}
32 changes: 32 additions & 0 deletions test/fixtures/expected/451_4_7_1_reputation.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"bounce": true,
"email": {
"body": "This is the mail system at host mailer.acme.email.\n\nI'm sorry to have to inform you that your message could not be delivered to one or more recipients. It's attached below.\n\nFor further assistance, please send mail to postmaster.\n\nIf you do so, please include this problem report. You can delete your own text from the attached returned message.\n\nThe mail system\n\n<[email protected]>: host mx2.emailsrvr.com[180.166.34.2] said: 451 4.7.1 Received too many messages from a new or untrusted IP: 93.177.84.61 (Z27/6DC2420) (G28) (in reply to RCPT TO command)",
"intro": "This is the mail system at host mailer.acme.email.\n\nI'm sorry to have to inform you that your message could not be delivered to one or more recipients. It's attached below.\n\nFor further assistance, please send mail to postmaster.\n\nIf you do so, please include this problem report. You can delete your own text from the attached returned message.\n\nThe mail system",
"error": "<[email protected]>: host mx2.emailsrvr.com[180.166.34.2] said: 451 4.7.1 Received too many messages from a new or untrusted IP: 93.177.84.61 (Z27/6DC2420) (G28) (in reply to RCPT TO command)"
},
"data": {
"error": {
"code": {
"basic": "451",
"enhanced": "4.7.1"
},
"label": "Received too many messages from a new or untrusted IP: 93.177.84.61 (Z27/6DC2420) (G28)",
"type": "action_aborted_local_error",
"temporary": true,
"permanent": false,
"data": {
"type": "reputation",
"blocked": false,
"spam": false
}
},
"recipient": "[email protected]",
"server": {
"hostname": "mx2.emailsrvr.com",
"ip": "180.166.34.2",
"port": null
},
"command": "RCPT TO"
}
}
Loading

0 comments on commit 1fd7e57

Please sign in to comment.