aboutsummaryrefslogtreecommitdiff
path: root/deno/mail-relay/app.ts
diff options
context:
space:
mode:
authorYuqian Yang <crupest@crupest.life>2025-06-30 14:25:02 +0800
committerYuqian Yang <crupest@crupest.life>2025-06-30 14:25:02 +0800
commite18d101cae1dfcef29abd102d2908d429f4688d5 (patch)
tree49c0b1d1c237c674fe603db23d2e174acdea6979 /deno/mail-relay/app.ts
parent66e2d76b75ed04ae8a43baefdb970f4cb89c5925 (diff)
downloadcrupest-e18d101cae1dfcef29abd102d2908d429f4688d5.tar.gz
crupest-e18d101cae1dfcef29abd102d2908d429f4688d5.tar.bz2
crupest-e18d101cae1dfcef29abd102d2908d429f4688d5.zip
mail: revert removing.
Diffstat (limited to 'deno/mail-relay/app.ts')
-rw-r--r--deno/mail-relay/app.ts83
1 files changed, 0 insertions, 83 deletions
diff --git a/deno/mail-relay/app.ts b/deno/mail-relay/app.ts
deleted file mode 100644
index 332c430..0000000
--- a/deno/mail-relay/app.ts
+++ /dev/null
@@ -1,83 +0,0 @@
-import { Hono } from "hono";
-import { logger as honoLogger } from "hono/logger";
-
-import {
- AliasRecipientMailHook,
- FallbackRecipientHook,
- MailDeliverer,
- RecipientFromHeadersHook,
-} from "./mail.ts";
-import { DovecotMailDeliverer } from "./dovecot.ts";
-import { DumbSmtpServer } from "./dumb-smtp-server.ts";
-
-export function createInbound(
- {
- fallback,
- mailDomain,
- aliasFile,
- ldaPath,
- doveadmPath,
- }: {
- fallback: string[];
- mailDomain: string;
- aliasFile: string;
- ldaPath: string;
- doveadmPath: string;
- },
-) {
- const deliverer = new DovecotMailDeliverer(ldaPath, doveadmPath);
- deliverer.preHooks.push(
- new RecipientFromHeadersHook(mailDomain),
- new FallbackRecipientHook(new Set(fallback)),
- new AliasRecipientMailHook(aliasFile),
- );
- return deliverer;
-}
-
-export function createHono(outbound: MailDeliverer, inbound: MailDeliverer) {
- const hono = new Hono();
-
- hono.onError((err, c) => {
- console.error("Hono handler threw an uncaught error.", err);
- return c.json({ message: "Server error, check its log." }, 500);
- });
- hono.use(honoLogger());
- hono.post("/send/raw", async (context) => {
- const body = await context.req.text();
- if (body.trim().length === 0) {
- return context.json({ message: "Can't send an empty mail." }, 400);
- } else {
- const result = await outbound.deliverRaw(body);
- return context.json({
- awsMessageId: result.awsMessageId,
- });
- }
- });
- hono.post("/receive/raw", async (context) => {
- await inbound.deliverRaw(await context.req.text());
- return context.json({ message: "Done!" });
- });
-
- return hono;
-}
-
-export function createSmtp(outbound: MailDeliverer) {
- return new DumbSmtpServer(outbound);
-}
-
-export async function sendMail(port: number) {
- const decoder = new TextDecoder();
- let text = "";
- for await (const chunk of Deno.stdin.readable) {
- text += decoder.decode(chunk);
- }
-
- const res = await fetch(`http://127.0.0.1:${port}/send/raw`, {
- method: "post",
- body: text,
- });
- const fn = res.ok ? "info" : "error";
- console[fn](res);
- console[fn](await res.text());
- if (!res.ok) Deno.exit(-1);
-}