Skip to content

Commit

Permalink
Add reputation enhanced type
Browse files Browse the repository at this point in the history
  • Loading branch information
eliottvincent committed Dec 4, 2023
1 parent 0e9b0a0 commit f40c0cf
Show file tree
Hide file tree
Showing 10 changed files with 224 additions and 19 deletions.
36 changes: 24 additions & 12 deletions lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,13 @@ 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,
/the following message to \<(.+?)\> was undeliverable/i,
/to the following addresses:\s*(.+)/i,
/^\<(.+?)\>:/m,
/^(.+?)\s?(?:\s\(.*?\))?\n?\s*[\[|<]mailto\:(.+?)[\]|>]/mi, // "[email protected]<mailto:[email protected]>" or "[email protected][mailto:[email protected]]" or "[email protected] ([email protected])<mailto:[email protected]>"
/^your message wasn't delivered to (.+?)\s/mi, // "Your message wasn't delivered to [email protected]"
/^your message to (.+?) couldn\'t/mi, // "Your message to [email protected] couldn't"
/^(.+?)\s?(?:\s\(.*?\))?\n?\s*[\[|<]mailto\:(.+?)[\]|>]/mi, // "[email protected]<mailto:[email protected]>" or "[email protected][mailto:[email protected]]" or "[email protected] ([email protected])<mailto:[email protected]>"
/^\<(.+?)\>:/m,
/\<(.+?)\> \(expanded from \<.+?\>\)\:/, // "<[email protected]> (expanded from <[email protected]>): "
/\<(.+?)\>:/ // "<[email protected]>:"
],
Expand Down Expand Up @@ -147,6 +148,10 @@ var REGEXES = {
/(out of storage|(?:mailbox (?:is )?full)|(?:user (?:is )?over quota))/i // "user is over quota" (iCloud)
],

enhanced_types_reputation : [
/(rate limited due to IP reputation)/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"
Expand Down Expand Up @@ -299,21 +304,22 @@ class Parser {
_permanent = true;
}

// Make sure the bounce is actually permanent
if (_permanent === true) {
var _match = this.__regexes.temporary_safe.match(str);

if (_match && _match.length > 1) {
_temporary = true;
_permanent = false;
}
}

if (_code.basic) {
_type = ERROR_CODES_TYPES[_code.basic] || null
}
}

// In cases where the bounce is detected as permanent, or the \
// temporary / permanent status is still unclear, run additional detection
if (_permanent === true || (_temporary === false && _permanent === false)) {
var _match = this.__regexes.temporary_safe.match(str);

if (_match && _match.length > 1) {
_temporary = true;
_permanent = false;
}
}

