email-bounce-parser 1.0.12 → 1.0.14

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 +46 -28
  2. package/package.json +1 -1
package/lib/parser.js CHANGED
@@ -87,7 +87,11 @@ var REGEXES = {
87
87
  /refused to talk to me\: (\d{3}(?:[\s\-]\d\.\d\.\d\d?)?) (.+)/m,
88
88
  /(?:error|reason)\:\s*?(\d{3}(?:[\s\-]\d\.\d\.\d\d?)?) (.+)/mi,
89
89
  /(\d{3}[\s\-]\d\.\d\.\d\d?)/m,
90
- /(\d{3}\-\'\d\.\d\.\d\d?)/m,
90
+ /(\d{3}\-\'\d\.\d\.\d\d?)/m
91
+ ],
92
+
93
+ error_lax : [
94
+ /(^\<.+?\>:.+)/m
91
95
  ],
92
96
 
93
97
  recipient : [
@@ -107,10 +111,11 @@ var REGEXES = {
107
111
 
108
112
  enhanced_types_no_such_recipient : [
109
113
  /(recipient address rejected: access denied)/i, // Outlook DBEB for invalid addresses
110
- /(invalid mailbox)/i,
114
+ /(no such (?:account|user|mailbox|recipient))/i,
115
+ /((?:terminated|disabled|inactive|not found|unavailable|invalid) (?:account|user|mailbox|recipient))/i,
111
116
  /(do(e)?sn\'t exist)/i, // Some Chinese SMTP return "dosn't" instead of "doesn't"
112
117
  /(user (?:.+?) does not exist)/i,
113
- /((?:account|user|mailbox) (?:is )?(?:terminated|disabled|inactive|not found|unavailable|invalid))/i
118
+ /((?:account|user|mailbox|recipient) (?:.+@.+ )?(?:is )?(?:terminated|disabled|inactive|not found|unavailable|invalid))/i
114
119
  ],
115
120
 
116
121
  enhanced_types_server_unknown : [
@@ -260,6 +265,7 @@ class Parser {
260
265
  enhanced : null
261
266
  },
262
267
  _label = null,
268
+ _type = null,
263
269
  _temporary = false,
264
270
  _permanent = false;
265
271
 
@@ -285,6 +291,20 @@ class Parser {
285
291
  _permanent = false;
286
292
  }
287
293
  }
294
+
295
+ if (_code.basic) {
296
+ _type = ERROR_CODES_TYPES[_code.basic] || null
297
+ }
298
+ }
299
+
300
+ // No label detected? Probably because there's no error code
301
+ if (!_label) {
302
+ // Attempt a lax check
303
+ var _match = loopRegexes(this.__regexes.error_lax, str);
304
+
305
+ if (_match && _match.length > 1) {
306
+ _label = trimString(_match[1]);
307
+ }
288
308
  }
289
309
 
290
310
  // Extract further data
@@ -294,7 +314,7 @@ class Parser {
294
314
  code : _code,
295
315
  label : _label,
296
316
 
297
- type : ERROR_CODES_TYPES[(_code || {}).basic],
317
+ type : _type,
298
318
 
299
319
  temporary : _temporary,
300
320
  permanent : _permanent,
@@ -347,38 +367,36 @@ class Parser {
347
367
  _blocked = false,
348
368
  _spam = false;
349
369
 
350
- if (code.basic) {
351
- // Detect enhanced-type from bounce content
352
- var _match = loopRegexes(this.__regexes.enhanced_types_no_such_recipient, str);
370
+ // Detect enhanced-type from bounce content
371
+ var _match = loopRegexes(this.__regexes.enhanced_types_no_such_recipient, str);
353
372
 
354
- if (_match && _match.length > 1) {
355
- _type = "no_such_recipient";
356
- }
373
+ if (_match && _match.length > 1) {
374
+ _type = "no_such_recipient";
375
+ }
357
376
 
358
- _match = loopRegexes(this.__regexes.enhanced_types_server_unknown, str);
377
+ _match = loopRegexes(this.__regexes.enhanced_types_server_unknown, str);
359
378
 
360
- if (!_type && _match && _match.length > 1) {
361
- _type = "server_unknown";
362
- }
379
+ if (!_type && _match && _match.length > 1) {
380
+ _type = "server_unknown";
381
+ }
363
382
 
364
- _match = loopRegexes(this.__regexes.enhanced_types_server_timeout, str);
383
+ _match = loopRegexes(this.__regexes.enhanced_types_server_timeout, str);
365
384
 
366
- if (!_type && _match && _match.length > 1) {
367
- _type = "server_timeout";
368
- }
385
+ if (!_type && _match && _match.length > 1) {
386
+ _type = "server_timeout";
387
+ }
369
388
 
370
- _match = loopRegexes(this.__regexes.enhanced_types_mailbox_full, str);
389
+ _match = loopRegexes(this.__regexes.enhanced_types_mailbox_full, str);
371
390
 
372
- if (!_type && _match && _match.length > 1) {
373
- _type = "mailbox_full";
374
- }
391
+ if (!_type && _match && _match.length > 1) {
392
+ _type = "mailbox_full";
393
+ }
375
394
 
376
- // Detect enhanced-type from enhanced error code
377
- // Notice: this is done as a last resort, as sometimes enhanced code \
378
- // doesn't clearly convey the actual error
379
- if (!_type && _match && code.enhanced) {
380
- _type = ERROR_CODES_TYPES[`${code.basic} ${code.enhanced}`] || null;
381
- }
395
+ // Detect enhanced-type from enhanced error code
396
+ // Notice: this is done as a last resort, as sometimes enhanced code \
397
+ // doesn't clearly convey the actual error
398
+ if (!_type && _match && code.enhanced) {
399
+ _type = ERROR_CODES_TYPES[`${code.basic} ${code.enhanced}`] || null;
382
400
  }
383
401
 
384
402
  // Check if blocked
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "email-bounce-parser",
3
- "version": "1.0.12",
3
+ "version": "1.0.14",
4
4
  "description": "Parses bounce emails and extract errors",
5
5
  "author": "Eliott Vincent <eliott@crisp.chat>",
6
6
  "main": "lib/index.js",