email-bounce-parser 1.0.2 → 1.0.3

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 CHANGED
@@ -71,6 +71,8 @@ console.log(result);
71
71
  //
72
72
  // data: {
73
73
  // type: "no_such_user",
74
+ // blocked: false,
75
+ // spam: false
74
76
  // }
75
77
  // },
76
78
  //
package/lib/parser.js CHANGED
@@ -73,6 +73,10 @@ 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
+
76
80
  error_code : [
77
81
  /(\d{3})[\s\-](\d\.\d\.\d)/,
78
82
  /(\d{3})/
@@ -226,6 +230,16 @@ class Parser {
226
230
  } else if (_code.basic[0] === "5") {
227
231
  _permanent = true;
228
232
  }
233
+
234
+ // Make sure the bounce is actually permanent
235
+ if (_permanent === true) {
236
+ var _match = this.__regexes.temporary_safe.match(str);
237
+
238
+ if (_match && _match.length > 1) {
239
+ _temporary = true;
240
+ _permanent = false;
241
+ }
242
+ }
229
243
  }
230
244
 
231
245
  // Extract further data
@@ -284,14 +298,32 @@ class Parser {
284
298
  * @return {object} The error data
285
299
  */
286
300
  __parseErrorData(str, code, label) {
287
- var _type = null;
301
+ var _type = null,
302
+ _blocked = false,
303
+ _spam = false;
288
304
 
289
305
  if (code.basic && code.enhanced) {
290
306
  _type = ERROR_CODES_TYPES[`${code.basic} ${code.enhanced}`] || null;
291
307
  }
292
308
 
309
+ // Check if blocked
310
+ var _blocked_match = this.__regexes.blocked.match(str);
311
+
312
+ if (_blocked_match && _blocked_match.length > 1) {
313
+ _blocked = true;
314
+ }
315
+
316
+ // Check if spam
317
+ var _spam_match = this.__regexes.spam.match(str);
318
+
319
+ if (_spam_match && _spam_match.length > 1) {
320
+ _spam = true;
321
+ }
322
+
293
323
  return {
294
- type : _type
324
+ type : _type,
325
+ blocked : _blocked,
326
+ spam : _spam
295
327
  }
296
328
  }
297
329
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "email-bounce-parser",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Parses bounce emails and extract errors",
5
5
  "author": "Eliott Vincent <eliott@crisp.chat>",
6
6
  "main": "lib/index.js",