Skip to content

Commit

Permalink
- signal that messages are to be accepted or rejected
Browse files Browse the repository at this point in the history
  • Loading branch information
aredridel committed Aug 23, 2010
1 parent b2677e1 commit 762fefc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
8 changes: 7 additions & 1 deletion bin/smtpd
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
}
})
Expand Down
27 changes: 24 additions & 3 deletions lib/smtp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.