packages/opal-node-email/emailprocess.js
function checkPOP3(msg) {
                let currentMessage;
                let maxMessage;

                // Form a new connection to our email server using POP3.
                let pop3Client = new POP3Client(
                    node.port, node.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
                 */
                function nextMessage() {
                    if (currentMessage > maxMessage) {
                        pop3Client.quit();
                        return;
                    }
                    pop3Client.retr(currentMessage);
                    currentMessage++;
                } // 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>
                    // }
                    if (status) {
                        currentMessage = 1;
                        maxMessage = data.count;
                        nextMessage();
                    } else {
                        node.log(util.format('stat error: %s %j', status, data));
                    }
                });

                pop3Client.on('error', function(err) {
                    node.log('We caught an error: ' + JSON.stringify(err));
                });

                pop3Client.on('connect', function() {
                    // node.log("We are now connected");
                    pop3Client.login(node.userid, node.password);
                });

                pop3Client.on('login', function(status, rawData) {
                    // node.log("login: " + status + ", " + rawData);
                    if (status) {
                        pop3Client.stat();
                    } else {
                        node.log(util.format('login error: %s %j', status, rawData));
                        pop3Client.quit();
                    }
                });

                pop3Client.on('retr', function(status, msgNumber, data, rawData) {
                    // 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.
                        let mailparser = new MailParser();
                        mailparser.on('end', function(mailObject) {
                            // node.log(util.format("mailparser: on(end): %j", mailObject));
                            processNewMessage(msg, mailObject);
                        });
                        mailparser.write(data);
                        mailparser.end();
                        pop3Client.dele(msgNumber);
                    } else {
                        node.log(util.format('retr error: %s %j', status, rawData));
                        pop3Client.quit();
                    }
                });

                pop3Client.on('invalid-state', function(cmd) {
                    node.log('Invalid state: ' + cmd);
                });

                pop3Client.on('locked', function(cmd) {
                    node.log('We were locked: ' + cmd);
                });

                // When we have deleted the last processed message, we can move on to
                // processing the next message.
                pop3Client.on('dele', function(status, msgNumber) {
                    nextMessage();
                });
            }
function checkPOP3(msg) {
                let currentMessage;
                let maxMessage;

                // Form a new connection to our email server using POP3.
                let pop3Client = new POP3Client(
                    node.port, node.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
                 */
                function nextMessage() {
                    if (currentMessage > maxMessage) {
                        pop3Client.quit();
                        return;
                    }
                    pop3Client.retr(currentMessage);
                    currentMessage++;
                } // 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>
                    // }
                    if (status) {
                        currentMessage = 1;
                        maxMessage = data.count;
                        nextMessage();
                    } else {
                        node.log(util.format('stat error: %s %j', status, data));
                    }
                });

                pop3Client.on('error', function(err) {
                    node.log('We caught an error: ' + JSON.stringify(err));
                });

                pop3Client.on('connect', function() {
                    // node.log("We are now connected");
                    pop3Client.login(node.userid, node.password);
                });

                pop3Client.on('login', function(status, rawData) {
                    // node.log("login: " + status + ", " + rawData);
                    if (status) {
                        pop3Client.stat();
                    } else {
                        node.log(util.format('login error: %s %j', status, rawData));
                        pop3Client.quit();
                    }
                });

                pop3Client.on('retr', function(status, msgNumber, data, rawData) {
                    // 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.
                        let mailparser = new MailParser();
                        mailparser.on('end', function(mailObject) {
                            // node.log(util.format("mailparser: on(end): %j", mailObject));
                            processNewMessage(msg, mailObject);
                        });
                        mailparser.write(data);
                        mailparser.end();
                        pop3Client.dele(msgNumber);
                    } else {
                        node.log(util.format('retr error: %s %j', status, rawData));
                        pop3Client.quit();
                    }
                });

                pop3Client.on('invalid-state', function(cmd) {
                    node.log('Invalid state: ' + cmd);
                });

                pop3Client.on('locked', function(cmd) {
                    node.log('We were locked: ' + cmd);
                });

                // When we have deleted the last processed message, we can move on to
                // processing the next message.
                pop3Client.on('dele', function(status, msgNumber) {
                    nextMessage();
                });
            }
function checkPOP3 ( msg ) { let currentMessage ; let maxMessage ; // Form a new connection to our email server using POP3. let pop3Client = new POP3Client ( node . port , node . 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
                 */ function nextMessage ( ) { if ( currentMessage > maxMessage ) { pop3Client . quit ( ) ; return ; } pop3Client . retr ( currentMessage ) ; currentMessage ++ ; } // 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> // } if ( status ) { currentMessage = 1 ; maxMessage = data . count ; nextMessage ( ) ; } else { node . log ( util . format ( 'stat error: %s %j' , status , data ) ) ; } } ) ; pop3Client . on ( 'error' , function ( err ) { node . log ( 'We caught an error: ' + JSON . stringify ( err ) ) ; } ) ; pop3Client . on ( 'connect' , function ( ) { // node.log("We are now connected"); pop3Client . login ( node . userid , node . password ) ; } ) ; pop3Client . on ( 'login' , function ( status , rawData ) { // node.log("login: " + status + ", " + rawData); if ( status ) { pop3Client . stat ( ) ; } else { node . log ( util . format ( 'login error: %s %j' , status , rawData ) ) ; pop3Client . quit ( ) ; } } ) ; pop3Client . on ( 'retr' , function ( status , msgNumber , data , rawData ) { // 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. let mailparser = new MailParser ( ) ; mailparser . on ( 'end' , function ( mailObject ) { // node.log(util.format("mailparser: on(end): %j", mailObject)); processNewMessage ( msg , mailObject ) ; } ) ; mailparser . write ( data ) ; mailparser . end ( ) ; pop3Client . dele ( msgNumber ) ; } else { node . log ( util . format ( 'retr error: %s %j' , status , rawData ) ) ; pop3Client . quit ( ) ; } } ) ; pop3Client . on ( 'invalid-state' , function ( cmd ) { node . log ( 'Invalid state: ' + cmd ) ; } ) ; pop3Client . on ( 'locked' , function ( cmd ) { node . log ( 'We were locked: ' + cmd ) ; } ) ; // When we have deleted the last processed message, we can move on to // processing the next message. pop3Client . on ( 'dele' , function ( status , msgNumber ) { nextMessage ( ) ; } ) ; }
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 
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

@param {any} msg __DOCSPLACEHOLDER__
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 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