Skip to content

Commit

Permalink
Add a way to specify MailParser options
Browse files Browse the repository at this point in the history
  • Loading branch information
rushidesai committed Aug 23, 2013
1 parent a299e41 commit b0cd975
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
5 changes: 3 additions & 2 deletions dist/mail.listener.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions src/mail.listener.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Imap = require "imap"
# MailListener class. Can `emit` events in `node.js` fashion.
class MailListener extends EventEmitter

constructor: (options) ->
constructor: (options, parserOptions) ->
# set this option to `true` if you want to fetch unread emial immediately on lib start.
@fetchUnreadOnStart = options.fetchUnreadOnStart
@markSeen = options.markSeen
Expand All @@ -17,6 +17,7 @@ class MailListener extends EventEmitter
port: options.port
tls: options.secure
@mailbox = options.mailbox || "INBOX"
@parserOptions = parserOptions

# start listener
start: =>
Expand Down Expand Up @@ -59,7 +60,7 @@ class MailListener extends EventEmitter
fetch = @imap.fetch(searchResults, { bodies: '', markSeen: markSeen })
# 6. email was fetched. Parse it!
fetch.on "message", (msg, id) =>
parser = new MailParser
parser = new MailParser @parserOptions
parser.on "end", (mail) =>
mail.uid = id
@emit "mail:parsed", mail
Expand All @@ -75,4 +76,4 @@ class MailListener extends EventEmitter
# imap
imap = @imap

module.exports = MailListener
module.exports = MailListener

0 comments on commit b0cd975

Please sign in to comment.