// No label detected? Probably because there's no error code
if (!_label) {
// Attempt a lax check
Expand Down Expand Up @@ -409,6 +415,12 @@ class Parser {
_type = "mailbox_full";
}

_match = loopRegexes(this.__regexes.enhanced_types_reputation, str);

if (!_type && _match && _match.length > 1) {
_type = "reputation";
}

// Detect enhanced-type from enhanced error code
// Notice: this is done as a last resort, as sometimes enhanced code \
// doesn't clearly convey the actual error
Expand Down
17 changes: 17 additions & 0 deletions test/fixtures/451_4_7_650_reputation.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
outlook-com.olc.protection.outlook.com[140.74.55.33] said: 451 4.7.650 The
mail server [39.177.48.16] has been temporarily rate limited due to IP
reputation. For e-mail delivery information, see
https://postmaster.live.com (S843) (in reply to RCPT TO command)
27 changes: 27 additions & 0 deletions test/fixtures/550_5_7_129_restricted_permissions.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Delivery has failed to these recipients or groups:

[email protected]<mailto:[email protected]>
Your message couldn't be delivered to the recipient because you don't have permission to send to it.

Ask the recipient's email admin to add you to the accept list for the recipient.

For more information, see DSN 5.7.129 Errors in Exchange Online and Office 365<https://go.microsoft.com/fwlink/?LinkId=389365>.









Diagnostic information for administrators:

Generating server: EV2MR07MI7830.eurprd06.prod.outlook.com

[email protected]
Remote server returned '550 5.7.129 RESOLVER.RST.RestrictedToRecipientsPermission; not authorized to send to recipient because the sender isn't on the recipient's list of senders to accept mail from'

Original message headers:

REDACTED
9 changes: 9 additions & 0 deletions test/fixtures/550_5_7_1_reputation.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

** Delivery incomplete **

There was a temporary problem delivering your message to [email protected]. Gmail will retry for 47 more hours. You'll be notified if the delivery fails permanently.

Learn more here: https://support.google.com/mail/answer/188131

The response from the remote server was:
550 5.7.1 [2500:1109:110::11 91] Gmail has detected that this message is likely suspicious due to the very low reputation of the sending domain. To best protect our users from spam, the message has been blocked. Please visit https://support.google.com/mail/answer/188131 for more information. t64-20020a1fc343000000b0049d0aa186d9si449748vkf.30 - gsmtp
32 changes: 32 additions & 0 deletions test/fixtures/expected/451_4_7_650_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 outlook-com.olc.protection.outlook.com[140.74.55.33] said: 451 4.7.650 The mail server [39.177.48.16] has been temporarily rate limited due to IP reputation. For e-mail delivery information, see https://postmaster.live.com (S843) (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 outlook-com.olc.protection.outlook.com[140.74.55.33] said: 451 4.7.650 The mail server [39.177.48.16] has been temporarily rate limited due to IP reputation. For e-mail delivery information, see https://postmaster.live.com (S843) (in reply to RCPT TO command)"
},
"data": {
"error": {
"code": {
"basic": "451",
"enhanced": "4.7.650"
},
"label": "The mail server [39.177.48.16] has been temporarily rate limited due to IP reputation. For e-mail delivery information, see https://postmaster.live.com (S843)",
"type": "action_aborted_local_error",
"temporary": true,
"permanent": false,
"data": {
"type": "reputation",
"blocked": false,
"spam": false
}
},
"recipient": "[email protected]",
"server": {
"hostname": "outlook-com.olc.protection.outlook.com",
"ip": "140.74.55.33",
"port": null
},
"command": "RCPT TO"
}
}
32 changes: 32 additions & 0 deletions test/fixtures/expected/550_5_7_129_restricted_permissions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"bounce": true,
"email": {
"body": "Delivery has failed to these recipients or groups:\n\n[email protected]<mailto:[email protected]>\nYour message couldn't be delivered to the recipient because you don't have permission to send to it.\n\nAsk the recipient's email admin to add you to the accept list for the recipient.\n\nFor more information, see DSN 5.7.129 Errors in Exchange Online and Office 365<https://go.microsoft.com/fwlink/?LinkId=389365>.\n\n\n\n\n\n\n\n\n\nDiagnostic information for administrators:\n\nGenerating server: EV2MR07MI7830.eurprd06.prod.outlook.com\n\n[email protected]\nRemote server returned '550 5.7.129 RESOLVER.RST.RestrictedToRecipientsPermission; not authorized to send to recipient because the sender isn't on the recipient's list of senders to accept mail from'\n\nOriginal message headers:\n\nREDACTED",
"intro": null,
"error": null
},
"data": {
"error": {
"code": {
"basic": "550",
"enhanced": "5.7.129"
},
"label": "RESOLVER.RST.RestrictedToRecipientsPermission; not authorized to send to recipient because the sender isn't on the recipient's list of senders to accept mail from",
"type": "action_not_taken",
"temporary": false,
"permanent": true,
"data": {
"type": null,
"blocked": false,
"spam": false
}
},
"recipient": "[email protected]",
"server": {
"hostname": "EV2MR07MI7830.eurprd06.prod.outlook.com",
"ip": null,
"port": null
},
"command": null
}
}
32 changes: 32 additions & 0 deletions test/fixtures/expected/550_5_7_1_reputation.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"bounce": true,
"email": {
"body": "** Delivery incomplete **\n\nThere was a temporary problem delivering your message to [email protected]. Gmail will retry for 47 more hours. You'll be notified if the delivery fails permanently.\n\nLearn more here: https://support.google.com/mail/answer/188131\n\nThe response from the remote server was:\n550 5.7.1 [2500:1109:110::11 91] Gmail has detected that this message is likely suspicious due to the very low reputation of the sending domain. To best protect our users from spam, the message has been blocked. Please visit https://support.google.com/mail/answer/188131 for more information. t64-20020a1fc343000000b0049d0aa186d9si449748vkf.30 - gsmtp",
"intro": null,
"error": null
},
"data": {
"error": {
"code": {
"basic": "550",
"enhanced": "5.7.1"
},
"label": "[2500:1109:110::11 91] Gmail has detected that this message is likely suspicious due to the very low reputation of the sending domain. To best protect our users from spam, the message has been blocked. Please visit https://support.google.com/mail/answer/188131 for more information. t64-20020a1fc343000000b0049d0aa186d9si449748vkf.30 - gsmtp",
"type": "action_not_taken",
"temporary": true,
"permanent": false,
"data": {
"type": "spam_content",
"blocked": true,
"spam": true
}
},
"recipient": "[email protected]",
"server": {
"hostname": null,
"ip": null,
"port": null
},
"command": null
}
}
32 changes: 32 additions & 0 deletions test/fixtures/expected/unknown_temporary.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"bounce": true,
"email": {
"body": "** Delivery incomplete **\n\nThere was a temporary problem delivering your message to [email protected]. Gmail will retry for 46 more hours. You'll be notified if the delivery fails permanently.",
"intro": null,
"error": null
},
"data": {
"error": {
"code": {
"basic": null,
"enhanced": null
},
"label": null,
"type": null,
"temporary": true,
"permanent": false,
"data": {
"type": null,
"blocked": false,
"spam": false
}
},
"recipient": "[email protected]",
"server": {
"hostname": null,
"ip": null,
"port": null
},
"command": null
}
}
4 changes: 4 additions & 0 deletions test/fixtures/unknown_temporary.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

