Skip to content

Commit

Permalink
feat: track datamode so connection; on error no loop (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
mathe42 authored Oct 14, 2022
1 parent f635459 commit 60a46cd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Denomailer - an SMTP client for Deno
# Denomailer - an SMTP client for Deno

[![deno module](https://shield.deno.dev/x/denomailer)](https://deno.land/x/denomailer)

> This was forked from https://github.com/manyuanrong/deno-smtp but now is much
Expand Down
10 changes: 10 additions & 0 deletions client/basic/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export class SMTPClient {

async send(config: ResolvedSendConfig) {
await this.#ready;
let dataMode = false;
try {
await this.#que.que();

Expand Down Expand Up @@ -117,6 +118,7 @@ export class SMTPClient {
);
}

dataMode = true;
await this.#connection.writeCmd("DATA");
this.#connection.assertCode(
await this.#connection.readCmd(),
Expand Down Expand Up @@ -318,9 +320,17 @@ export class SMTPClient {
await this.#connection.readCmd(),
CommandCode.OK,
);
dataMode = false;
await this.#cleanup();
this.#que.next();
} catch (ex) {
if (dataMode) {
console.error("Error while in datamode - connection not revoverable");
queueMicrotask(() => {
this.#connection.conn?.close();
});
throw ex;
}
await this.#cleanup();
this.#que.next();
throw ex;
Expand Down
5 changes: 3 additions & 2 deletions client/basic/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ export class SMTPConnection {
}

const nonNullResult: string[] =
(result.at(-1) === null ? result.slice(0, result.length - 1) : // deno-lint-ignore no-explicit-any
result) as any;
(result.at(-1) === null
? result.slice(0, result.length - 1) // deno-lint-ignore no-explicit-any
: result) as any;

if (nonNullResult.length === 0) return null;

Expand Down

0 comments on commit 60a46cd

Please sign in to comment.