email node - remove promises for node8

and fixup tests
This commit is contained in:
Dave Conway-Jones 2020-10-19 21:33:32 +01:00
parent ffa5761756
commit 6f351943cb
No known key found for this signature in database
GPG Key ID: 88BA2B8A411BE9FF
3 changed files with 41 additions and 38 deletions

View File

@ -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();
});
}
});

View File

@ -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",

View File

@ -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", {