email-bounce-parser 1.0.11 → 1.0.12

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 +63 -33
  2. package/package.json +1 -1
package/lib/parser.js CHANGED
@@ -9,16 +9,40 @@ var ERROR_CODES_TYPES = {
9
9
  "421 4.3.0" : "temporary_system_problem",
10
10
  "421 4.4.5" : "server_busy",
11
11
  "432 4.7.12" : "password_needed",
12
- "450" : "mailbox_unavailable",
13
- "451" : "local_error",
14
- "452" : "insufficient_system_storage",
12
+ "450" : "action_not_taken_mailbox_unavailable",
13
+ "450 4.2.1" : "action_not_taken_mailbox_rate_limited",
14
+ "451 4.4.2" : "timeout",
15
+ "451" : "action_aborted_local_error",
16
+ "451 4.5.0" : "smtp_protocol_violation_rfc_2821",
17
+ "452" : "action_not_taken_insufficient_system_storage",
18
+ "452 4.2.2" : "mailbox_over_quota",
19
+ "454" : "smtp_protocol_violation_rfc_3207",
20
+ "454 4.5.0" : "smtp_protocol_violation_rfc_3207",
21
+ "454 4.7.0" : "authentication_issue",
22
+ "455" : "server_unable_to_accommodate_parameters",
23
+ "500" : "syntax_error",
24
+ "501" : "syntax_error_parameters",
25
+ "501 5.5.2" : "response_decode_error",
26
+ "501 5.5.4" : "invalid_helo_ehlo",
27
+ "502" : "command_not_implemented",
15
28
  "503" : "bad_commands_sequence",
29
+ "503 5.7.0" : "no_identity_changes_permitted",
30
+ "504" : "parameter_not_implemented",
31
+ "504 5.7.4" : "unrecognized_authentication_type",
32
+ "530 5.5.1" : "authentication_required",
16
33
  "550" : "action_not_taken",
17
34
  "550 5.1.1" : "no_such_recipient",
18
35
  "550 5.2.1" : "recipient_disabled_or_recipient_rate_limited",
19
36
  "550 5.7.1" : "spam_content",
37
+ "551" : "user_not_local",
38
+ "552" : "action_aborted_exceeded_storage_allocation",
39
+ "552 5.2.2" : "mailbox_over_quota",
40
+ "552 5.2.3" : "message_size_limit",
41
+ "553" : "action_not_taken_mailbox_name_not_allowed",
20
42
  "554" : "transaction_failed",
21
43
  "554 5.7.1" : "spam_content",
44
+ "555" : "parameters_not_recognized",
45
+ "555 5.5.2" : "syntax_error"
22
46
  };
23
47
 
