Permalink
Browse files

- signal that messages are to be accepted or rejected

  • Loading branch information...
1 parent b2677e1 commit 762fefc3b41f35f0931679ce889b53bde6d57197 @aredridel committed Aug 23, 2010
Showing with 31 additions and 4 deletions.
  1. +7 −1 bin/smtpd
  2. +24 −3 lib/smtp.js
View
@@ -29,7 +29,13 @@ var server = smtp.createServer(function(conn) {
console.log(error)
} else {
sys.pump(message, mbox, function() {
- mbox.close()
+ mbox.end()
+ message.accept()
+ })
+ message.on('end', function() {
+ // This is ugly, but pump stops on
+ // close, not end.
+ message.emit('close')
})
}
})
View
@@ -23,6 +23,15 @@ sys.inherits(Message, events.EventEmitter)
Message.prototype.pause = function() { this.emit('pause') }
Message.prototype.resume = function() { this.emit('resume') }
+Message.prototype.accept = function() {
+ this.accepted = true
+ this.emit('accept')
+}
+Message.prototype.reject = function() {
+ this.accepted = false
+ this.emit('reject')
+}
+
var debug;
var debugLevel = parseInt(process.env.NODE_DEBUG, 16);
if (debugLevel & 0x4) {
@@ -82,10 +91,13 @@ function connectionListener(socket) {
if(line.match(/^\./)) {
socket.state = 'welcome'
socket.currentMessage.emit('end')
- if(socket.currentMessage.accepted) {
- Out.out("250 Ok, but I don't know what to do with the message")
+ var message = socket.currentMessage
+ if(message.accepted === undefined) {
+ In.pause()
+ message.on('accept', function() { acceptOrReject(socket, message, In) })
+ message.on('reject', function() { acceptOrReject(socket, message, In) })
} else {
- Out.out("421 Something went wrong")
+ acceptOrReject(socket, message, In)
}
} else {
socket.currentMessage.emit('data', line)
@@ -183,3 +195,12 @@ function resetSMTPState(socket) {
socket.currentMessage = null
socket.heloname = null
}
+
+function acceptOrReject(socket, message, stream) {
+ if(message.accepted) {
+ socket.out("250 Ok, but I don't know what to do with the message")
+ } else {
+ socket.out("421 Something went wrong")
+ }
+ if(stream.paused) stream.resume()
+}

0 comments on commit 762fefc

Please sign in to comment.