aboutsummaryrefslogtreecommitdiff
path: root/services/docker/mail-server/relay/app.ts
diff options
context:
space:
mode:
Diffstat (limited to 'services/docker/mail-server/relay/app.ts')
-rw-r--r--services/docker/mail-server/relay/app.ts78
1 files changed, 0 insertions, 78 deletions
diff --git a/services/docker/mail-server/relay/app.ts b/services/docker/mail-server/relay/app.ts
deleted file mode 100644
index 87a4d77..0000000
--- a/services/docker/mail-server/relay/app.ts
+++ /dev/null
@@ -1,78 +0,0 @@
-import { join } from "@std/path";
-import { Hono } from "hono";
-import { logger as honoLogger } from "hono/logger";
-
-import log from "./log.ts";
-import config from "./config.ts";
-import { DbService } from "./db.ts";
-import {
- AliasRecipientMailHook,
- FallbackRecipientHook,
- MailDeliverer,
-} from "./mail.ts";
-import { DovecotMailDeliverer } from "./dovecot.ts";
-import { CronTask, CronTaskConfig } from "./cron.ts";
-import { DumbSMTPServer as DumbSmtpServer } from "./dumb-smtp-server.ts";
-
-export abstract class AppBase {
- protected readonly db: DbService;
- protected readonly crons: CronTask[] = [];
- protected readonly routes: Hono[] = [];
- protected readonly inboundDeliverer: MailDeliverer;
- protected readonly hono = new Hono();
-
- protected abstract readonly outboundDeliverer: MailDeliverer;
-
- constructor() {
- const dataPath = config.get("dataPath");
- Deno.mkdirSync(dataPath, { recursive: true });
- log.path = join(dataPath, "log");
- log.info(config);
-
- this.db = new DbService(join(dataPath, "db.sqlite"));
- this.inboundDeliverer = new DovecotMailDeliverer();
- this.inboundDeliverer.preHooks.push(
- new FallbackRecipientHook(new Set(config.getList("inboundFallback"))),
- new AliasRecipientMailHook(join(dataPath, "aliases.csv")),
- );
-
- this.hono.onError((err, c) => {
- log.error(err);
- return c.json({ msg: "Server error, check its log." }, 500);
- });
-
- this.hono.use(honoLogger());
- this.hono.post("/send/raw", async (context) => {
- const body = await context.req.text();
- if (body.trim().length === 0) {
- return context.json({ msg: "Can't send an empty mail" }, 400);
- } else {
- const mail = await this.outboundDeliverer.deliverRaw(body);
- return context.json({
- messageId: mail.messageId,
- awsMessageId: mail.awsMessageId,
- });
- }
- });
- this.hono.post("/receive/raw", async (context) => {
- await this.inboundDeliverer.deliverRaw(await context.req.text());
- return context.json({ "msg": "Done!" });
- });
- }
-
- createCron(config: CronTaskConfig): CronTask {
- const cron = new CronTask(config);
- this.crons.push(cron);
- return cron;
- }
-
- serve(): { smtp: DumbSmtpServer; http: Deno.HttpServer } {
- const smtp = new DumbSmtpServer(this.outboundDeliverer);
- smtp.serve();
- const http = Deno.serve({
- hostname: config.HTTP_HOST,
- port: config.HTTP_PORT,
- }, this.hono.fetch);
- return { smtp, http };
- }
-}