info: socket.io started SMTP server listening on port 1025 Express server listening on 1080:NaN, in %s mode
Line | Hits | Source |
---|---|---|
1 | 1 | 'use strict'; |
2 | ||
3 | 1 | var path = require('path'); |
4 | 1 | var rootPath = path.normalize(__dirname + '/../..'); |
5 | ||
6 | 1 | module.exports = { |
7 | root: rootPath, | |
8 | port: process.env.PORT || 1080, | |
9 | mailPort: 1025 | |
10 | }; | |
11 |
Line | Hits | Source |
---|---|---|
1 | 1 | 'use strict'; |
2 | ||
3 | 1 | var 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 | */ | |
14 | 1 | module.exports = function(app) { |
15 | 1 | var env = app.get('env'); |
16 | ||
17 | 1 | if ('development' === env) { |
18 | 1 | app.use(require('connect-livereload')()); |
19 | ||
20 | // Disable caching of scripts for easier testing | |
21 | 1 | app.use(function noCache(req, res, next) { |
22 | 13 | if (req.url.indexOf('/scripts/') === 0) { |
23 | 1 | res.header('Cache-Control', 'no-cache, no-store, must-revalidate'); |
24 | 1 | res.header('Pragma', 'no-cache'); |
25 | 1 | res.header('Expires', 0); |
26 | } | |
27 | 13 | next(); |
28 | }); | |
29 | ||
30 | 1 | app.use(express.static(path.join(config.root, '.tmp'))); |
31 | 1 | app.use(express.static(path.join(config.root, 'app'))); |
32 | 1 | app.set('views', config.root + '/app/views'); |
33 | } | |
34 | ||
35 | 1 | if ('production' === env) { |
36 | 0 | app.use(favicon(path.join(config.root, 'public', 'favicon.ico'))); |
37 | 0 | app.use(express.static(path.join(config.root, 'public'))); |
38 | 0 | app.set('views', config.root + '/views'); |
39 | } | |
40 | ||
41 | 1 | app.set('view engine', 'jade'); |
42 | 1 | app.use(bodyParser()); |
43 | 1 | app.use(methodOverride()); |
44 | ||
45 | // Error handler - has to be last | |
46 | 1 | if ('development' === app.get('env')) { |
47 | 1 | app.use(errorHandler()); |
48 | } | |
49 | }; |
Line | Hits | Source |
---|---|---|
1 | 1 | 'use strict'; |
2 | ||
3 | 1 | var MailComposer = require('mailcomposer').MailComposer; |
4 | ||
5 | 1 | exports.details = function (req, res) { |
6 | 4 | var id = req.param('email'); |
7 | 4 | db.find({_id: id}, function (err, email) { |
8 | 5 | if (err) { return res.send(500, err); } |
9 | 5 | if (!email.length) { return res.send(404); } |
10 | 1 | res.send(email[0].html); |
11 | }); | |
12 | }; | |
13 | ||
14 | 1 | exports.download = function (req, res) { |
15 | 2 | var id = req.param('email'); |
16 | 2 | db.find({_id: id}, function (err, emails) { |
17 | 3 | if (err) { return res.send(500, err); } |
18 | 1 | if (!emails) { return res.send(404); } |
19 | 1 | res.attachment('email-' + id + '.eml'); |
20 | 1 | res.setHeader('Content-Type', 'application/octet-stream'); |
21 | ||
22 | 1 | var mailcomposer = new MailComposer(); |
23 | 1 | mailcomposer.setMessageOption(emails[0]); |
24 | 1 | mailcomposer.streamMessage(); |
25 | 1 | mailcomposer.pipe(res); |
26 | }); | |
27 | }; | |
28 |
Line | Hits | Source |
---|---|---|
1 | 1 | 'use strict'; |
2 | ||
3 | 1 | var path = require('path'); |
4 | 1 | var forever = require('forever'); |
5 | ||
6 | 1 | exports.partials = function (req, res) { |
7 | 2 | var stripped = req.url.split('.')[0]; |
8 | 2 | var requestedView = path.join('./', stripped); |
9 | 2 | res.render(requestedView, function (err, html) { |
10 | 2 | if (err) { |
11 | 1 | res.status(404); |
12 | 1 | res.send(404); |
13 | } else { | |
14 | 1 | res.send(html); |
15 | } | |
16 | }); | |
17 | }; | |
18 | ||
19 | 1 | exports.quit = function (req, res) { |
20 | 3 | forever.list(false, function (err, list) { |
21 | 4 | if (err) { return res.send(500, err); } |
22 | 2 | list = list || []; |
23 | 2 | var currentProcess; |
24 | 2 | for (var i = 0; i < list.length; i++) { |
25 | 1 | if (list[i].pid === process.pid) { |
26 | 1 | currentProcess = i; |
27 | 1 | break; |
28 | } | |
29 | } | |
30 | 2 | if (currentProcess || currentProcess === 0) { |
31 | 1 | forever.stop(currentProcess); |
32 | 1 | return res.send(200); |
33 | } | |
34 | 1 | var message = process.env !== 'production' ? |
35 | 'CatchMe is not in production mode' : | |
36 | 'Error, I can\'t find current process'; | |
37 | 1 | res.send(404, message); |
38 | }); | |
39 | }; | |
40 | ||
41 | 1 | exports.index = function(req, res) { |
42 | 2 | res.render('index'); |
43 | }; | |
44 |
Line | Hits | Source |
---|---|---|
1 | 1 | 'use strict'; |
2 | ||
3 | 1 | var simplesmtp = require('simplesmtp'); |
4 | 1 | var MailParser = require('mailparser').MailParser; |
5 | 1 | var events = require('events'); |
6 | 1 | var eventEmitter = new events.EventEmitter(); |
7 | 1 | var emailGuide = require('email-guide'); |
8 | ||
9 | 1 | exports.register = function (port) { |
10 | 1 | simplesmtp.createSimpleServer({}, function (req) { |
11 | 1 | var mailparser = new MailParser(); |
12 | 1 | mailparser.on('end', function (email) { |
13 | 1 | emailGuide(email.html, function (err, guide) { |
14 | 1 | if (err) { throw err; } |
15 | 1 | email.guide = guide; |
16 | 1 | db.insert(email, function (err, newDoc) { |
17 | 0 | if (err) { throw err; } |
18 | 0 | eventEmitter.emit('email:new', newDoc); |
19 | }); | |
20 | }); | |
21 | }); | |
22 | 1 | req.pipe(mailparser); |
23 | 1 | req.accept(); |
24 | }).listen(port, function (err) { | |
25 | 1 | var message = err ? err.message : 'SMTP server listening on port ' + port; |
26 | 1 | console.log(message); |
27 | }); | |
28 | 1 | return eventEmitter; |
29 | }; |
Line | Hits | Source |
---|---|---|
1 | 1 | 'use strict'; |
2 | ||
3 | 1 | var index = require('./controllers'); |
4 | 1 | var emails = require('./controllers/emails.js'); |
5 | ||
6 | 1 | module.exports = function(app) { |
7 | 1 | app.route('/emails/:email/download') |
8 | .get(emails.download); | |
9 | 1 | app.route('/emails/:email') |
10 | .get(emails.details); | |
11 | 1 | app.route('/partials/*') |
12 | .get(index.partials); | |
13 | 1 | app.route('/quit') |
14 | .get(index.quit); | |
15 | 1 | app.route('/*') |
16 | .get(index.index); | |
17 | }; |
Line | Hits | Source |
---|---|---|
1 | 1 | 'use strict'; |
2 | ||
3 | 1 | var sockets = require('./sockets'); |
4 | ||
5 | 1 | exports.register = function (server, mailer) { |
6 | 1 | var io = require('socket.io').listen(server); |
7 | 1 | io.set('log level', 1); |
8 | ||
9 | 1 | io.sockets.on('connection', function (socket) { |
10 | 0 | sockets.onConnect(socket, mailer); |
11 | }); | |
12 | }; | |
13 |
Line | Hits | Source |
---|---|---|
1 | 1 | 'use strict'; |
2 | ||
3 | 1 | function onConnect (socket, db) { |
4 | 0 | require('./emails').register(socket, db); |
5 | } | |
6 | ||
7 | 1 | exports.onConnect = onConnect; |
8 |