From 14983c9722743369c11305cb79fdd1d96dd70ea6 Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Tue, 12 Jan 2021 12:41:41 +0000 Subject: [PATCH] mail - check attachment valid contents if possible to close #728 --- social/email/61-email.js | 13 ++++++++++++- social/email/locales/en-US/61-email.json | 3 ++- social/email/package.json | 8 ++++---- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/social/email/61-email.js b/social/email/61-email.js index f480c60a..0c7b3b5a 100644 --- a/social/email/61-email.js +++ b/social/email/61-email.js @@ -120,7 +120,18 @@ module.exports = function(RED) { var payload = RED.util.ensureString(msg.payload); sendopts.text = payload; // plaintext body if (/<[a-z][\s\S]*>/i.test(payload)) { sendopts.html = payload; } // html body - if (msg.attachments) { sendopts.attachments = msg.attachments; } // add attachments + if (msg.attachments && Array.isArray(msg.attachments)) { + sendopts.attachments = msg.attachments; + for (var a=0; a < sendopts.attachments.length; a++) { + if (sendopts.attachments[a].hasOwnProperty("content")) { + if (typeof sendopts.attachments[a].content !== "string" && !Buffer.isBuffer(sendopts.attachments[a].content)) { + node.error(RED._("email.errors.invalidattachment"),msg); + node.status({fill:"red",shape:"ring",text:"email.status.sendfail"}); + return; + } + } + } + } } smtpTransport.sendMail(sendopts, function(error, info) { if (error) { diff --git a/social/email/locales/en-US/61-email.json b/social/email/locales/en-US/61-email.json index cca6fa1d..606580b7 100644 --- a/social/email/locales/en-US/61-email.json +++ b/social/email/locales/en-US/61-email.json @@ -60,7 +60,8 @@ "fetchfail": "Failed to fetch folder: __folder__", "parsefail": "Failed to parse message", "messageerror": "Fetch message error: __error__", - "refreshtoolarge": "Refresh interval too large. Limiting to 2147483 seconds" + "refreshtoolarge": "Refresh interval too large. Limiting to 2147483 seconds", + "invalidattachment": "Invalid attachment content. Must be String or buffer" } } } diff --git a/social/email/package.json b/social/email/package.json index 7611fb45..8aa2a66e 100644 --- a/social/email/package.json +++ b/social/email/package.json @@ -1,13 +1,13 @@ { "name": "node-red-node-email", - "version": "1.8.2", + "version": "1.8.3", "description": "Node-RED nodes to send and receive simple emails.", "dependencies": { "imap": "^0.8.19", "poplib": "^0.1.7", - "mailparser": "^3.0.0", - "nodemailer": "~6.4.10", - "smtp-server": "^3.7.0" + "mailparser": "^3.0.1", + "nodemailer": "~6.4.17", + "smtp-server": "^3.8.0" }, "repository": { "type": "git",