diff --git a/index.js b/index.js index fce3316..55dac8d 100755 --- a/index.js +++ b/index.js @@ -10,9 +10,9 @@ const cli = require('cli').enable('catchall').enable('status'); const config = cli.parse({ 'smtp-port': ['s', 'SMTP port to listen on', 'number', 1025], - 'smtp-ip': [false, 'IP Address to bind SMTP service to', 'ip', '0.0.0.0'], + 'smtp-ip': ['i', 'IP Address to bind SMTP service to', 'ip', '0.0.0.0'], 'http-port': ['h', 'HTTP port to listen on', 'number', 1080], - 'http-ip': [false, 'IP Address to bind HTTP service to', 'ip', '0.0.0.0'], + 'http-ip': ['p', 'IP Address to bind HTTP service to', 'ip', '0.0.0.0'], whitelist: ['w', 'Only accept e-mails from these adresses. Accepts multiple e-mails comma-separated', 'string'], max: ['m', 'Max number of e-mails to keep', 'number', 100], auth: ['a', 'Enable Authentication', 'string'], @@ -20,6 +20,7 @@ const config = cli.parse({ }); const whitelist = config.whitelist ? config.whitelist.split(',') : []; +const emailErrors = [] let users = null; if (config.auth && !/.+:.+/.test(config.auth)) { @@ -38,6 +39,13 @@ const server = new SMTPServer({ authOptional: true, maxAllowedUnauthenticatedCommands: 1000, onMailFrom(address, session, cb) { + if (emailErrors.length > 0) { + const isError = emailErrors.shift() + + if (isError) + cb(new Error('Failed to send mail')) + } + if (whitelist.length == 0 || whitelist.indexOf(address.address) !== -1) { cb(); } else { @@ -96,6 +104,8 @@ server.listen(config['smtp-port'], config['smtp-ip']); const app = express(); +app.use(express.json()) + app.use(function(req, res, next) { res.header("Access-Control-Allow-Origin", "*"); res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); @@ -137,6 +147,11 @@ function emailFilter(filter) { } } +app.post('/api/emails/errors', (req, res) => { + emailErrors.push(...req.body.errors) + res.send() +}) + app.get('/api/emails', (req, res) => { res.json(mails.filter(emailFilter(req.query))); }); diff --git a/package.json b/package.json index 4032b93..8f96edd 100644 --- a/package.json +++ b/package.json @@ -31,19 +31,19 @@ }, "dependencies": { "cli": "1.0.1", - "express": "4.16.4", - "express-basic-auth": "1.1.6", - "lodash": "4.17.11", - "mailparser": "2.4.3", - "moment": "2.24.0", - "smtp-server": "3.5.0" + "express": "4.18.2", + "express-basic-auth": "1.2.1", + "lodash": "4.17.21", + "mailparser": "3.5.0", + "moment": "2.29.4", + "smtp-server": "3.11.0" }, "devDependencies": { - "react": "16.8.3", - "react-dom": "16.8.3", - "react-scripts": "2.1.5", - "react-transition-group": "2.6.0", - "reactstrap": "7.1.0" + "react": "18.2.0", + "react-dom": "18.2.0", + "react-scripts": "5.0.1", + "react-transition-group": "4.4.5", + "reactstrap": "9.1.4" }, "engines": { "node": ">=8.5.0"