Created
July 23, 2011 15:46
-
-
Save michielbdejong/1101566 to your computer and use it in GitHub Desktop.
smtp forwarded into the browser over a websocket
This file contains 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
var Browsermail = function() { | |
var sockets = {} | |
require('smtp').createServer(function(connection) { | |
connection.on('DATA', function(message) { | |
for(var i = 0; i < message.recipients.length; i++) { | |
var emailAddress = message.recipients[i].address.match(/([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)/g)[0] | |
if(socket = sockets[emailAddress]) { | |
message.on('data', function(data) { | |
socket.emit('data', data) | |
}) | |
message.on('end', function() { | |
socket.emit('end') | |
message.accept() | |
}) | |
} | |
} | |
}) | |
}).listen(25) | |
return { | |
addForward: function(emailAddress, socket) { | |
sockets[emailAddress] = socket | |
} | |
} | |
} | |
var b = Browsermail() | |
require('socket.io').listen(8000).sockets.on('connection', function(socket) { | |
b.addForward('[email protected]', socket) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment