**
* Loguin function with IMAP, if there is a user with that email, call succesCB, if not, failCB.
* @method checkPassword
* @param name {string} Email id
* @param server {string} Email server
* @param password {string} Password
* @param successCB {function} If loguin was successful, call successCB(name)
* @param errorCB {function} If loguin was not successful, call failCB(name)
*/
function checkPassword(userName, server, password, successCB, failCB) {
var uName = userName + "@" + server;
var hostName;
var portNumber;
var tlsEnable;
var imap = new Imap({
user: uName,
password: password,
host: hostName,
port: portNumber,
tls: tlsEnable,
tlsOptions: { rejectUnauthorized: false }
});
function openInbox(cb) {
imap.openBox('INBOX', true, cb);
}
imap.once('ready', function() {
console.log(uName + "Authenticated");
successCB(uName);
imap.end();
});
imap.once('error', function(err) {
console.log(uName + "Not authenticated");
failCB("Wrong Login, try again",1);
});
imap.once('end', function() {
console.log('Closing IMAP.');
});
imap.connect();
}