Last active
August 29, 2015 14:03
-
-
Save wwahammy/0f84c8a9f1398eee899d to your computer and use it in GitHub Desktop.
Help me Kyle, you're my only hope!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What exactly is the problem? Can you give me some sample input, output, etc for each of the variables?