email-bounce-parser 1.0.15 → 1.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/parser.js +55 -14
  2. package/package.json +4 -2
package/lib/parser.js CHANGED
@@ -8,6 +8,7 @@ var ERROR_CODES_TYPES = {
8
8
  "421" : "service_not_available",
9
9
  "421 4.3.0" : "temporary_system_problem",
10
10
  "421 4.4.5" : "server_busy",
11
+ "421 4.7.28" : "ip_blocked_spam",
11
12
  "432 4.7.12" : "password_needed",
12
13
  "450" : "action_not_taken_mailbox_unavailable",
13
14
  "450 4.2.1" : "action_not_taken_mailbox_rate_limited",
@@ -84,7 +85,7 @@ var REGEXES = {
84
85
  /said\: (\d{3}(?:[\s\-]\d\.\d\.\d\d?)?) (.+) \(in reply to/,
85
86
  /said\: (\d{3}(?:[\s\-]\d\.\d\.\d\d?)?)-(.+)/,
86
87
  /(\d{3}\-\'\d\.\d\.\d\d?) (.+)/,
87
- /LMTP error after (?:.+?)\:\<.+?\>\: (\d{3}(?:[\s\-]\d\.\d\.\d\d?)?) <.+?\>(.+)$/m,
88
+ /LMTP error after .+?\:\<.+?\>\: (\d{3}(?:[\s\-]\d\.\d\.\d\d?)?) <.+?\>(.+)$/m,
88
89
  /remote server returned \'(\d{3}(?:[\s\-]\d\.\d\.\d\d?)?) (.+)\'/i,
89
90
  /The response from the remote server was:\s(\d{3}(?:[\s\-]\d\.\d\.\d\d?)?) (.+)/,
90
91
  /refused to talk to me\: (\d{3}(?:[\s\-]\d\.\d\.\d\d?)?) (.+)/,
@@ -94,18 +95,20 @@ var REGEXES = {
94
95
  ],
95
96
 
96
97
  error_lax : [
97
- /(^\<.+?\>:.+)/m
98
+ /^(?:\<.+?\> \(expanded from \<.+?\>\)\:)(.+)/m, // "<john@acme.com> (expanded from <john@digiflex.com>): Domain name not found"
99
+ /^(?:\<.+?\>\:)(.+)/m // "<john@acme.com>: Domain name not found"
98
100
  ],
99
101
 
100
102
  recipient : [
101
- /The following addresses had permanent fatal errors (?:.*?)\s\<(.+?)\>/,
102
- /The following message to \<(.+?)\> was undeliverable/,
103
- /to the following addresses:\s*(.+)/,
103
+ /the following addresses had permanent fatal errors (?:.*?)\s\<(.+?)\>/i,
104
+ /the following message to \<(.+?)\> was undeliverable/i,
105
+ /to the following addresses:\s*(.+)/i,
104
106
  /^\<(.+?)\>:/m,
105
- /^(.+?)\s?\n?\s*[\[|<]mailto\:(.+?)[\]|>]/m,
106
- /^Your message wasn't delivered to (.+?)\s/m,
107
- /^Your message to (.+?) couldn\'t/m,
108
- /\<(.+?)\>:/
107
+ /^(.+?)\s?\n?\s*[\[|<]mailto\:(.+?)[\]|>]/mi, // "john@acme.com<mailto:john@acme.com>"
108
+ /^your message wasn't delivered to (.+?)\s/mi, // "Your message wasn't delivered to john@acme.com"
109
+ /^your message to (.+?) couldn\'t/mi, // "Your message to john@acme.com couldn't"
110
+ /\<(.+?)\> \(expanded from \<.+?\>\)\:/, // "<john@acme.com> (expanded from <john@digiflex.com>): "
111
+ /\<(.+?)\>:/ // "<john@acme.com>:"
109
112
  ],
110
113
 
111
114
  temporary_safe : /(temporary|temporarily)/i,
@@ -122,7 +125,8 @@ var REGEXES = {
122
125
  ],
123
126
 
124
127
  enhanced_types_server_unknown : [
125
- /(does not accept mail)/i
128
+ /(does not accept mail)/i,
129
+ /(domain name not found)/i
126
130
  ],
127
131
 
128
132
  enhanced_types_server_timeout : [
@@ -134,8 +138,8 @@ var REGEXES = {
134
138
  ],
135
139
 
136
140
  error_code : [
137
- /(\d{3})[\s\-](\d\.\d\.\d)/, // "550 5.4.1" or "550-5.4.1"
138
- /(\d{3})\-\'(\d\.\d\.\d)/, // "550-'5.4.1"
141
+ /(\d{3})[\s\-](\d\.\d\.\d\d?)/, // "550 5.4.1" or "550-5.4.1" or "550-5.4.11"
142
+ /(\d{3})\-\'(\d\.\d\.\d\d?)/, // "550-'5.4.1" or "550-'5.4.11"
139
143
  /(\d{3})/ // "550"
140
144
  ]
141
145
  };
@@ -276,7 +280,7 @@ class Parser {
276
280
 
277
281
  if (_match && _match.length > 1) {
278
282
  _code = this.__parseErrorCode(_match[1]);
279
- _label = trimString(_match[2]);
283
+ _label = this.__cleanErrorLabel(_match[2]);
280
284
 
281
285
  // Check temporary / permanent
282
286
  if (_code.basic[0] === "4") {
@@ -306,7 +310,7 @@ class Parser {
306
310
  var _match = loopRegexes(this.__regexes.error_lax, str);
307
311
 
308
312
  if (_match && _match.length > 1) {
309
- _label = trimString(_match[1]);
313
+ _label = this.__cleanErrorLabel(_match[1]);
310
314
  }
311
315
  }
312
316
 
@@ -550,6 +554,43 @@ class Parser {
550
554
 
551
555
  return _str;
552
556
  }
557
+
558
+
559
+ /**
560
+ * Cleans error label
561
+ * @private
562
+ * @param {string} [label]
563
+ * @return {string} Unquoted text
564
+ */
565
+ __cleanErrorLabel(label="") {
566
+ var _label = this.__unquoteText(label);
567
+
568
+ _label = trimString(_label);
569
+
570
+ return _label;
571
+ }
572
+
573
+
574
+ /**
575
+ * Unquotes text
576
+ * @private
577
+ * @param {string} [str]
578
+ * @return {string} Unquoted text
579
+ */
580
+ __unquoteText(str="") {
581
+ var _str = str;
582
+
583
+ _str = trimString(_str);
584
+
585
+ if (
586
+ (_str.startsWith("'") && _str.endsWith("'")) ||
587
+ (_str.startsWith("\"") && _str.endsWith("\""))
588
+ ) {
589
+ return _str.slice(1, -1);
590
+ }
591
+
592
+ return _str;
593
+ }
553
594
  }
554
595
 
555
596
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "email-bounce-parser",
3
- "version": "1.0.15",
3
+ "version": "1.0.16",
4
4
  "description": "Parses bounce emails and extract errors",
5
5
  "author": "Eliott Vincent <eliott@crisp.chat>",
6
6
  "main": "lib/index.js",
@@ -30,7 +30,9 @@
30
30
  "mail",
31
31
  "email",
32
32
  "bounce",
33
- "bounces"
33
+ "bounces",
34
+ "smtp",
35
+ "rfc"
34
36
  ],
35
37
  "license": "MIT"
36
38
  }