From e734e37a7e04c449645fac086217adffd70aec49 Mon Sep 17 00:00:00 2001 From: Matthias Rolke Date: Tue, 25 Feb 2014 15:00:45 +0100 Subject: [PATCH 1/2] make searchFilter customizable --- index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 +} From ba0257f6b8fa495e7e96eb0eece30edea2e51aaa Mon Sep 17 00:00:00 2001 From: Matthias Rolke Date: Wed, 26 Feb 2014 11:48:15 +0100 Subject: [PATCH 2/2] update readme --- readme.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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(){}) ```