mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
tidy up email listing - no code changes
This commit is contained in:
parent
3107080b19
commit
1cfb5f403d
@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright 2013, 2015 IBM Corp.
|
||||
* Copyright 2013, 2016 IBM Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -136,10 +136,10 @@ module.exports = function(RED) {
|
||||
|
||||
|
||||
|
||||
//
|
||||
// EmailInNode
|
||||
//
|
||||
// Setup the EmailInNode
|
||||
//
|
||||
// EmailInNode
|
||||
//
|
||||
// Setup the EmailInNode
|
||||
function EmailInNode(n) {
|
||||
var imap;
|
||||
|
||||
@ -149,7 +149,7 @@ module.exports = function(RED) {
|
||||
this.inserver = n.server || (globalkeys && globalkeys.server) || "imap.gmail.com";
|
||||
this.inport = n.port || (globalkeys && globalkeys.port) || "993";
|
||||
this.box = n.box || "INBOX";
|
||||
this.useSSL = n.useSSL;
|
||||
this.useSSL= n.useSSL;
|
||||
this.protocol = n.protocol || "IMAP";
|
||||
this.disposition = n.disposition || "None"; // "None", "Delete", "Read"
|
||||
|
||||
@ -206,23 +206,23 @@ module.exports = function(RED) {
|
||||
}
|
||||
|
||||
node.send(msg); // Propagate the message down the flow
|
||||
}; // End of processNewMessage
|
||||
} // End of processNewMessage
|
||||
|
||||
// Check the POP3 email mailbox for any new messages. For any that are found,
|
||||
// retrieve each message, call processNewMessage to process it and then delete
|
||||
// the messages from the server.
|
||||
// Check the POP3 email mailbox for any new messages. For any that are found,
|
||||
// retrieve each message, call processNewMessage to process it and then delete
|
||||
// the messages from the server.
|
||||
function checkPOP3(msg) {
|
||||
var currentMessage;
|
||||
var maxMessage;
|
||||
|
||||
// Form a new connection to our email server using POP3.
|
||||
// Form a new connection to our email server using POP3.
|
||||
var pop3Client = new POP3Client(
|
||||
node.inport, node.inserver,
|
||||
{enabletls: node.useSSL} // Should we use SSL to connect to our email server?
|
||||
);
|
||||
|
||||
// If we have a next message to retrieve, ask to retrieve it otherwise issue a
|
||||
// quit request.
|
||||
// If we have a next message to retrieve, ask to retrieve it otherwise issue a
|
||||
// quit request.
|
||||
function nextMessage() {
|
||||
if (currentMessage > maxMessage) {
|
||||
pop3Client.quit();
|
||||
@ -233,11 +233,11 @@ module.exports = function(RED) {
|
||||
} // End of nextMessage
|
||||
|
||||
pop3Client.on("stat", function(status, data) {
|
||||
// Data contains:
|
||||
// {
|
||||
// count: <Number of messages to be read>
|
||||
// octect: <size of messages to be read>
|
||||
// }
|
||||
// Data contains:
|
||||
// {
|
||||
// count: <Number of messages to be read>
|
||||
// octect: <size of messages to be read>
|
||||
// }
|
||||
if (status) {
|
||||
currentMessage = 1;
|
||||
maxMessage = data.count;
|
||||
@ -270,8 +270,8 @@ module.exports = function(RED) {
|
||||
node.log(util.format("retr: status=%s, msgNumber=%d, data=%j", status, msgNumber, data));
|
||||
if (status) {
|
||||
|
||||
// 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.
|
||||
// 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.
|
||||
var mailparser = new MailParser();
|
||||
mailparser.on("end", function(mailObject) {
|
||||
//node.log(util.format("mailparser: on(end): %j", mailObject));
|
||||
@ -295,18 +295,18 @@ module.exports = function(RED) {
|
||||
node.log("We were locked: " + cmd);
|
||||
});
|
||||
|
||||
// When we have deleted the last processed message, we can move on to
|
||||
// processing the next message.
|
||||
// When we have deleted the last processed message, we can move on to
|
||||
// processing the next message.
|
||||
pop3Client.on("dele", function(status, msgNumber) {
|
||||
nextMessage();
|
||||
});
|
||||
}; // End of checkPOP3
|
||||
} // End of checkPOP3
|
||||
|
||||
|
||||
//
|
||||
// checkIMAP
|
||||
//
|
||||
// Check the email sever using the IMAP protocol for new messages.
|
||||
//
|
||||
// checkIMAP
|
||||
//
|
||||
// Check the email sever using the IMAP protocol for new messages.
|
||||
function checkIMAP(msg) {
|
||||
node.log("Checkimg IMAP for new messages");
|
||||
// We get back a 'ready' event once we have connected to imap
|
||||
@ -386,17 +386,17 @@ module.exports = function(RED) {
|
||||
}); // End of imap->ready
|
||||
imap.connect();
|
||||
node.status({fill:"grey",shape:"dot",text:"node-red:common.status.connecting"});
|
||||
}; // End of checkIMAP
|
||||
} // End of checkIMAP
|
||||
|
||||
|
||||
// Perform a check of the email inboxes using either POP3 or IMAP
|
||||
// Perform a check of the email inboxes using either POP3 or IMAP
|
||||
function checkEmail(msg) {
|
||||
if (node.protocol === "POP3") {
|
||||
checkPOP3(msg);
|
||||
} else if (node.protocol === "IMAP") {
|
||||
checkIMAP(msg);
|
||||
}
|
||||
}; // End of checkEmail
|
||||
} // End of checkEmail
|
||||
|
||||
if (node.protocol === "IMAP") {
|
||||
imap = new Imap({
|
||||
@ -413,7 +413,7 @@ module.exports = function(RED) {
|
||||
node.log(err);
|
||||
node.status({fill:"red",shape:"ring",text:"email.status.connecterror"});
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
this.on("input", function(msg) {
|
||||
checkEmail(msg);
|
||||
@ -426,7 +426,7 @@ module.exports = function(RED) {
|
||||
if (imap) { imap.destroy(); }
|
||||
});
|
||||
|
||||
// Set the repetition timer as needed
|
||||
// Set the repetition timer as needed
|
||||
if (!isNaN(this.repeat) && this.repeat > 0) {
|
||||
this.interval_id = setInterval( function() {
|
||||
node.emit("input",{});
|
||||
|
Loading…
x
Reference in New Issue
Block a user