Skip to content

Commit

Permalink
[init] first working service
Browse files Browse the repository at this point in the history
  • Loading branch information
dscape committed Sep 13, 2011
0 parents commit 04104d9
Show file tree
Hide file tree
Showing 8 changed files with 182 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
node_modules/
1 change: 1 addition & 0 deletions LICENSE
@@ -0,0 +1 @@
copyright 2011 nuno job <nunojob.com> (oO)--',--
56 changes: 56 additions & 0 deletions 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: <http://github.com/dscape/cloudmailin>
* bugs: <http://github.com/dscape/cloudmailin/issues>

`(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/
1 change: 1 addition & 0 deletions cfg/server.js
@@ -0,0 +1 @@
module.exports = exports = {port: 80};
14 changes: 14 additions & 0 deletions 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);
});
}
43 changes: 43 additions & 0 deletions index.html
@@ -0,0 +1,43 @@
<html>
<head>
<title>cloudmailin curls</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.3/jquery.min.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script>
function email_hook (email) {
email = JSON.stringify(email).replace(/"/g, '\\"').replace(/'/g, '"');
$('#placeholder').append(
$("<pre>curl -vX POST localhost -d '" + email + "'</pre>"));
}

function subscribe(name) {
if (!name || name === '') { return ; }
var socket = io.connect();
socket.emit('subscribe', name, function(namespace){
io.connect(namespace)
.on('email', email_hook);
});
}
</script>
</head>
<body>
<div id="questions">
<h1>What's your email ID?</h1>
<p>e.g. <strong>282f057bb3b492d36e03</strong> if your email is 282f057bb3b492d36e03@cloudmailin.net</p>
<input type="text" id="subscribe"/>
<p>Just <strong>click somewhere else</strong> in the page to get started!</p>
</div>
<h1>cURLs</h1>
<p>Replace localhost with your server</p>
<div id="placeholder">
</div>
<script>
$(document).ready(function() {
$('#subscribe').focusout(function() {
subscribe($('#subscribe').val());
$('#questions').hide('fast');
});
});
</script>
</body>
</html>
12 changes: 12 additions & 0 deletions 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 <nunojobpinto@gmail.com> (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" }
}
54 changes: 54 additions & 0 deletions 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);
});
});

0 comments on commit 04104d9

Please sign in to comment.