forked from EmailVerify/email-verify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
executable file
·122 lines (109 loc) · 3.38 KB
/
app.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env node
var arguments = process.argv.slice(2);
if (arguments.length === 0) {
throw new Error('You must provide one or more email addresses.');
}
var addresses = [],
domain = null,
err_msg = null,
options = {
port : 25,
sender : '[email protected]',
fdqn : 'mail.example.org'
};
//todo: code refactoring
for (var i = 0 ; i < arguments.length ; i++) {
if (arguments[i] === '-d') {
if (arguments[++i]) {
domain = '@' + arguments[i];
}
else {
err_msg = 'Malformed Domain Command'; break;
}
}
else if (domain && arguments[i] === '-n') {
if (arguments[i + 1] && arguments[i + 2]) {
var first = arguments[++i],
firstletter = first.charAt(0),
last = arguments[++i],
lastletter = last.charAt(0);
addresses.push(first + domain);
addresses.push(last + domain);
addresses.push(first + last + domain);
addresses.push(first + '.' + last + domain);
addresses.push(last + first + domain);
addresses.push(last + '.' + first + domain);
addresses.push(firstletter + last + domain);
addresses.push(firstletter + '.' + last + domain);
addresses.push(firstletter + lastletter + domain);
addresses.push(firstletter + domain);
addresses.push(last + firstletter + domain);
addresses.push(last + '.' + firstletter + domain);
addresses.push(first + lastletter + domain);
addresses.push(first + '.' + lastletter + domain);
}
else {
err_msg = 'Malformed Domain Command';
break;
}
}
else if (domain && arguments[i] === '-s') {
require('./standard.json').addresses.forEach(function (val, index, array) {
addresses.push(val + domain);
});
}
else if (arguments[i] === '-sd' && arguments[i+1]) {
options.sender = arguments[++i];
}
else if (arguments[i] === '-p' && arguments[i+1] && arguments[i+1] % 1 === 0) {
options.port = arguments[++i];
}
else if (arguments[i] === '-t' && arguments[i+1] && arguments[i+1] % 1 === 0) {
options.timeout = parseInt(arguments[++i]);
}
else if (arguments[i] === '-f' && arguments[i+1]) {
options.fdqn = arguments[++i];
}
else if (arguments[i] === '-dns' && arguments[i+1]) {
options.dns = arguments[++i];
}
else if (arguments[i] === '-c' && arguments[i+1]) {
options.concurrency = parseInt(arguments[++i]);
}
else if (domain) {
addresses.push(arguments[i] + domain);
}
else if (arguments[i] === '-file' || arguments[i] === '--file'){
// check arguments filename supplied?
if (!arguments[i+1]) {
throw new Error("You must supplied the path to the file.");
} else {
require('./methods/readfromfile.js')
.getAddressFromTextFile(arguments[i+1])
.forEach(function (val, index, array) {
addresses.push(val);
});
break; // immediately exit to prevent adding the filename itself to the addresses vars
}
}
else {
addresses.push(arguments[i]);
}
}
if (err_msg) {
console.log(err_msg);
}
else {
var Promise = require("bluebird");
var verifier = require('./index.js');
Promise.map(addresses, function(val) {
return new Promise(function (resolve, reject) {
verifier.verify(val, options, function (err, info) {
if (!err && info.success) {
console.log(info.addr);
}
resolve();
});
});
}, {concurrency: options.concurrency});
}