mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Let email node set a default filename for binary attachment
so it will send "something" if only a buffer arrives.
This commit is contained in:
parent
974ac31d33
commit
7e9d96ee87
@ -79,6 +79,14 @@ module.exports = function(RED) {
|
|||||||
sendopts.to = node.name || msg.to; // comma separated list of addressees
|
sendopts.to = node.name || msg.to; // comma separated list of addressees
|
||||||
sendopts.subject = msg.topic || msg.title || "Message from Node-RED"; // subject line
|
sendopts.subject = msg.topic || msg.title || "Message from Node-RED"; // subject line
|
||||||
if (Buffer.isBuffer(msg.payload)) { // if it's a buffer in the payload then auto create an attachment instead
|
if (Buffer.isBuffer(msg.payload)) { // if it's a buffer in the payload then auto create an attachment instead
|
||||||
|
if (!msg.filename) {
|
||||||
|
var fe = "bin";
|
||||||
|
if ((msg.payload[0] === 0xFF)&&(msg.payload[1] === 0xD8)) { fe = "jpg"; }
|
||||||
|
if ((msg.payload[0] === 0x47)&&(msg.payload[1] === 0x49)) { fe = "gif"; } //46
|
||||||
|
if ((msg.payload[0] === 0x42)&&(msg.payload[1] === 0x4D)) { fe = "bmp"; }
|
||||||
|
if ((msg.payload[0] === 0x89)&&(msg.payload[1] === 0x50)) { fe = "png"; } //4E
|
||||||
|
msg.filename = "attachment."+fe;
|
||||||
|
}
|
||||||
sendopts.attachments = [ { content: msg.payload, filename:(msg.filename.replace(/^.*[\\\/]/, '') || "file.bin") } ];
|
sendopts.attachments = [ { content: msg.payload, filename:(msg.filename.replace(/^.*[\\\/]/, '') || "file.bin") } ];
|
||||||
if (msg.hasOwnProperty("headers") && msg.headers.hasOwnProperty("content-type")) {
|
if (msg.hasOwnProperty("headers") && msg.headers.hasOwnProperty("content-type")) {
|
||||||
sendopts.attachments[0].contentType = msg.headers["content-type"];
|
sendopts.attachments[0].contentType = msg.headers["content-type"];
|
||||||
|
Loading…
Reference in New Issue
Block a user