info: socket.io started SMTP server listening on port 1025 Express server listening on 1080:NaN, in %s mode Coverage

Coverage

93%
115
108
7

/Users/pentiado/Documents/Code/catch-me/lib/config/config.js

100%
4
4
0
LineHitsSource
11'use strict';
2
31var path = require('path');
41var rootPath = path.normalize(__dirname + '/../..');
5
61module.exports = {
7 root: rootPath,
8 port: process.env.PORT || 1080,
9 mailPort: 1025
10};
11

/Users/pentiado/Documents/Code/catch-me/lib/config/express.js

87%
24
21
3
LineHitsSource
11'use strict';
2
31var express = require('express'),
4 favicon = require('static-favicon'),
5 bodyParser = require('body-parser'),
6 methodOverride = require('method-override'),
7 errorHandler = require('errorhandler'),
8 path = require('path'),
9 config = require('./config.js');
10
11/**
12 * Express configuration
13 */
141module.exports = function(app) {
151 var env = app.get('env');
16
171 if ('development' === env) {
181 app.use(require('connect-livereload')());
19
20 // Disable caching of scripts for easier testing
211 app.use(function noCache(req, res, next) {
2213 if (req.url.indexOf('/scripts/') === 0) {
231 res.header('Cache-Control', 'no-cache, no-store, must-revalidate');
241 res.header('Pragma', 'no-cache');
251 res.header('Expires', 0);
26 }
2713 next();
28 });
29
301 app.use(express.static(path.join(config.root, '.tmp')));
311 app.use(express.static(path.join(config.root, 'app')));
321 app.set('views', config.root + '/app/views');
33 }
34
351 if ('production' === env) {
360 app.use(favicon(path.join(config.root, 'public', 'favicon.ico')));
370 app.use(express.static(path.join(config.root, 'public')));
380 app.set('views', config.root + '/views');
39 }
40
411 app.set('view engine', 'jade');
421 app.use(bodyParser());
431 app.use(methodOverride());
44
45 // Error handler - has to be last
461 if ('development' === app.get('env')) {
471 app.use(errorHandler());
48 }
49};

/Users/pentiado/Documents/Code/catch-me/lib/controllers/emails.js

100%
19
19
0
LineHitsSource
11'use strict';
2
31var MailComposer = require('mailcomposer').MailComposer;
4
51exports.details = function (req, res) {
64 var id = req.param('email');
74 db.find({_id: id}, function (err, email) {
85 if (err) { return res.send(500, err); }
95 if (!email.length) { return res.send(404); }
101 res.send(email[0].html);
11 });
12};
13
141exports.download = function (req, res) {
152 var id = req.param('email');
162 db.find({_id: id}, function (err, emails) {
173 if (err) { return res.send(500, err); }
181 if (!emails) { return res.send(404); }
191 res.attachment('email-' + id + '.eml');
201 res.setHeader('Content-Type', 'application/octet-stream');
21
221 var mailcomposer = new MailComposer();
231 mailcomposer.setMessageOption(emails[0]);
241 mailcomposer.streamMessage();
251 mailcomposer.pipe(res);
26 });
27};
28

/Users/pentiado/Documents/Code/catch-me/lib/controllers/index.js

100%
27
27
0
LineHitsSource
11'use strict';
2
31var path = require('path');
41var forever = require('forever');
5
61exports.partials = function (req, res) {
72 var stripped = req.url.split('.')[0];
82 var requestedView = path.join('./', stripped);
92 res.render(requestedView, function (err, html) {
102 if (err) {
111 res.status(404);
121 res.send(404);
13 } else {
141 res.send(html);
15 }
16 });
17};
18
191exports.quit = function (req, res) {
203 forever.list(false, function (err, list) {
214 if (err) { return res.send(500, err); }
222 list = list || [];
232 var currentProcess;
242 for (var i = 0; i < list.length; i++) {
251 if (list[i].pid === process.pid) {
261 currentProcess = i;
271 break;
28 }
29 }
302 if (currentProcess || currentProcess === 0) {
311 forever.stop(currentProcess);
321 return res.send(200);
33 }
341 var message = process.env !== 'production' ?
35 'CatchMe is not in production mode' :
36 'Error, I can\'t find current process';
371 res.send(404, message);
38 });
39};
40
411exports.index = function(req, res) {
422 res.render('index');
43};
44

/Users/pentiado/Documents/Code/catch-me/lib/mailer/index.js

90%
21
19
2
LineHitsSource
11'use strict';
2
31var simplesmtp = require('simplesmtp');
41var MailParser = require('mailparser').MailParser;
51var events = require('events');
61var eventEmitter = new events.EventEmitter();
71var emailGuide = require('email-guide');
8
91exports.register = function (port) {
101 simplesmtp.createSimpleServer({}, function (req) {
111 var mailparser = new MailParser();
121 mailparser.on('end', function (email) {
131 emailGuide(email.html, function (err, guide) {
141 if (err) { throw err; }
151 email.guide = guide;
161 db.insert(email, function (err, newDoc) {
170 if (err) { throw err; }
180 eventEmitter.emit('email:new', newDoc);
19 });
20 });
21 });
221 req.pipe(mailparser);
231 req.accept();
24 }).listen(port, function (err) {
251 var message = err ? err.message : 'SMTP server listening on port ' + port;
261 console.log(message);
27 });
281 return eventEmitter;
29};

/Users/pentiado/Documents/Code/catch-me/lib/routes.js

100%
9
9
0
LineHitsSource
11'use strict';
2
31var index = require('./controllers');
41var emails = require('./controllers/emails.js');
5
61module.exports = function(app) {
71 app.route('/emails/:email/download')
8 .get(emails.download);
91 app.route('/emails/:email')
10 .get(emails.details);
111 app.route('/partials/*')
12 .get(index.partials);
131 app.route('/quit')
14 .get(index.quit);
151 app.route('/*')
16 .get(index.index);
17};

/Users/pentiado/Documents/Code/catch-me/lib/socketio.js

85%
7
6
1
LineHitsSource
11'use strict';
2
31var sockets = require('./sockets');
4
51exports.register = function (server, mailer) {
61 var io = require('socket.io').listen(server);
71 io.set('log level', 1);
8
91 io.sockets.on('connection', function (socket) {
100 sockets.onConnect(socket, mailer);
11 });
12};
13

/Users/pentiado/Documents/Code/catch-me/lib/sockets/index.js

75%
4
3
1
LineHitsSource
11'use strict';
2
31function onConnect (socket, db) {
40 require('./emails').register(socket, db);
5}
6
71exports.onConnect = onConnect;
8