aboutsummaryrefslogtreecommitdiff
path: root/services/docker/mail-server/relay/aws/retriever.ts
diff options
context:
space:
mode:
Diffstat (limited to 'services/docker/mail-server/relay/aws/retriever.ts')
-rw-r--r--services/docker/mail-server/relay/aws/retriever.ts39
1 files changed, 20 insertions, 19 deletions
diff --git a/services/docker/mail-server/relay/aws/retriever.ts b/services/docker/mail-server/relay/aws/retriever.ts
index b81a8f6..756cfc3 100644
--- a/services/docker/mail-server/relay/aws/retriever.ts
+++ b/services/docker/mail-server/relay/aws/retriever.ts
@@ -6,9 +6,10 @@ import {
S3Client,
} from "@aws-sdk/client-s3";
-import { log, warn } from "../logger.ts";
-import { getConfigValue } from "../config.ts";
-import "../util.ts";
+import log from "../log.ts";
+import config from "../config.ts";
+import "../better-js.ts";
+
import { Mail, MailDeliverer } from "../mail.ts";
import { AwsContext, s3MoveObject } from "./context.ts";
@@ -17,7 +18,7 @@ const AWS_SES_S3_SETUP_TAG = "AMAZON_SES_SETUP_NOTIFICATION";
export class AwsMailRetriever {
readonly liveMailPrefix = "mail/live/";
readonly archiveMailPrefix = "mail/archive/";
- readonly mailBucket = getConfigValue("awsMailBucket");
+ readonly mailBucket = config.get("awsMailBucket");
readonly #s3;
@@ -29,7 +30,7 @@ export class AwsMailRetriever {
}
async listLiveMails(): Promise<string[]> {
- log("Begin to retrieve live mails.");
+ log.info("Begin to retrieve live mails.");
const listCommand = new ListObjectsV2Command({
Bucket: this.mailBucket,
@@ -38,14 +39,14 @@ export class AwsMailRetriever {
const res = await this.#s3.send(listCommand);
if (res.Contents == null) {
- warn("Listing live mails in S3 returns null Content.");
+ log.warn("Listing live mails in S3 returns null Content.");
return [];
}
const result: string[] = [];
for (const object of res.Contents) {
if (object.Key == null) {
- warn("Listing live mails in S3 returns an object with no Key.");
+ log.warn("Listing live mails in S3 returns an object with no Key.");
continue;
}
@@ -56,10 +57,10 @@ export class AwsMailRetriever {
return result;
}
- async deliverS3Mail(s3Key: string) {
- log(`Begin to deliver s3 mail ${s3Key}...`);
+ async deliverS3Mail(s3Key: string, recipients: string[] = []) {
+ log.info(`Begin to deliver s3 mail ${s3Key} to ${recipients.join(" ")}...`);
- log(`Fetching s3 mail ${s3Key}...`);
+ log.info(`Fetching s3 mail ${s3Key}...`);
const mailPath = `${this.liveMailPrefix}${s3Key}`;
const command = new GetObjectCommand({
Bucket: this.mailBucket,
@@ -72,26 +73,26 @@ export class AwsMailRetriever {
}
const rawMail = await res.Body.transformToString();
- log(`Done fetching s3 mail ${s3Key}.`);
+ log.info(`Done fetching s3 mail ${s3Key}.`);
- log(`Delivering s3 mail ${s3Key}...`);
+ log.info(`Delivering s3 mail ${s3Key}...`);
const mail = new Mail(rawMail);
- await this.inboundDeliverer.deliver(mail);
- log(`Done delivering s3 mail ${s3Key}.`);
+ await this.inboundDeliverer.deliver({ mail, recipients: recipients });
+ log.info(`Done delivering s3 mail ${s3Key}.`);
- const date = mail.date ?? mail.simpleParseDate();
+ const date = mail.startSimpleParse().sections().headers().date();
const dateString = date?.toFileNameString(true) ?? "invalid-date";
const newPath = `${this.archiveMailPrefix}${dateString}/${s3Key}`;
- log(`Archiving s3 mail ${s3Key} to ${newPath}...`);
+ log.info(`Archiving s3 mail ${s3Key} to ${newPath}...`);
await s3MoveObject(this.#s3, this.mailBucket, mailPath, newPath);
- log(`Done delivering s3 mail ${s3Key}...`);
+ log.info(`Done delivering s3 mail ${s3Key}...`);
}
async recycleLiveMails() {
- log("Begin to recycle live mails...");
+ log.info("Begin to recycle live mails...");
const mails = await this.listLiveMails();
- log(`Found ${mails.length} live mails`);
+ log.info(`Found ${mails.length} live mails`);
for (const s3Key of mails) {
await this.deliverS3Mail(s3Key);
}