diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c2658d7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules/ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..1e7cc50 --- /dev/null +++ b/LICENSE @@ -0,0 +1 @@ +copyright 2011 nuno job (oO)--',-- \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..3c3e192 --- /dev/null +++ b/README.md @@ -0,0 +1,56 @@ +# cloudmailin + +simple service to test the [cloudmailin] service for development. will intercept emails and return them to you so you can `curl` them locally to your app while developing. + +# installation + +1. install [node.js] +2. install [npm] + +```sh + git clone git://github.com/dscape/cloudmailin.git + cd cloudmailin + npm install + node server.js +``` + +if you like you can use a service like [nodejitsu] or [no.de] to host your service. + +# usage + +just point your `cloudmailin` account to `http://cloudmailin.no.de`. now visit `http://cloudmailin.no.de` and follow the instructions. + +after subscribing send an email to your cloudmailin email address and see the curl appear. + +# roadmap, bugs + +check [issue] + +# contribute + +everyone is welcome to contribute. patches, bugfixes, new features + +1. create an [issue] on github so the community can comment on your idea +2. fork `nano` in github +3. create a new branch `git checkout -b my_branch` +4. create tests for the changes you made +5. make sure you pass both existing and newly inserted tests +6. commit your changes +7. push to your branch `git push origin my_branch` +8. create an pull request + +# meta + +* code: `git clone git://github.com/cloudmailin/nano.git` +* home: +* bugs: + +`(oO)--',-` in [caos] + +[cloudmailin]: https://cloudmailin.com +[issue]: http://github.com/dscape/cloudmailin/issues +[caos]: http://caos.di.uminho.pt/ +[nodejitsu]: http://nodejitsu.com +[no.de]: http://no.de +[npm]: http://npmjs.org +[node.js]: http://nodejs.org/ \ No newline at end of file diff --git a/cfg/server.js b/cfg/server.js new file mode 100644 index 0000000..a7bd392 --- /dev/null +++ b/cfg/server.js @@ -0,0 +1 @@ +module.exports = exports = {port: 80}; \ No newline at end of file diff --git a/client.js b/client.js new file mode 100644 index 0000000..c0b3027 --- /dev/null +++ b/client.js @@ -0,0 +1,14 @@ +var socket = io.connect('/'); + +function email_hook (email) { console.log(email); } +function connect_hook (channel) { + return function () { console.log('joined #' + channel); }; +} + +function subscribe(name) { + socket.emit('subscribe', name, function(data){ + var channel = io.connect('/' + data.namespace); + channel.on('connect', connect_hook(data.namespace)); + channel.on('email', email_hook); + }); +} \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..7471982 --- /dev/null +++ b/index.html @@ -0,0 +1,43 @@ + + + cloudmailin curls + + + + + +
+

What's your email ID?

+

e.g. 282f057bb3b492d36e03 if your email is 282f057bb3b492d36e03@cloudmailin.net

+ +

Just click somewhere else in the page to get started!

+
+

cURLs

+

Replace localhost with your server

+
+
+ + + diff --git a/package.json b/package.json new file mode 100644 index 0000000..fd77074 --- /dev/null +++ b/package.json @@ -0,0 +1,12 @@ +{ "name": "cloudmailin" +, "subdomain": "cloudmailin" +, "description": "cloudmailin testing service" +, "homepage": "http://github.com/dscape/cloudmailin" +, "repository": "git://github.com/dscape/cloudmailin" +, "version": "0.0.1" +, "author": "Nuno Job (http://nunojob.com)" +, "keywords": ["cloudmailin", "email"] +, "dependencies": {"express": "2.4.x", "socket.io": "0.8.x"} +, "scripts": {"start": "server.js"} +, "engines" : { "node": ">=0.3.6" } +} \ No newline at end of file diff --git a/server.js b/server.js new file mode 100644 index 0000000..6235d59 --- /dev/null +++ b/server.js @@ -0,0 +1,54 @@ +var express = require('express') + , app = express.createServer() + , io = require('socket.io').listen(app) + , cfg = require('./cfg/server') + , channels = {} + ; + +app.configure( function () { app.use(express.bodyParser()); }); +app.listen(cfg.port); + +// { "address_id": 1920 +// , "created_at": "2011-09-12T06:06:34-07:00" +// , "from": "Nuno.Job@marklogic.com" +// , "mid": "CA93C11F.A951%nuno@marklogic.com" +// , "size":5215 +// , "status": "500" +// , "subject": "Testing" +// , "to": "282f057bb3b492d36e03@cloudmailin.net"} +function email_route(request, response) { + var parsed = request.body + , email_address = parsed.to + , subscribers = channels[email_address] + ; + + if(subscribers) { + subscribers.emit('email', parsed); + response.send('{ok: true}', 201); + } + else { + response.send('{reason: "No subscribers", error: "no_subscribers"}', 200); + } +} + +function app_route(request,response) { + response.sendfile(__dirname + '/index.html'); +} + +app.post('/', email_route); +app.get('/', app_route); + +function connect_hook (channel_name) { + return function () { console.log('user connected to ' + channel_name); }; +} + +io.sockets + .on('connection', function(socket) { + socket.on('subscribe', function(channel_name,cb) { + var channel = io + .of('/' + channel_name) + .on('connection', connect_hook(channel_name)); + channels[channel_name] = channel; + cb('/' + channel_name); + }); + }); \ No newline at end of file