diff --git a/index.js b/index.js index 56a12cb..866ee90 100644 --- a/index.js +++ b/index.js @@ -24,16 +24,20 @@ function MailListener(options) { this.attachmentOptions = options.attachmentOptions || {}; this.attachments = options.attachments || false; this.attachmentOptions.directory = (this.attachmentOptions.directory ? this.attachmentOptions.directory : ''); - this.imap = new Imap({ - xoauth2: options.xoauth2, - user: options.username, - password: options.password, - host: options.host, - port: options.port, - tls: options.tls, - tlsOptions: options.tlsOptions || {} - }); + if (!options.imap) { + options.imap = { + xoauth2: options.xoauth2, + user: options.username, + password: options.password, + host: options.host, + port: options.port, + tls: options.tls, + tlsOptions: options.tlsOptions || {} + }; + } + + this.imap = new Imap(options.imap); this.imap.once('ready', imapReady.bind(this)); this.imap.once('close', imapClose.bind(this)); this.imap.on('error', imapError.bind(this)); diff --git a/readme.md b/readme.md index 95a586d..712d0c6 100644 --- a/readme.md +++ b/readme.md @@ -21,12 +21,14 @@ JavaScript Code: var MailListener = require("mail-listener2"); var mailListener = new MailListener({ - username: "imap-username", - password: "imap-password", - host: "imap-host", - port: 993, // imap port - tls: true, - tlsOptions: { rejectUnauthorized: false }, + imap: { // please refer to the node-imap documentation for more details on configuration + user: "imap-username", + password: "imap-password", + host: "imap-host", + port: 993, // imap port + tls: true, + tlsOptions: { rejectUnauthorized: false } + }, mailbox: "INBOX", // mailbox to monitor searchFilter: ["UNSEEN", "FLAGGED"], // the search filter being used after an IDLE notification has been retrieved markSeen: true, // all fetched email willbe marked as seen and not fetched next time diff --git a/test.js b/test.js index c22f3b5..10e564d 100644 --- a/test.js +++ b/test.js @@ -1,12 +1,14 @@ var MailListener = require("./"); var mailListener = new MailListener({ - username: "xxxx", - password: "xxx", - host: "imap.gmail.com", - port: 993, - tls: true, - tlsOptions: { rejectUnauthorized: false }, + imap: { + user: "xxxx", + password: "xxx", + host: "imap.gmail.com", + port: 993, + tls: true, + tlsOptions: { rejectUnauthorized: false } + }, mailbox: "INBOX", markSeen: true, fetchUnreadOnStart: true,