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

mail - check attachment valid contents if possible

to close #728
This commit is contained in:
Dave Conway-Jones 2021-01-12 12:41:41 +00:00
parent c0c6d75535
commit 14983c9722
No known key found for this signature in database
GPG Key ID: 88BA2B8A411BE9FF
3 changed files with 18 additions and 6 deletions

View File

@ -120,7 +120,18 @@ module.exports = function(RED) {
var payload = RED.util.ensureString(msg.payload); var payload = RED.util.ensureString(msg.payload);
sendopts.text = payload; // plaintext body sendopts.text = payload; // plaintext body
if (/<[a-z][\s\S]*>/i.test(payload)) { sendopts.html = payload; } // html 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) { smtpTransport.sendMail(sendopts, function(error, info) {
if (error) { if (error) {

View File

@ -60,7 +60,8 @@
"fetchfail": "Failed to fetch folder: __folder__", "fetchfail": "Failed to fetch folder: __folder__",
"parsefail": "Failed to parse message", "parsefail": "Failed to parse message",
"messageerror": "Fetch message error: __error__", "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"
} }
} }
} }

View File

@ -1,13 +1,13 @@
{ {
"name": "node-red-node-email", "name": "node-red-node-email",
"version": "1.8.2", "version": "1.8.3",
"description": "Node-RED nodes to send and receive simple emails.", "description": "Node-RED nodes to send and receive simple emails.",
"dependencies": { "dependencies": {
"imap": "^0.8.19", "imap": "^0.8.19",
"poplib": "^0.1.7", "poplib": "^0.1.7",
"mailparser": "^3.0.0", "mailparser": "^3.0.1",
"nodemailer": "~6.4.10", "nodemailer": "~6.4.17",
"smtp-server": "^3.7.0" "smtp-server": "^3.8.0"
}, },
"repository": { "repository": {
"type": "git", "type": "git",