The IMAPListener SIB Listener periodically checks an IMAP mailbox for activity and triggers a workflow if mail messages matching its filter criteria are found.
Module | sib_imaplistener |
Version | 1.3.0 |
var IMAPServiceCustom = { _id: "imapSample:1", _name: "SIB IMAP Listener Sample", box: "INBOX", filter: ['UNSEEN'], imap: { user: "email@domain.com", password: "thePassword", host: "mail.host.com", port: 993, tls: true }, getXML: (bodies)=>{ for( let i=0; i < bodies.length; i++ ) { if( !bodies[i].hdr ) continue; console.log( bodies[i].hdr ); let ct = bodies[i].hdr["Content-Type"]; if( ct.indexOf( "application/xml" ) == -1 ) continue; let fname = ct.split( "name=\"" )[1].split( "\"" )[0]; let data = new Buffer( bodies[i].bodies[0].content, "base64" ).toString( "UTF-8" ); return {filename:fname, content:data}; } return {}; }, init: ( thisListener )=>{}, inputFormat: (topic, msg, cb)=>{ let oMsg = {from: msg.hdr.From, to:msg.hdr.To, subj:msg.hdr.Subject, _sibheader:msg._sibheader}; oMsg.xml = IMAPServiceCustom.getXML( msg.bodies ); cb( oMsg ); }, loggerCfg: { dest: { file: false, console: true, mqtt: true } }, outputFormat: (topic, msg, cb)=>{ cb( msg ); }, persist: false, schedule: "* * * * *", setFlags: "Deleted", mqtt: "mqtt://localhost", topic: "SIB/Samples/IMAPListener" }; module.exports = IMAPServiceCustom;