aboutsummaryrefslogtreecommitdiff
path: root/services/docker/mail-server/aws-sendmail/aws/retriver.ts
diff options
context:
space:
mode:
Diffstat (limited to 'services/docker/mail-server/aws-sendmail/aws/retriver.ts')
-rw-r--r--services/docker/mail-server/aws-sendmail/aws/retriver.ts32
1 files changed, 17 insertions, 15 deletions
diff --git a/services/docker/mail-server/aws-sendmail/aws/retriver.ts b/services/docker/mail-server/aws-sendmail/aws/retriver.ts
index cdfe6f1..1544c04 100644
--- a/services/docker/mail-server/aws-sendmail/aws/retriver.ts
+++ b/services/docker/mail-server/aws-sendmail/aws/retriver.ts
@@ -6,23 +6,23 @@ import {
S3Client,
} from "@aws-sdk/client-s3";
-import { generateTimeStringForFileName, getEnvRequired } from "../base.ts";
+import { generateTimeStringForFileName } from "../util.ts";
import { getLogger } from "../logger.ts";
-import { AwsContext } from "./base.ts";
-import { MailDeliverer } from "../mail.ts";
+import { AwsContext, s3MoveObject } from "./context.ts";
+import { getConfig } from "../config.ts";
export class AwsMailRetriever {
- mailBucket = getEnvRequired(
- "AWS_MAIL_BUCKET",
- "aws s3 bucket saving raw mails",
- );
- liveMailPrefix = "mail/live/";
- archiveMailPrefix = "mail/archive/";
+ readonly liveMailPrefix = "mail/live/";
+ readonly archiveMailPrefix = "mail/archive/";
+ readonly mailBucket = getConfig().getValue("awsMailBucket");
- private s3Client;
- private liveMailRecyclerAborter = new AbortController();
+ private readonly s3Client;
+ private readonly liveMailRecyclerAborter = new AbortController();
- constructor(private aws: AwsContext, private localDeliverer: MailDeliverer) {
+ constructor(
+ aws: AwsContext,
+ private readonly callback: (rawMail: string) => Promise<void>,
+ ) {
const { region, credentials } = aws;
this.s3Client = new S3Client({ region, credentials });
}
@@ -66,9 +66,10 @@ export class AwsMailRetriever {
}
async deliverS3MailObject(messageId: string) {
+ const mailPath = `${this.liveMailPrefix}${messageId}`;
const command = new GetObjectCommand({
Bucket: this.mailBucket,
- Key: `${this.liveMailPrefix}${messageId}`,
+ Key: mailPath,
});
const res = await this.s3Client.send(command);
@@ -78,9 +79,10 @@ export class AwsMailRetriever {
}
const rawMail = await res.Body.transformToString();
- await this.localDeliverer.deliverRaw(rawMail);
+ await this.callback(rawMail);
- const archiveCommand = new
+ // TODO: Continue here.
+ await s3MoveObject(this.s3Client, this.mailBucket, mailPath, );
}
async recycleLiveMails() {