Fixed IMAP timeout

This commit is contained in:
zeldaroot 2020-06-07 06:50:14 +03:00
parent 85c2b6fb12
commit 32e8658f2a

View file

@ -1034,6 +1034,18 @@ if (
? nodemailer.createTransport(options_smtp)
: null;
var imap = new Imap(options_imap);
var si_i = 0;
var si = setInterval(function() {
if (si_i >= 6) {
clearInterval(si);
console.error('ERROR: IMAP Timeout');
active.num--;
active.process.imap = false;
}
si_i++;
}, 11000);
imap.once('ready', function() {
imap.openBox('INBOX', false, function(err) {
if (err) {
@ -1096,11 +1108,13 @@ if (
});
});
imap.once('error', function(err) {
clearInterval(si);
console.error('imap.once', err);
active.num--;
active.process.imap = false;
});
imap.once('end', function() {
imap.once('close', function() {
clearInterval(si);
if (headers_ && headers_.length) {
var save = false;
async.eachOfLimit(
@ -1220,9 +1234,18 @@ if (
);
if (
!err &&
modules.abuse.data.smtp.host.indexOf('yandex') + 1
modules.abuse.data.smtp.host.indexOf('zoho') === -1
) {
var imap2 = new Imap(options_imap);
var si_i2 = 0;
var si2 = setInterval(function() {
if (si_i2 >= 6) {
clearInterval(si2);
console.error('ERROR: IMAP2 Timeout');
callback();
}
si_i2++;
}, 11000);
imap2.once('ready', function() {
imap2.openBox('Sent', false, function(err, box) {
if (err) {
@ -1267,10 +1290,12 @@ if (
});
});
imap2.once('error', function(err) {
clearInterval(si2);
console.error('SENT FOLDER', err);
callback();
});
imap2.once('end', function() {
imap2.once('close', function() {
clearInterval(si2);
console.error('SENT', mailOptions.to, mailOptions.subject);
callback();
});