Skip to content

Commit

Permalink
Merge pull request #9 from amtrack/master
Browse files Browse the repository at this point in the history
make searchFilter customizable
  • Loading branch information
chirag04 committed Feb 26, 2014
2 parents 64177ce + ba0257f commit c7f3ca8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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) {
Expand All @@ -83,4 +84,4 @@ function parseUnread() {
});
}
});
}
}
3 changes: 2 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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(){})

```

Expand Down

0 comments on commit c7f3ca8

Please sign in to comment.