diff options
author | Yuqian Yang <crupest@crupest.life> | 2025-06-16 01:53:32 +0800 |
---|---|---|
committer | Yuqian Yang <crupest@crupest.life> | 2025-06-16 01:53:32 +0800 |
commit | e5509b819a2798077232fb014926e7abc7bf9edc (patch) | |
tree | 38f89f2a9fcb13b003328c6667bc32aa66e9fae1 /deno/mail-relay/aws | |
parent | b4a5820f57a6b5aa72e068e318705fcbeb0c3302 (diff) | |
download | crupest-e5509b819a2798077232fb014926e7abc7bf9edc.tar.gz crupest-e5509b819a2798077232fb014926e7abc7bf9edc.tar.bz2 crupest-e5509b819a2798077232fb014926e7abc7bf9edc.zip |
mail: add save aws message id mail.
Diffstat (limited to 'deno/mail-relay/aws')
-rw-r--r-- | deno/mail-relay/aws/app.ts | 19 | ||||
-rw-r--r-- | deno/mail-relay/aws/mail.ts | 14 |
2 files changed, 27 insertions, 6 deletions
diff --git a/deno/mail-relay/aws/app.ts b/deno/mail-relay/aws/app.ts index cb275ae..86f7c6b 100644 --- a/deno/mail-relay/aws/app.ts +++ b/deno/mail-relay/aws/app.ts @@ -19,6 +19,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 +48,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 +101,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(original, context.mail); + }, ), ); return deliverer; @@ -182,6 +191,7 @@ function createAwsRecycleOnlyServices() { const inbound = createInbound(logFileProvider, { 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 +200,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 }; } diff --git a/deno/mail-relay/aws/mail.ts b/deno/mail-relay/aws/mail.ts index cc05d23..7ac2332 100644 --- a/deno/mail-relay/aws/mail.ts +++ b/deno/mail-relay/aws/mail.ts @@ -25,7 +25,13 @@ export class AwsMailMessageIdRewriteHook implements MailDeliverHook { export class AwsMailMessageIdSaveHook implements MailDeliverHook { readonly #record; - constructor(record: (original: string, aws: string) => Promise<void>) { + constructor( + record: ( + original: string, + aws: string, + context: MailDeliverContext, + ) => Promise<void>, + ) { this.#record = record; } @@ -42,7 +48,11 @@ export class AwsMailMessageIdSaveHook implements MailDeliverHook { } if (context.result.awsMessageId != null) { console.info(`Saving ${messageId} => ${context.result.awsMessageId}.`); - await this.#record(messageId, context.result.awsMessageId); + context.mail.raw = context.mail.raw.replaceAll( + messageId, + context.result.awsMessageId, + ); + await this.#record(messageId, context.result.awsMessageId, context); } console.info("Done save message ids."); } |