From 6f351943cbd442a80add12f3892cd17f516eb614 Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Mon, 19 Oct 2020 21:33:32 +0100 Subject: [PATCH] email node - remove promises for node8 and fixup tests --- social/email/61-email.js | 58 +++++++++++++++--------------- social/email/package.json | 2 +- test/social/email/61-email_spec.js | 19 ++++++---- 3 files changed, 41 insertions(+), 38 deletions(-) diff --git a/social/email/61-email.js b/social/email/61-email.js index 15371c12..272c7390 100644 --- a/social/email/61-email.js +++ b/social/email/61-email.js @@ -529,37 +529,35 @@ module.exports = function(RED) { disabledCommands: ['AUTH', 'STARTTLS'], onData: function (stream, session, callback) { - simpleParser(stream, { - skipTextToHtml: true, - skipTextLinks: true - }) - .then(parsed => { - node.status({fill:"green", shape:"dot", text:""}); - var msg = {} - msg.payload = parsed.text; - msg.topic = parsed.subject; - msg.date = parsed.date; - msg.header = {}; - parsed.headers.forEach((v, k) => {msg.header[k] = v;}); - if (parsed.html) { msg.html = parsed.html; } - if (parsed.to) { - if (typeof(parsed.to) === "string" && parsed.to.length > 0) { msg.to = parsed.to; } - else if (parsed.to.hasOwnProperty("text") && parsed.to.text.length > 0) { msg.to = parsed.to.text; } + simpleParser(stream, { skipTextToHtml:true, skipTextLinks:true }, (err, parsed) => { + if (err) { node.error(RED._("email.errors.parsefail"),err); } + else { + node.status({fill:"green", shape:"dot", text:""}); + var msg = {} + msg.payload = parsed.text; + msg.topic = parsed.subject; + msg.date = parsed.date; + msg.header = {}; + parsed.headers.forEach((v, k) => {msg.header[k] = v;}); + if (parsed.html) { msg.html = parsed.html; } + if (parsed.to) { + if (typeof(parsed.to) === "string" && parsed.to.length > 0) { msg.to = parsed.to; } + else if (parsed.to.hasOwnProperty("text") && parsed.to.text.length > 0) { msg.to = parsed.to.text; } + } + if (parsed.cc) { + if (typeof(parsed.cc) === "string" && parsed.cc.length > 0) { msg.cc = parsed.cc; } + else if (parsed.cc.hasOwnProperty("text") && parsed.cc.text.length > 0) { msg.cc = parsed.cc.text; } + } + if (parsed.cc && parsed.cc.length > 0) { msg.cc = parsed.cc; } + if (parsed.bcc && parsed.bcc.length > 0) { msg.bcc = parsed.bcc; } + if (parsed.from && parsed.from.value && parsed.from.value.length > 0) { msg.from = parsed.from.value[0].address; } + if (parsed.attachments) { msg.attachments = parsed.attachments; } + else { msg.attachments = []; } + node.send(msg); // Propagate the message down the flow + setTimeout(function() { node.status({})}, 500); } - if (parsed.cc) { - if (typeof(parsed.cc) === "string" && parsed.cc.length > 0) { msg.cc = parsed.cc; } - else if (parsed.cc.hasOwnProperty("text") && parsed.cc.text.length > 0) { msg.cc = parsed.cc.text; } - } - if (parsed.cc && parsed.cc.length > 0) { msg.cc = parsed.cc; } - if (parsed.bcc && parsed.bcc.length > 0) { msg.bcc = parsed.bcc; } - if (parsed.from && parsed.from.value && parsed.from.value.length > 0) { msg.from = parsed.from.value[0].address; } - if (parsed.attachments) { msg.attachments = parsed.attachments; } - else { msg.attachments = []; } - node.send(msg); // Propagate the message down the flow - setTimeout(function() { node.status({})}, 500); - }) - .catch(err => { node.error(RED._("email.errors.parsefail"),err); }) - .finally(callback); + callback(); + }); } }); diff --git a/social/email/package.json b/social/email/package.json index ccfc19d5..d9f4f93c 100644 --- a/social/email/package.json +++ b/social/email/package.json @@ -1,6 +1,6 @@ { "name": "node-red-node-email", - "version": "1.8.0", + "version": "1.8.1", "description": "Node-RED nodes to send and receive simple emails.", "dependencies": { "imap": "^0.8.19", diff --git a/test/social/email/61-email_spec.js b/test/social/email/61-email_spec.js index 5d4f9a56..dd2316d9 100644 --- a/test/social/email/61-email_spec.js +++ b/test/social/email/61-email_spec.js @@ -225,13 +225,18 @@ describe('email Node', function () { n2.on("input", function(msg) { //console.log("GOT",msg); - msg.should.have.a.property("payload",'Hello World\n'); - msg.should.have.a.property("topic","Test"); - msg.should.have.a.property("from",'foo@example.com'); - msg.should.have.a.property("to",'bar@example.com'); - msg.should.have.a.property("attachments"); - msg.should.have.a.property("header"); - done(); + try { + msg.should.have.a.property("payload",'Hello World\n'); + msg.should.have.a.property("topic","Test"); + msg.should.have.a.property("from",'foo@example.com'); + msg.should.have.a.property("to",'bar@example.com'); + msg.should.have.a.property("attachments"); + msg.should.have.a.property("header"); + done(); + } + catch(e) { + done(e) + } }); n3.emit("input", {