Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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