1 | var imap = require("imap-simple");
|
2 | var test = function(useTLS, config, callback) {
|
3 | var internalConfig = {};
|
4 | if (!config.user) {
|
5 | throw "NoUser";
|
6 | }
|
7 | internalConfig.user = config.user;
|
8 | internalConfig.password = "";
|
9 | if (config.password) {
|
10 | internalConfig.password = config.password;
|
11 | }
|
12 | internalConfig.tls = false;
|
13 | internalConfig.port = 143;
|
14 | if (useTLS == true) {
|
15 | internalConfig.tls = true;
|
16 | internalConfig.port = 993;
|
17 | }
|
18 | if (config.port) {
|
19 | internalConfig.port = config.port;
|
20 | }
|
21 | internalConfig.host = "localhost";
|
22 | if (config.host) {
|
23 | internalConfig.host = config.host;
|
24 | }
|
25 | internalConfig.authTimeout = 10000;
|
26 | imap.connect(config, function(err, connection) {
|
27 | if (err) {
|
28 | callback(false);
|
29 | } else {
|
30 | callback(true);
|
31 | connection.end();
|
32 | }
|
33 | return;
|
34 | });
|
35 | return;
|
36 | };
|
37 | var SecureImapWorks = function(config, callback) {
|
38 | test(true, config, callback);
|
39 | return;
|
40 | };
|
41 | var InsecureImapWorks = function(config, callback) {
|
42 | test(false, config, callback);
|
43 | return;
|
44 | };
|
45 |
|
46 | var output = {};
|
47 | output.secureImapWorks = SecureImapWorks;
|
48 | output.insecureImapWorks = InsecureImapWorks;
|
49 | module.exports = exports = output; |
\ | No newline at end of file |