-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmail-cleanup.js
34 lines (26 loc) · 878 Bytes
/
mail-cleanup.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
const fs = require("fs");
const _ = require('underscore');
const MAIL_PROVIDERS = ['abv.bg', 'gmail.com', 'mail.bg', 'yahoo.com', 'hotmail.com', 'dir.bg', 'yahoo.co.uk']
FILE_NAME = 'clean-mails.txt'
function contains(target, pattern) {
let value = 0;
pattern.forEach(function(word) {
value = value + target.includes(word);
});
return (value === 1)
}
function storeNewEmail(email) {
if(email != undefined ) {
console.log(email);
fs.appendFileSync(FILE_NAME, email + '\n', "UTF-8",{'flags': 'a+'});
}
}
console.log('start cleanup');
const allFileContents = fs.readFileSync('test-mails.txt', 'utf-8');
allFileContents.split(/\r?\n/).forEach(email => {
// console.log(`Line from file: ${line}`);
if (contains(email.toLowerCase(), MAIL_PROVIDERS)) {
console.log(email)
storeNewEmail(email);
}
});