-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbrowsermail.js
More file actions
30 lines (28 loc) · 902 Bytes
/
browsermail.js
File metadata and controls
30 lines (28 loc) · 902 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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('mich@myfavouritesandwich.org', socket);
});