diff --git a/index.js b/index.js index 7afef15..565d6e2 100644 --- a/index.js +++ b/index.js @@ -8,6 +8,7 @@ module.exports = MailListener; function MailListener(options) { this.markSeen = !!options.markSeen; this.mailbox = options.mailbox || "INBOX"; + this.searchFilter = options.searchFilter || "UNSEEN"; this.fetchUnreadOnStart = !!options.fetchUnreadOnStart; this.mailParserOptions = options.mailParserOptions || {}, this.imap = new Imap({ @@ -64,7 +65,7 @@ function imapMail() { function parseUnread() { var self = this; - this.imap.search([ 'UNSEEN' ], function(err, results) { + this.imap.search([ self.searchFilter ], function(err, results) { if (err) { self.emit('error',err); } else if(results.length > 0) { @@ -83,4 +84,4 @@ function parseUnread() { }); } }); -} \ No newline at end of file +} diff --git a/readme.md b/readme.md index 84cb46b..e33e23e 100644 --- a/readme.md +++ b/readme.md @@ -28,6 +28,7 @@ var mailListener = new MailListener({ tls: true, tlsOptions: { rejectUnauthorized: false }, mailbox: "INBOX", // mailbox to monitor + searchFilter: "UNSEEN", // 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 fetchUnreadOnStart: true, // use it only if you want to get all unread email on lib start. Default is `false`, mailParserOptions: {streamAttachments: true} // options to be passed to mailParser lib. @@ -57,7 +58,7 @@ mailListener.on("mail", function(mail){ }); // it's possible to access imap object from node-imap library for performing additional actions. E.x. -mailListener.imap.move(:msguids, :mailboxes, function(){}) +mailListener.imap.move(:msguids, :mailboxes, function(){}) ```