User Tools

Site Tools




The IMAPListener SIB Listener periodically checks an IMAP mailbox for activity and triggers a workflow if mail messages matching its filter criteria are found.




  • CRONSchedule: [.custom.schedule]
    • on trigger:
      • Connect to IMAP server (.custom.imap)
        • on connect:
          • Check mailbox for messages according to .custom.filter
            • on message:
              • Publish: .custom.topic

Custom configuration

var IMAPServiceCustom = {
	_id: "imapSample:1",
	_name: "SIB IMAP Listener Sample",
	box: "INBOX",
	filter: ['UNSEEN'],
	imap: {
		user: "",
		password: "thePassword",
		host: "",
		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;
  • _id: The unique ID of this service
  • _name: A plaintext description of this service
  • box: The name of the mailbox to check
  • filter: The IMAP filter according to node-imap filtering
  • imap: The server configuration to connect to according to the node-imap format
  • init(thisListener): If defined this method is executed when the service is starting up as the last step of initialization. thisListener is a reference to the instance of the listener that does the method call.
  • inputFormat(topic, msg, callback): The method that is run on service activation. The original message is passed as the argument and the return value from this method must be a JSON formatted message conforming to the SIB message standard.
  • loggerCfg: A JSON Object defining what logger actions should be active for this service (see Logger Configuration
  • outputFormat(topic, msg, callback): This message is run on the response data before publishing to the response topic. The response message is passed as the argument and the return data must be a JSON formatted message conforming to the SIB message standard.
  • publishInput: If defined overrides the standard publishing to the internal MQTT transfer
  • publishOutput: If defined overrides the standard MQTT publish of the output data (to the responseTopic) and instead lets the publishOutput be responsible for publishing data to the output topic.
  • persist: True/false, if true the listener does not disconnect from the mailserver but tries to keep an open connection which will be re-used betweeen runs
  • schedule: The cron-schedule when to run the check
  • setFlags: Which flags to set to the fetched emails when processing is done. See node-imap documentation for valid values
  • mqtt: The MQTT connection string for the internal MQTT transport
  • topic: The MQTT topic to subscribe to on the internal MQTT transport
sib/listeners/imaplistener.txt · Last modified: 2019/09/20 07:30 by hubbe