mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
use latest mailparser API (#546)
The API diverged between the original and mailparser-mit
This commit is contained in:
parent
b74aacd266
commit
877763aae9
@ -14,7 +14,7 @@ module.exports = function(RED) {
|
|||||||
var nodemailer = require("nodemailer");
|
var nodemailer = require("nodemailer");
|
||||||
var Imap = require('imap');
|
var Imap = require('imap');
|
||||||
var POP3Client = require("poplib");
|
var POP3Client = require("poplib");
|
||||||
var MailParser = require("mailparser").MailParser;
|
var SimpleParser = require("mailparser").simpleParser;
|
||||||
var util = require("util");
|
var util = require("util");
|
||||||
|
|
||||||
if (parseInt(process.version.split("v")[1].split(".")[0]) < 8) {
|
if (parseInt(process.version.split("v")[1].split(".")[0]) < 8) {
|
||||||
@ -206,7 +206,9 @@ module.exports = function(RED) {
|
|||||||
msg.payload = mailMessage.text;
|
msg.payload = mailMessage.text;
|
||||||
msg.topic = mailMessage.subject;
|
msg.topic = mailMessage.subject;
|
||||||
msg.date = mailMessage.date;
|
msg.date = mailMessage.date;
|
||||||
msg.header = mailMessage.headers;
|
msg.header = {};
|
||||||
|
mailMessage.headers.forEach((v, k) => {msg.header[k] = v;});
|
||||||
|
|
||||||
if (mailMessage.html) { msg.html = mailMessage.html; }
|
if (mailMessage.html) { msg.html = mailMessage.html; }
|
||||||
if (mailMessage.to && mailMessage.to.length > 0) { msg.to = mailMessage.to; }
|
if (mailMessage.to && mailMessage.to.length > 0) { msg.to = mailMessage.to; }
|
||||||
if (mailMessage.cc && mailMessage.cc.length > 0) { msg.cc = mailMessage.cc; }
|
if (mailMessage.cc && mailMessage.cc.length > 0) { msg.cc = mailMessage.cc; }
|
||||||
@ -285,13 +287,16 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
// We have now received a new email message. Create an instance of a mail parser
|
// We have now received a new email message. Create an instance of a mail parser
|
||||||
// and pass in the email message. The parser will signal when it has parsed the message.
|
// and pass in the email message. The parser will signal when it has parsed the message.
|
||||||
var mailparser = new MailParser();
|
SimpleParser(data, {}, function(err, parsed) {
|
||||||
mailparser.on("end", function(mailObject) {
|
//node.log(util.format("SimpleParser: on(end): %j", mailObject));
|
||||||
//node.log(util.format("mailparser: on(end): %j", mailObject));
|
if (err){
|
||||||
processNewMessage(msg, mailObject);
|
node.status({fill:"red", shape:"ring", text:"email.status.parseerror"});
|
||||||
|
node.error(RED._("email.errors.parsefail", {folder:node.box}), err);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
processNewMessage(msg, parsed);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
mailparser.write(data);
|
|
||||||
mailparser.end();
|
|
||||||
pop3Client.dele(msgNumber);
|
pop3Client.dele(msgNumber);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -379,22 +384,18 @@ module.exports = function(RED) {
|
|||||||
// For each fetched message returned ...
|
// For each fetched message returned ...
|
||||||
fetch.on('message', function(imapMessage, seqno) {
|
fetch.on('message', function(imapMessage, seqno) {
|
||||||
//node.log(RED._("email.status.message",{number:seqno}));
|
//node.log(RED._("email.status.message",{number:seqno}));
|
||||||
var messageText = "";
|
|
||||||
//console.log("> Fetch message - msg=%j, seqno=%d", imapMessage, seqno);
|
//console.log("> Fetch message - msg=%j, seqno=%d", imapMessage, seqno);
|
||||||
imapMessage.on('body', function(stream, info) {
|
imapMessage.on('body', function(stream, info) {
|
||||||
//console.log("> message - body - stream=?, info=%j", info);
|
//console.log("> message - body - stream=?, info=%j", info);
|
||||||
stream.on('data', function(chunk) {
|
SimpleParser(stream, {}, function(err, parsed) {
|
||||||
//console.log("> stream - data - chunk=??");
|
if (err){
|
||||||
messageText += chunk.toString('utf8');
|
node.status({fill:"red", shape:"ring", text:"email.status.parseerror"});
|
||||||
|
node.error(RED._("email.errors.parsefail", {folder:node.box}),err);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
processNewMessage(msg, parsed);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
stream.once('end', function() {
|
|
||||||
var mailParser = new MailParser();
|
|
||||||
mailParser.on('end', function(mailMessage) {
|
|
||||||
processNewMessage(msg, mailMessage);
|
|
||||||
});
|
|
||||||
mailParser.write(messageText);
|
|
||||||
mailParser.end();
|
|
||||||
}); // End of msg->end
|
|
||||||
}); // End of msg->body
|
}); // End of msg->body
|
||||||
}); // End of fetch->message
|
}); // End of fetch->message
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "node-red-node-email",
|
"name": "node-red-node-email",
|
||||||
"version": "1.5.1",
|
"version": "1.5.2",
|
||||||
"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",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user