Skip to content

Instantly share code, notes, and snippets.

@wwahammy
Last active August 29, 2015 14:03
Show Gist options
  • Save wwahammy/0f84c8a9f1398eee899d to your computer and use it in GitHub Desktop.
Save wwahammy/0f84c8a9f1398eee899d to your computer and use it in GitHub Desktop.
Help me Kyle, you're my only hope!
smtp = require('smtp-protocol')
Q = require('q')
EventEmitter = require('events').EventEmitter
class LightSMTPServer extends EventEmitter
constructor: () ->
runServer: (userHandlers, options) ->
server = smtp.createServer((req) ->
req.on('message', (stream, ack) ->
console.log
usableHandlers =
userHandlers.filter(
(h) -> Q.try(() -> h.canHandle(req.to)))
Q.all(usableHandlers).then((r) ->
console.log ('in then')
if r.length == 0
console.log('rejecting')
@emit 'message_reject', {address: req.to}
console.log('we emitted rejection')
ack.reject
else
console.log('accepting')
@emit 'message_accept', {address: req.to}
console.log('we emitted acceptance')
ack.accept
)
)
)
server.listen(options["port"])
module.exports = LightSMTPServer
@seiyria
Copy link

seiyria commented Jul 2, 2014

What exactly is the problem? Can you give me some sample input, output, etc for each of the variables?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment