Skip to content

Commit

Permalink
Merge branch 'master' of github.com:crisp-oss/email-bounce-parser
Browse files Browse the repository at this point in the history
  • Loading branch information
valeriansaliou committed Jan 6, 2025
2 parents 7fba22a + 06d5cd7 commit eb16913
Show file tree
Hide file tree
Showing 43 changed files with 1,020 additions and 19 deletions.
32 changes: 18 additions & 14 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 All @@ -110,7 +113,7 @@ var REGEXES = {

recipient : [
/the following addresses had permanent fatal errors (?:.*?)\s\<(.+?)\>/i,
/there was a temporary problem delivering your message to (.+?). Gmail will retry/i,
/there was a temporary problem (?:while )?delivering your message to (.+?). Gmail will retry/i,
/the following message to \<(.+?)\> was undeliverable/i,
/to the following addresses:\s*(.+)/i,
/^your message wasn't delivered to (.+?)\s/mi, // "Your message wasn't delivered to [email protected]"
Expand All @@ -122,8 +125,8 @@ var REGEXES = {
],

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

enhanced_types : {
no_such_recipient : [
Expand All @@ -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 Expand Up @@ -552,6 +555,7 @@ class Parser {
_str = _str.replace(this.__regexes.line_break_double_indent_single, "\n\n");

// Replace single Line-break with regular space
// TODO: re2 doesn't support lookbehinds, so for now we use a pure-JS regex
_str = _str.replace(/(?<!\n)\n(?!\n)/gm, " ");

// Replace long indent with double Line-break
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "email-bounce-parser",
"version": "1.0.20",
"version": "1.0.22",
"description": "Parses bounce emails and extract errors",
"author": "Eliott Vincent <[email protected]>",
"main": "lib/index.js",
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)
14 changes: 14 additions & 0 deletions test/fixtures/450_rate_limited.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 mta6.am0.yahoodns.net[76.159.240.27] said: 450 User is
receiving mail too quickly tnmpmscs (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_4_0_hops.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
This is the mail system at host burns.eiro.biz.

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
balancer_haproxy.email.locaweb.com.br[1.13.102.292] said: 554 5.4.0 Error:
too many hops (in reply to end of DATA command)
15 changes: 15 additions & 0 deletions test/fixtures/554_5_7_105_sender_blocked.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
This is the mail system at host out41.mail.ovh.net.

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 mxplan3.mail.ovh.net[49.32.197.262]
said: 554 5.7.105 SenderFilterAgent; Sender denied as sender's email
address is on SenderFilterConfig list (in reply to end of DATA command)
15 changes: 15 additions & 0 deletions test/fixtures/554_5_7_1_no_such_recipient_variant_1.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 vero.in.mest.micro.com[81.280.22.8]
said: 554 5.7.1 <[email protected]>: Recipient address rejected:
BLOCK-SEND-ER. (in reply to RCPT TO command)
15 changes: 15 additions & 0 deletions test/fixtures/554_5_7_1_spam_content_variant_3.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 mx01.mail.icloud.com[71.75.155.43] said: 554
5.7.1 [CS01] Message rejected due to local policy. Please visit
https://support.apple.com/en-us/HT204137 (in reply to end of DATA command)
17 changes: 17 additions & 0 deletions test/fixtures/554_5_7_1_spam_content_variant_4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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 mail2.etecsa.net[118.252.213.4] said: 554 5.7.1
Service unavailable; Client host [39.177.48.171] blocked using
0spam.fusionzero.com; Received: from mailer-2w.outbound.crisp.email
([39.177.48.171]) Fri, 22 Sep 2023 01:01:01 +0000 Subject: Backlinking is
not that crazy anymore (in reply to RCPT TO command)
Loading

0 comments on commit eb16913

Please sign in to comment.