From 337588e7ab3271ea2af6148e5299dce3f53e9944 Mon Sep 17 00:00:00 2001 From: Tom Brusehaver <41647049+tbrusehaver@users.noreply.github.com> Date: Mon, 3 Sep 2018 13:56:36 -0500 Subject: [PATCH] Fix for Email In Node Crashed Node-RED (#471) When attachments aren't correct. --- social/email/61-email.js | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/social/email/61-email.js b/social/email/61-email.js index 7294af9e..a50ae6d8 100644 --- a/social/email/61-email.js +++ b/social/email/61-email.js @@ -226,6 +226,7 @@ module.exports = function(RED) { function nextMessage() { if (currentMessage > maxMessage) { pop3Client.quit(); + setInputRepeatTimeout(); return; } pop3Client.retr(currentMessage); @@ -248,6 +249,7 @@ module.exports = function(RED) { }); pop3Client.on("error", function(err) { + setInputRepeatTimeout(); node.log("error: " + JSON.stringify(err)); }); @@ -263,6 +265,7 @@ module.exports = function(RED) { } else { node.log(util.format("login error: %s %j", status, rawData)); pop3Client.quit(); + setInputRepeatTimeout(); } }); @@ -284,6 +287,7 @@ module.exports = function(RED) { else { node.log(util.format("retr error: %s %j", status, rawData)); pop3Client.quit(); + setInputRepeatTimeout(); } }); @@ -323,6 +327,7 @@ module.exports = function(RED) { node.status({fill:"red", shape:"ring", text:"email.status.foldererror"}); node.error(RED._("email.errors.fetchfail", {folder:node.box}),err); imap.end(); + setInputRepeatTimeout(); return; } //console.log("> search - err=%j, results=%j", err, results); @@ -330,6 +335,7 @@ module.exports = function(RED) { //console.log(" [X] - Nothing to fetch"); node.status({}); imap.end(); + setInputRepeatTimeout(); return; } @@ -377,10 +383,12 @@ module.exports = function(RED) { } else { cleanup(); } + setInputRepeatTimeout(); }); fetch.once('error', function(err) { console.log('Fetch error: ' + err); + setInputRepeatTimeout(); }); }); // End of imap->search }); // End of imap->openInbox @@ -424,16 +432,19 @@ module.exports = function(RED) { this.on("close", function() { if (this.interval_id != null) { - clearInterval(this.interval_id); + clearTimeout(this.interval_id); } if (imap) { imap.destroy(); } }); - // Set the repetition timer as needed - if (!isNaN(this.repeat) && this.repeat > 0) { - this.interval_id = setInterval( function() { - node.emit("input",{}); - }, this.repeat ); + function setInputRepeatTimeout() + { + // Set the repetition timer as needed + if (!isNaN(node.repeat) && node.repeat > 0) { + node.interval_id = setTimeout( function() { + node.emit("input",{}); + }, node.repeat ); + } } node.emit("input",{});