-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
48 lines (40 loc) · 861 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'use strict';
var fs = require('fs');
var path = require('path');
var pathToLists = path.join(__dirname, 'spam_lists');
var lists = [];
loadLists();
function loadLists() {
fs.readdir(pathToLists, function(err, files) {
if(err) {
throw new Error('could not find spam_lists directory');
}
files.forEach(function(file) {
readFile(path.join(pathToLists, file));
});
});
}
function readFile(file) {
fs.readFile(file, 'utf8', function(err, data) {
if(err) {
throw new Error('could not open ' + file);
}
var emails = data.split('\n');
emails.forEach(function(email) {
switch (email.charAt(0)) {
case '#':
case '!':
case '\n':
break;
default:
lists.push(email.trim());
break;
}
});
});
}
module.exports = {
isEmailClean: function(email) {
return (lists.indexOf(email.trim()) === -1);
}
};