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