From 2f33fe4b1e95a4f868ef13fdf3deed5859595da4 Mon Sep 17 00:00:00 2001 From: scspijker Date: Tue, 11 Oct 2022 17:13:32 +0200 Subject: [PATCH 1/6] [BAC-1140] package.json update for NJS 18 compatibility --- package.json | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) 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" From e415e8d1c40948d71e6076be8210407759c3f32f Mon Sep 17 00:00:00 2001 From: scspijker Date: Fri, 14 Oct 2022 13:04:10 +0200 Subject: [PATCH 2/6] Allow IPv6 compatibility from CLI --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index fce3316..715207c 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'], From e68efb219bd64a086252b72f372f4ac6ee03d80b Mon Sep 17 00:00:00 2001 From: Bart van de Put Date: Thu, 14 Mar 2024 11:03:38 +0100 Subject: [PATCH 3/6] added route for mocking errors --- index.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/index.js b/index.js index 715207c..1f30cb0 100755 --- a/index.js +++ b/index.js @@ -20,6 +20,7 @@ const config = cli.parse({ }); const whitelist = config.whitelist ? config.whitelist.split(',') : []; +let emailErrors = [] let users = null; if (config.auth && !/.+:.+/.test(config.auth)) { @@ -38,6 +39,16 @@ const server = new SMTPServer({ authOptional: true, maxAllowedUnauthenticatedCommands: 1000, onMailFrom(address, session, cb) { + if (emailErrors.length > 0) { + const emailError = emailErrors.pop() + + if (!emailErrors.find(error => error.id === emailError.id)) { + mails.pop() + } + + cb(emailError.error) + } + if (whitelist.length == 0 || whitelist.indexOf(address.address) !== -1) { cb(); } else { @@ -96,6 +107,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 +150,11 @@ function emailFilter(filter) { } } +app.post('/api/emails/errors', (req, res) => { + emailErrors = req.body.errorData + res.send() +}) + app.get('/api/emails', (req, res) => { res.json(mails.filter(emailFilter(req.query))); }); From 3e184ca23d015f2d502d3c3d652b5e5ac21e8312 Mon Sep 17 00:00:00 2001 From: Bart van de Put Date: Thu, 14 Mar 2024 13:13:41 +0100 Subject: [PATCH 4/6] simplify errors --- index.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index 1f30cb0..22f0eac 100755 --- a/index.js +++ b/index.js @@ -20,7 +20,7 @@ const config = cli.parse({ }); const whitelist = config.whitelist ? config.whitelist.split(',') : []; -let emailErrors = [] +const emailErrors = [] let users = null; if (config.auth && !/.+:.+/.test(config.auth)) { @@ -40,13 +40,7 @@ const server = new SMTPServer({ maxAllowedUnauthenticatedCommands: 1000, onMailFrom(address, session, cb) { if (emailErrors.length > 0) { - const emailError = emailErrors.pop() - - if (!emailErrors.find(error => error.id === emailError.id)) { - mails.pop() - } - - cb(emailError.error) + cb(emailErrors.pop()) } if (whitelist.length == 0 || whitelist.indexOf(address.address) !== -1) { @@ -151,7 +145,13 @@ function emailFilter(filter) { } app.post('/api/emails/errors', (req, res) => { - emailErrors = req.body.errorData + let numberOfErrors = req.body.numberOfErrors + + do { + emailErrors.push(new Error('Failed to send email')) + numberOfErrors-- + } while (numberOfErrors > 0) + res.send() }) From 0e957795c8af11a792dcbe70d31c2a5ee664712a Mon Sep 17 00:00:00 2001 From: Bart van de Put Date: Thu, 21 Mar 2024 15:05:33 +0100 Subject: [PATCH 5/6] able to fail mails after successful mails --- index.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 22f0eac..4d0e3cf 100755 --- a/index.js +++ b/index.js @@ -40,7 +40,10 @@ const server = new SMTPServer({ maxAllowedUnauthenticatedCommands: 1000, onMailFrom(address, session, cb) { if (emailErrors.length > 0) { - cb(emailErrors.pop()) + const isError = emailErrors.pop() + + if (isError) + cb(new Error('Failed to send mail')) } if (whitelist.length == 0 || whitelist.indexOf(address.address) !== -1) { @@ -145,13 +148,8 @@ function emailFilter(filter) { } app.post('/api/emails/errors', (req, res) => { - let numberOfErrors = req.body.numberOfErrors - - do { - emailErrors.push(new Error('Failed to send email')) - numberOfErrors-- - } while (numberOfErrors > 0) - + emailErrors.push(...req.body.errors) + emailErrors.reverse() res.send() }) From 8a8054da74f3219152f41f09c80c99949d428c41 Mon Sep 17 00:00:00 2001 From: Bart van de Put Date: Thu, 21 Mar 2024 15:14:08 +0100 Subject: [PATCH 6/6] use shift and dont reverse --- index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/index.js b/index.js index 4d0e3cf..55dac8d 100755 --- a/index.js +++ b/index.js @@ -40,7 +40,7 @@ const server = new SMTPServer({ maxAllowedUnauthenticatedCommands: 1000, onMailFrom(address, session, cb) { if (emailErrors.length > 0) { - const isError = emailErrors.pop() + const isError = emailErrors.shift() if (isError) cb(new Error('Failed to send mail')) @@ -149,7 +149,6 @@ function emailFilter(filter) { app.post('/api/emails/errors', (req, res) => { emailErrors.push(...req.body.errors) - emailErrors.reverse() res.send() })