aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--deno/mail-relay/aws/deliver.ts4
-rw-r--r--deno/mail-relay/dovecot.ts25
-rw-r--r--deno/mail-relay/dumb-smtp-server.ts7
-rw-r--r--deno/mail-relay/mail.ts12
4 files changed, 24 insertions, 24 deletions
diff --git a/deno/mail-relay/aws/deliver.ts b/deno/mail-relay/aws/deliver.ts
index 4dd4b3a..ae010a7 100644
--- a/deno/mail-relay/aws/deliver.ts
+++ b/deno/mail-relay/aws/deliver.ts
@@ -44,10 +44,10 @@ export class AwsMailDeliverer extends SyncMailDeliverer {
`${res.MessageId}@${this.#aws.region}.amazonses.com`;
}
+ context.result.smtpMessage = `AWS Message ID: ${context.result.awsMessageId}`;
context.result.recipients.set("*", {
kind: "done",
- message:
- `Successfully called aws send-email, message id ${context.result.awsMessageId}.`,
+ message: `Successfully called aws send-email.`,
});
} catch (cause) {
context.result.recipients.set("*", {
diff --git a/deno/mail-relay/dovecot.ts b/deno/mail-relay/dovecot.ts
index e8469e6..55e1e9b 100644
--- a/deno/mail-relay/dovecot.ts
+++ b/deno/mail-relay/dovecot.ts
@@ -1,5 +1,3 @@
-import { basename } from "@std/path";
-
import { Mail, MailDeliverContext, MailDeliverer } from "./mail.ts";
// https://doc.dovecot.org/main/core/man/dovecot-lda.1.html
@@ -23,7 +21,7 @@ async function runCommand(
): Promise<CommandResult> {
const { args, stdin, errorCodeMessageMap } = options;
- console.info(`Run external command ${bin} ${args.join(" ")} ...`);
+ console.info(`Run external command ${bin} ${args.join(" ")}`);
try {
// Create and spawn process.
@@ -89,7 +87,7 @@ export class DovecotMailDeliverer extends MailDeliverer {
const recipients = [...context.recipients];
if (recipients.length === 0) {
- context.result.message =
+ context.result.smtpMessage =
"Failed to deliver to dovecot, no recipients are specified.";
return;
}
@@ -196,12 +194,17 @@ export class DovecotMailDeliverer extends MailDeliverer {
);
}
- console.info("Schedule deletion of old mails at 15 seconds later.");
- setTimeout(() => {
- console.info(
- "Try to delete mails in Sent box that has old message id.",
- );
- void this.#deleteMail(from, "Sent", messageIdToDelete);
- }, 1000 * 15);
+ console.info("Schedule deletion of old mails at 15,30,60 seconds later.");
+ [15, 30, 60].forEach((seconds) =>
+ setTimeout(() => {
+ console.info(
+ `Try to delete mails in Sent. (message-id: ${messageIdToDelete}, ` +
+ `attempt delay: ${seconds}s) ` +
+ "Note that the mail may have already been deleted," +
+ " in which case failures of deletion can be just ignored.",
+ );
+ void this.#deleteMail(from, "Sent", messageIdToDelete);
+ }, 1000 * seconds)
+ );
}
}
diff --git a/deno/mail-relay/dumb-smtp-server.ts b/deno/mail-relay/dumb-smtp-server.ts
index ac7069c..94502c4 100644
--- a/deno/mail-relay/dumb-smtp-server.ts
+++ b/deno/mail-relay/dumb-smtp-server.ts
@@ -12,6 +12,7 @@ function createResponses(host: string, port: number | string) {
RCPT: "250 2.1.5 Recipient OK",
DATA: "354 Start mail input; end with <CRLF>.<CRLF>",
QUIT: `211 2.0.0 ${serverName} closing connection`,
+ ACTIVE_CLOSE: "421 4.7.0 Please open a new connection to send more emails",
INVALID: "500 5.5.1 Error: command not recognized",
} as const;
}
@@ -93,15 +94,15 @@ export class DumbSmtpServer {
if (line === ".") {
try {
console.info(LOG_TAG, "Mail data Received, begin to relay...");
- const { message } = await this.#deliverer.deliverRaw(rawMail);
- await send(`250 2.6.0 ${message}`);
+ const { smtpMessage } = await this.#deliverer.deliverRaw(rawMail);
+ await send(`250 2.6.0 ${smtpMessage}`);
rawMail = null;
console.info(LOG_TAG, "Relay succeeded.");
} catch (err) {
console.error(LOG_TAG, "Relay failed.", err);
await send("554 5.3.0 Error: check server log");
- return;
}
+ await send(this.#responses["ACTIVE_CLOSE"]);
} else {
const dataLine = line.startsWith("..") ? line.slice(1) : line;
rawMail += dataLine + CRLF;
diff --git a/deno/mail-relay/mail.ts b/deno/mail-relay/mail.ts
index 1fa1e6a..f1fc892 100644
--- a/deno/mail-relay/mail.ts
+++ b/deno/mail-relay/mail.ts
@@ -159,7 +159,7 @@ export interface MailDeliverRecipientResult {
}
export class MailDeliverResult {
- message: string = "";
+ smtpMessage: string = "";
recipients: Map<string, MailDeliverRecipientResult> = new Map();
constructor(public mail: Mail) {}
@@ -173,13 +173,9 @@ export class MailDeliverResult {
[Symbol.for("Deno.customInspect")]() {
return [
- `message: ${this.message}`,
- ...this.recipients
- .entries()
- .map(
- ([recipient, result]) =>
- `${recipient} [${result.kind}]: ${result.message}`,
- ),
+ ...this.recipients.entries().map(([recipient, result]) =>
+ `${recipient} [${result.kind}]: ${result.message}`
+ ),
].join("\n");
}
}