** Delivery incomplete **

There was a temporary problem delivering your message to [email protected]. Gmail will retry for 46 more hours. You'll be notified if the delivery fails permanently.
22 changes: 15 additions & 7 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,17 @@ module.exports = {
"unknown_server_timeout_variant_1",
"unknown_server_timeout_variant_2",

"unknown_temporary",

"421_too_many_connections",

"421_4_4_2_timeout",
"421_4_7_28_ip_blocked_spam",

"451_action_aborted_local_error",

"451_4_7_650_reputation",

"450_4_2_1_no_such_recipient",

"452_4_2_2_mailbox_full",
Expand All @@ -134,13 +138,6 @@ module.exports = {
"550_no_such_recipient_variant_10",
"550_no_such_recipient_variant_11",

"550_5_4_1_no_such_recipient",
"550_5_4_1_no_such_recipient_variant_1",
"550_5_4_1_no_such_recipient_variant_2",
"550_5_4_1_no_such_recipient_variant_3",

"550_5_4_310_server_unknown",

"550_5_1_1_no_such_recipient",
"550_5_1_1_no_such_recipient_variant_1",
"550_5_1_1_no_such_recipient_variant_2",
Expand Down Expand Up @@ -174,13 +171,24 @@ module.exports = {
"550_5_2_1_recipient_unknown",
"550_5_2_1_account_disabled",

"550_5_4_1_no_such_recipient",
"550_5_4_1_no_such_recipient_variant_1",
"550_5_4_1_no_such_recipient_variant_2",
"550_5_4_1_no_such_recipient_variant_3",

"550_5_4_310_server_unknown",

"550_5_5_0_no_such_recipient",

"550_5_7_1_reputation",

"550_5_7_1_spam_content",
"550_5_7_1_spam_content_variant_1",
"550_5_7_1_spam_content_variant_2",
"550_5_7_1_spam_content_variant_3",

"550_5_7_129_restricted_permissions",

"552_no_such_recipient",

"552_5_2_2_mailbox_over_quota",
Expand Down

0 comments on commit f40c0cf

Please sign in to comment.