email-bounce-parser 1.0.2 → 1.0.4
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.
- package/README.md +2 -0
- package/lib/parser.js +48 -4
- package/package.json +1 -1
package/README.md
CHANGED
package/lib/parser.js
CHANGED
|
@@ -73,6 +73,14 @@ var REGEXES = {
|
|
|
73
73
|
/\<(.+?)\>:/
|
|
74
74
|
],
|
|
75
75
|
|
|
76
|
+
temporary_safe : /(temporary|temporarily)/i,
|
|
77
|
+
blocked : /((?:is listed)blocked|banned|denied|dnsbl)/i,
|
|
78
|
+
spam : /(spam)/i,
|
|
79
|
+
|
|
80
|
+
enhanced_types_no_such_recipient : [
|
|
81
|
+
/((?:user is terminated)|(?:invalid mailbox))/i
|
|
82
|
+
],
|
|
83
|
+
|
|
76
84
|
error_code : [
|
|
77
85
|
/(\d{3})[\s\-](\d\.\d\.\d)/,
|
|
78
86
|
/(\d{3})/
|
|
@@ -226,6 +234,16 @@ class Parser {
|
|
|
226
234
|
} else if (_code.basic[0] === "5") {
|
|
227
235
|
_permanent = true;
|
|
228
236
|
}
|
|
237
|
+
|
|
238
|
+
// Make sure the bounce is actually permanent
|
|
239
|
+
if (_permanent === true) {
|
|
240
|
+
var _match = this.__regexes.temporary_safe.match(str);
|
|
241
|
+
|
|
242
|
+
if (_match && _match.length > 1) {
|
|
243
|
+
_temporary = true;
|
|
244
|
+
_permanent = false;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
229
247
|
}
|
|
230
248
|
|
|
231
249
|
// Extract further data
|
|
@@ -284,14 +302,40 @@ class Parser {
|
|
|
284
302
|
* @return {object} The error data
|
|
285
303
|
*/
|
|
286
304
|
__parseErrorData(str, code, label) {
|
|
287
|
-
var _type = null
|
|
305
|
+
var _type = null,
|
|
306
|
+
_blocked = false,
|
|
307
|
+
_spam = false;
|
|
308
|
+
|
|
309
|
+
if (code.basic) {
|
|
310
|
+
if (code.enhanced) {
|
|
311
|
+
_type = ERROR_CODES_TYPES[`${code.basic} ${code.enhanced}`] || null;
|
|
312
|
+
} else {
|
|
313
|
+
var _match = loopRegexes(this.__regexes.enhanced_types_no_such_recipient, str);
|
|
314
|
+
|
|
315
|
+
if (_match && _match.length > 1) {
|
|
316
|
+
_type = "no_such_recipient";
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// Check if blocked
|
|
322
|
+
var _blocked_match = this.__regexes.blocked.match(str);
|
|
323
|
+
|
|
324
|
+
if (_blocked_match && _blocked_match.length > 1) {
|
|
325
|
+
_blocked = true;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// Check if spam
|
|
329
|
+
var _spam_match = this.__regexes.spam.match(str);
|
|
288
330
|
|
|
289
|
-
if (
|
|
290
|
-
|
|
331
|
+
if (_spam_match && _spam_match.length > 1) {
|
|
332
|
+
_spam = true;
|
|
291
333
|
}
|
|
292
334
|
|
|
293
335
|
return {
|
|
294
|
-
type
|
|
336
|
+
type : _type,
|
|
337
|
+
blocked : _blocked,
|
|
338
|
+
spam : _spam
|
|
295
339
|
}
|
|
296
340
|
}
|
|
297
341
|
|