From d37b3ccac1fad8b28d3b1e3fcff0fad1454694f5 Mon Sep 17 00:00:00 2001 From: mathe42 <2pi_r2@gmx.de> Date: Sun, 12 Feb 2023 20:47:01 +0100 Subject: [PATCH] fix STARTTLS (fixes #59) --- client/basic/client.ts | 2 ++ client/basic/connection.ts | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/client/basic/client.ts b/client/basic/client.ts index 3011325..2ca55d3 100644 --- a/client/basic/client.ts +++ b/client/basic/client.ts @@ -334,6 +334,8 @@ export class SMTPClient { ) { this.#connection.writeCmdAndAssert(CommandCode.READY, "STARTTLS"); + await this.#connection.cleanupForStartTLS() + const conn = await Deno.startTls(this.#connection.conn, { hostname: this.config.connection.hostname, }); diff --git a/client/basic/connection.ts b/client/basic/connection.ts index 06f4ecb..91331f8 100644 --- a/client/basic/connection.ts +++ b/client/basic/connection.ts @@ -36,6 +36,11 @@ export class SMTPConnection { this.#writer = this.#writableTransformStream.writable.getWriter(); } + async cleanupForStartTLS() { + await this.#reader.cancel() + await this.#writer.close() + } + async readLine() { const ret = await this.#reader.read(); return ret.value ?? null; @@ -66,6 +71,7 @@ export class SMTPConnection { } } + public assertCode(cmd: Command | null, code: number, msg?: string) { if (!cmd) { throw new Error(`invalid cmd`);