1
0
mirror of https://github.com/node-red/node-red-nodes.git synced 2023-10-10 13:36:58 +02:00

Fix for Email In Node Crashed Node-RED (#471)

When attachments aren't correct.
This commit is contained in:
Tom Brusehaver 2018-09-03 13:56:36 -05:00 committed by Dave Conway-Jones
parent 52df7cb30f
commit 337588e7ab

View File

@ -226,6 +226,7 @@ module.exports = function(RED) {
function nextMessage() { function nextMessage() {
if (currentMessage > maxMessage) { if (currentMessage > maxMessage) {
pop3Client.quit(); pop3Client.quit();
setInputRepeatTimeout();
return; return;
} }
pop3Client.retr(currentMessage); pop3Client.retr(currentMessage);
@ -248,6 +249,7 @@ module.exports = function(RED) {
}); });
pop3Client.on("error", function(err) { pop3Client.on("error", function(err) {
setInputRepeatTimeout();
node.log("error: " + JSON.stringify(err)); node.log("error: " + JSON.stringify(err));
}); });
@ -263,6 +265,7 @@ module.exports = function(RED) {
} else { } else {
node.log(util.format("login error: %s %j", status, rawData)); node.log(util.format("login error: %s %j", status, rawData));
pop3Client.quit(); pop3Client.quit();
setInputRepeatTimeout();
} }
}); });
@ -284,6 +287,7 @@ module.exports = function(RED) {
else { else {
node.log(util.format("retr error: %s %j", status, rawData)); node.log(util.format("retr error: %s %j", status, rawData));
pop3Client.quit(); pop3Client.quit();
setInputRepeatTimeout();
} }
}); });
@ -323,6 +327,7 @@ module.exports = function(RED) {
node.status({fill:"red", shape:"ring", text:"email.status.foldererror"}); node.status({fill:"red", shape:"ring", text:"email.status.foldererror"});
node.error(RED._("email.errors.fetchfail", {folder:node.box}),err); node.error(RED._("email.errors.fetchfail", {folder:node.box}),err);
imap.end(); imap.end();
setInputRepeatTimeout();
return; return;
} }
//console.log("> search - err=%j, results=%j", err, results); //console.log("> search - err=%j, results=%j", err, results);
@ -330,6 +335,7 @@ module.exports = function(RED) {
//console.log(" [X] - Nothing to fetch"); //console.log(" [X] - Nothing to fetch");
node.status({}); node.status({});
imap.end(); imap.end();
setInputRepeatTimeout();
return; return;
} }
@ -377,10 +383,12 @@ module.exports = function(RED) {
} else { } else {
cleanup(); cleanup();
} }
setInputRepeatTimeout();
}); });
fetch.once('error', function(err) { fetch.once('error', function(err) {
console.log('Fetch error: ' + err); console.log('Fetch error: ' + err);
setInputRepeatTimeout();
}); });
}); // End of imap->search }); // End of imap->search
}); // End of imap->openInbox }); // End of imap->openInbox
@ -424,16 +432,19 @@ module.exports = function(RED) {
this.on("close", function() { this.on("close", function() {
if (this.interval_id != null) { if (this.interval_id != null) {
clearInterval(this.interval_id); clearTimeout(this.interval_id);
} }
if (imap) { imap.destroy(); } if (imap) { imap.destroy(); }
}); });
function setInputRepeatTimeout()
{
// Set the repetition timer as needed // Set the repetition timer as needed
if (!isNaN(this.repeat) && this.repeat > 0) { if (!isNaN(node.repeat) && node.repeat > 0) {
this.interval_id = setInterval( function() { node.interval_id = setTimeout( function() {
node.emit("input",{}); node.emit("input",{});
}, this.repeat ); }, node.repeat );
}
} }
node.emit("input",{}); node.emit("input",{});