Skip to content

Commit

Permalink
no more LB encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
mathe42 committed Apr 22, 2022
1 parent d4a599a commit 7f0cd93
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
4 changes: 2 additions & 2 deletions encoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ export function quotedPrintableEncode(data: string, encLB = false) {

if (old.endsWith("\r") || old.endsWith("\n")) {
ret += old;
} else {
ret += `${old}=\r\n`;
}

ret += `${old}=\r\n`;
}

// Add rest with no new line
Expand Down
16 changes: 13 additions & 3 deletions smtp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ interface SmtpClientOptions {
console_debug?: boolean;
unsecure?: boolean;
mailFilter?: (box: string, domain: string, internalTag?: string | symbol | undefined) => (Promise<boolean> | boolean)
/** @deprecated use ONLY for debugging! enable this to make shure that \n and \r are differently encoded. But this will tripple their size!*/
encodeLB?: boolean
}

export class SmtpClient {
Expand All @@ -39,11 +41,13 @@ export class SmtpClient {
constructor({
console_debug = false,
unsecure = false,
mailFilter
mailFilter,
encodeLB = false
}: SmtpClientOptions = {}) {
this.#console_debug = console_debug;
this.#allowUnsecure = unsecure;
this.#mailFilter = mailFilter
this.#encodeLB = encodeLB
}

async connect(config: ConnectConfig | ConnectConfigWithAuthentication) {
Expand Down Expand Up @@ -81,6 +85,8 @@ export class SmtpClient {
#idlePromise = Promise.resolve()
#idleCB = () => {}

#encodeLB = false

#currentlySending = false;
#sending: (() => void)[] = [];

Expand Down Expand Up @@ -167,7 +173,7 @@ export class SmtpClient {
if (config.content) {
config.mimeContent.push({
mimeType: 'text/plain; charset="utf-8"',
content: quotedPrintableEncode(config.content, true),
content: quotedPrintableEncode(config.content, this.#encodeLB),
transferEncoding: "quoted-printable",
});
}
Expand All @@ -181,9 +187,13 @@ export class SmtpClient {

config.mimeContent.push({
mimeType: 'text/html; charset="utf-8"',
content: quotedPrintableEncode(config.html, true),
content: quotedPrintableEncode(config.html),
transferEncoding: "quoted-printable",
});

if(this.#console_debug) {
console.log(config.mimeContent.at(-1)?.content, this.#encodeLB)
}
}
}

Expand Down

0 comments on commit 7f0cd93

Please sign in to comment.