split mail and mailserver

mail = all the per-domain code
mailserver = all the mail server level code
This commit is contained in:
Girish Ramakrishnan
2023-08-04 20:54:16 +05:30
parent fb9d8c23e1
commit 946e5caacb
8 changed files with 349 additions and 327 deletions

View File

@@ -15,7 +15,7 @@ const assert = require('assert'),
debug = require('debug')('box:routes/mailserver'),
HttpError = require('connect-lastmile').HttpError,
HttpSuccess = require('connect-lastmile').HttpSuccess,
mail = require('../mail.js'),
mailServer = require('../mailserver.js'),
middleware = require('../middleware/index.js'),
safe = require('safetydance'),
services = require('../services.js'),
@@ -23,7 +23,7 @@ const assert = require('assert'),
// because of how the proxy middleware works, the http response is already sent by the time this function is called
async function restart(req, res, next) {
await safe(mail.restartMail(), { debug });
await safe(mailServer.restartMail(), { debug });
next();
}
@@ -66,7 +66,7 @@ async function queueProxy(req, res, next) {
}
async function getLocation(req, res, next) {
const [error, result] = await safe(mail.getLocation());
const [error, result] = await safe(mailServer.getLocation());
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(200, { domain: result.domain, subdomain: result.subdomain }));
@@ -78,7 +78,7 @@ async function setLocation(req, res, next) {
if (typeof req.body.domain !== 'string') return next(new HttpError(400, 'domain must be a string'));
if (typeof req.body.subdomain !== 'string') return next(new HttpError(400, 'subdomain must be a string'));
const [error, taskId] = await safe(mail.setLocation(req.body.subdomain, req.body.domain, AuditSource.fromRequest(req)));
const [error, taskId] = await safe(mailServer.setLocation(req.body.subdomain, req.body.domain, AuditSource.fromRequest(req)));
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(202, { taskId }));