24
48
  var REGEXES = {
@@ -45,6 +69,7 @@ var REGEXES = {
45
69
 
46
70
  email_server : [
47
71
  /host (\S+)\[([\d\.]+)\](?:\:(\d+)\:)? (?:said|refused to talk)/m,
72
+ /^(\S+) rejected your message/m,
48
73
  /\: connect to (.+)\[(.+)\](?:\:(\d+)\:)?/m,
49
74
  /Name service error for name\=(\S+)\s/m,
50
75
  /RCPT TO\:\<(.+?)\>/m,
@@ -55,17 +80,20 @@ var REGEXES = {
55
80
  error : [
56
81
  /said\: (\d{3}(?:[\s\-]\d\.\d\.\d\d?)?) (.+) \(in reply to/m,
57
82
  /said\: (\d{3}(?:[\s\-]\d\.\d\.\d\d?)?)-(.+)/m,
83
+ /(\d{3}\-\'\d\.\d\.\d\d?) (.+)/m,
58
84
  /LMTP error after (?:.+?)\:\<.+?\>\: (\d{3}(?:[\s\-]\d\.\d\.\d\d?)?) <.+?\>(.+)$/m,
59
85
  /Remote Server returned \'(\d{3}(?:[\s\-]\d\.\d\.\d\d?)?) (.+)\'/m,
60
86
  /The response from the remote server was:\s(\d{3}(?:[\s\-]\d\.\d\.\d\d?)?) (.+)/m,
61
87
  /refused to talk to me\: (\d{3}(?:[\s\-]\d\.\d\.\d\d?)?) (.+)/m,
62
- /Error\:\s*?(\d{3}(?:[\s\-]\d\.\d\.\d\d?)?) (.+)/m,
63
- /reason: (\d{3}[\s\-]\d\.\d\.\d\d?) (.+)/m,
64
- /(\d{3}[\s\-]\d\.\d\.\d\d?)/m
88
+ /(?:error|reason)\:\s*?(\d{3}(?:[\s\-]\d\.\d\.\d\d?)?) (.+)/mi,
89
+ /(\d{3}[\s\-]\d\.\d\.\d\d?)/m,
90
+ /(\d{3}\-\'\d\.\d\.\d\d?)/m,
65
91
  ],
66
92
 
67
93
  recipient : [
68
94
  /The following addresses had permanent fatal errors (?:.*?)\s\<(.+?)\>/,
95
+ /The following message to \<(.+?)\> was undeliverable/,
96
+ /to the following addresses:\s*(.+)/,
69
97
  /^\<(.+?)\>:/m,
70
98
  /^(.+?)\s?\n?\s*[\[|<]mailto\:(.+?)[\]|>]/m,
71
99
  /^Your message wasn't delivered to (.+?)\s/m,
@@ -74,14 +102,15 @@ var REGEXES = {
74
102
  ],
75
103
 
76
104
  temporary_safe : /(temporary|temporarily)/i,
77
- blocked : /((?:is listed)blocked|banned|denied|dnsbl)/i,
105
+ blocked : /((?:is listed)|blocked|banned|denied|dnsbl)/i,
78
106
  spam : /(spam)/i,
79
107
 
80
108
  enhanced_types_no_such_recipient : [
81
109
  /(recipient address rejected: access denied)/i, // Outlook DBEB for invalid addresses
82
110
  /(invalid mailbox)/i,
83
111
  /(do(e)?sn\'t exist)/i, // Some Chinese SMTP return "dosn't" instead of "doesn't"
84
- /((?:account|user|mailbox) (?:is )?(?:terminated|disabled|not found|unavailable|invalid))/i
112
+ /(user (?:.+?) does not exist)/i,
113
+ /((?:account|user|mailbox) (?:is )?(?:terminated|disabled|inactive|not found|unavailable|invalid))/i
85
114
  ],
86
115
 
87
116
  enhanced_types_server_unknown : [
@@ -97,12 +126,9 @@ var REGEXES = {
97
126
  ],
98
127
 
99
128
  error_code : [
100
- /(\d{3})[\s\-](\d\.\d\.\d)/,
101
- /(\d{3})/
102
- ],
103
-
104
- mailbox_address : [
105
- /^(([^\s@]+)@([^\s@]+)\.([^\s@]+))$/
129
+ /(\d{3})[\s\-](\d\.\d\.\d)/, // "550 5.4.1" or "550-5.4.1"
130
+ /(\d{3})\-\'(\d\.\d\.\d)/, // "550-'5.4.1"
131
+ /(\d{3})/ // "550"
106
132
  ]
107
133
  };
108
134
 
@@ -322,32 +348,36 @@ class Parser {
322
348
  _spam = false;
323
349
 
324
350
  if (code.basic) {
325
- if (code.enhanced) {
326
- _type = ERROR_CODES_TYPES[`${code.basic} ${code.enhanced}`] || null;
327
- } else {
328
- var _match = loopRegexes(this.__regexes.enhanced_types_no_such_recipient, str);
351
+ // Detect enhanced-type from bounce content
352
+ var _match = loopRegexes(this.__regexes.enhanced_types_no_such_recipient, str);
329
353
 
330
- if (_match && _match.length > 1) {
331
- _type = "no_such_recipient";
332
- }
354
+ if (_match && _match.length > 1) {
355
+ _type = "no_such_recipient";
356
+ }
333
357
 
334
- _match = loopRegexes(this.__regexes.enhanced_types_server_unknown, str);
358
+ _match = loopRegexes(this.__regexes.enhanced_types_server_unknown, str);
335
359
 
336
- if (!_type && _match && _match.length > 1) {
337
- _type = "server_unknown";
338
- }
360
+ if (!_type && _match && _match.length > 1) {
361
+ _type = "server_unknown";
362
+ }
339
363
 
340
- _match = loopRegexes(this.__regexes.enhanced_types_server_timeout, str);
364
+ _match = loopRegexes(this.__regexes.enhanced_types_server_timeout, str);
341
365
 
342
- if (!_type && _match && _match.length > 1) {
343
- _type = "server_timeout";
344
- }
366
+ if (!_type && _match && _match.length > 1) {
367
+ _type = "server_timeout";
368
+ }
345
369
 
346
- _match = loopRegexes(this.__regexes.enhanced_types_mailbox_full, str);
370
+ _match = loopRegexes(this.__regexes.enhanced_types_mailbox_full, str);
347
371
 
348
- if (!_type && _match && _match.length > 1) {
349
- _type = "mailbox_full";
350
- }
372
+ if (!_type && _match && _match.length > 1) {
373
+ _type = "mailbox_full";
374
+ }
375
+
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;
351
381
  }
352
382
  }
353
383
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "email-bounce-parser",
3
- "version": "1.0.11",
3
+ "version": "1.0.12",
4
4
  "description": "Parses bounce emails and extract errors",
5
5
  "author": "Eliott Vincent <eliott@crisp.chat>",
6
6
  "main": "lib/index.js",