aboutsummaryrefslogtreecommitdiff
path: root/deno/mail-relay/aws/app.ts
diff options
context:
space:
mode:
Diffstat (limited to 'deno/mail-relay/aws/app.ts')
-rw-r--r--deno/mail-relay/aws/app.ts29
1 files changed, 18 insertions, 11 deletions
diff --git a/deno/mail-relay/aws/app.ts b/deno/mail-relay/aws/app.ts
index cb275ae..a8a9895 100644
--- a/deno/mail-relay/aws/app.ts
+++ b/deno/mail-relay/aws/app.ts
@@ -6,7 +6,6 @@ import { FetchHttpHandler } from "@smithy/fetch-http-handler";
// @ts-types="npm:@types/yargs"
import yargs from "yargs";
-import { LogFileProvider } from "@crupest/base/log";
import { ConfigDefinition, ConfigProvider } from "@crupest/base/config";
import { CronTask } from "@crupest/base/cron";
@@ -19,6 +18,7 @@ import {
import { AwsMailDeliverer } from "./deliver.ts";
import { AwsMailFetcher, AwsS3MailConsumer } from "./fetch.ts";
import { createHono, createInbound, createSmtp, sendMail } from "../app.ts";
+import { DovecotMailDeliverer } from "../dovecot.ts";
const PREFIX = "crupest-mail-server";
const CONFIG_DEFINITIONS = {
@@ -47,6 +47,10 @@ const CONFIG_DEFINITIONS = {
description: "full path of lda executable",
default: "/dovecot/libexec/dovecot/dovecot-lda",
},
+ doveadmPath: {
+ description: "full path of doveadm executable",
+ default: "/dovecot/bin/doveadm",
+ },
inboundFallback: {
description: "comma separated addresses used as fallback recipients",
default: "",
@@ -96,14 +100,18 @@ function createAwsOptions({
function createOutbound(
awsOptions: ReturnType<typeof createAwsOptions>,
db: DbService,
+ local?: DovecotMailDeliverer,
) {
const deliverer = new AwsMailDeliverer(awsOptions);
deliverer.preHooks.push(
new AwsMailMessageIdRewriteHook(db.messageIdToAws.bind(db)),
);
deliverer.postHooks.push(
- new AwsMailMessageIdSaveHook((original, aws) =>
- db.addMessageIdMap({ message_id: original, aws_message_id: aws }).then()
+ new AwsMailMessageIdSaveHook(
+ async (original, aws, context) => {
+ await db.addMessageIdMap({ message_id: original, aws_message_id: aws });
+ void local?.saveNewSent(context.mail, original);
+ },
),
);
return deliverer;
@@ -155,10 +163,7 @@ function createCron(fetcher: AwsMailFetcher, consumer: AwsS3MailConsumer) {
function createBaseServices() {
const config = new ConfigProvider(PREFIX, CONFIG_DEFINITIONS);
Deno.mkdirSync(config.get("dataPath"), { recursive: true });
- const logFileProvider = new LogFileProvider(
- join(config.get("dataPath"), "log"),
- );
- return { config, logFileProvider };
+ return { config };
}
function createAwsFetchOnlyServices() {
@@ -177,11 +182,12 @@ function createAwsFetchOnlyServices() {
function createAwsRecycleOnlyServices() {
const services = createAwsFetchOnlyServices();
- const { config, logFileProvider } = services;
+ const { config } = services;
- const inbound = createInbound(logFileProvider, {
+ const inbound = createInbound({
fallback: config.getList("inboundFallback"),
ldaPath: config.get("ldaPath"),
+ doveadmPath: config.get("doveadmPath"),
aliasFile: join(config.get("dataPath"), "aliases.csv"),
mailDomain: config.get("mailDomain"),
});
@@ -190,12 +196,13 @@ function createAwsRecycleOnlyServices() {
return { ...services, inbound, recycler };
}
+
function createAwsServices() {
const services = createAwsRecycleOnlyServices();
- const { config, awsOptions } = services;
+ const { config, awsOptions, inbound } = services;
const dbService = new DbService(join(config.get("dataPath"), "db.sqlite"));
- const outbound = createOutbound(awsOptions, dbService);
+ const outbound = createOutbound(awsOptions, dbService, inbound);
return { ...services, dbService, outbound };
}