-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathemailTester.js
97 lines (97 loc) · 2.13 KB
/
emailTester.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
var imap = require("imap-simple");
var pop3 = require("poplib");
var IMAPtest = function(useTLS, config, callback) {
var internalConfig = {};
if (!config.user) {
throw "NoUser";
}
internalConfig.user = config.user;
internalConfig.password = "";
if (config.password) {
internalConfig.password = config.password;
}
internalConfig.tls = false;
internalConfig.port = 143;
if (useTLS == true) {
internalConfig.tls = true;
internalConfig.port = 993;
}
if (config.port) {
internalConfig.port = config.port;
}
internalConfig.host = "localhost";
if (config.host) {
internalConfig.host = config.host;
}
internalConfig.authTimeout = 10000;
imap.connect(config, function(err, connection) {
if (err) {
callback(false);
} else {
callback(true);
connection.end();
}
return;
});
return;
};
var SecureImapWorks = function(config, callback) {
IMAPtest(true, config, callback);
return;
};
var InsecureImapWorks = function(config, callback) {
IMAPtest(false, config, callback);
return;
};
var defaultPopURL = "pop.gmail.com";
var popTest = function(useSecurity, server, callback) {
var port = 110;
if (useSecurity == true) {
port = 995;
}
var fired = false;
var client = new pop3(port, server, {
tlserrs: false,
enabletls: useSecurity,
debug: false
});
client.on("connect", function(){
if (fired==false) {
fired = true;
client.quit();
callback(true);
}
});
var fail = function(screwUp) {
if (fired==false) {
fired = true;
callback(false);
}
};
client.on("error", fail);
client.on("invalid-state", fail);
client.on("locked", fail);
return;
};
var insecurePopTest = function(callback, url) {
var internalURL = defaultPopURL;
if (url) {
internalURL = url;
}
popTest(false, internalURL, callback);
return;
};
var securePopTest = function(callback, url) {
var internalURL = defaultPopURL;
if (url) {
internalURL = url;
}
popTest(true, internalURL, callback);
return;
};
var output = {};
output.SecureImapWorks = SecureImapWorks;
output.InsecureImapWorks = InsecureImapWorks;
output.insecurePopTest = insecurePopTest;
output.securePopTest = securePopTest;
module.exports = exports = output;