From 7f0cd939a673086fbf0dea8bf78dd2b8239e4bd1 Mon Sep 17 00:00:00 2001 From: mathe42 <2pi_r2@gmx.de> Date: Fri, 22 Apr 2022 22:16:49 +0200 Subject: [PATCH] no more LB encoding --- encoding.ts | 4 ++-- smtp.ts | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/encoding.ts b/encoding.ts index 9a772a4..1174666 100644 --- a/encoding.ts +++ b/encoding.ts @@ -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 diff --git a/smtp.ts b/smtp.ts index 796e6b5..7fd378f 100644 --- a/smtp.ts +++ b/smtp.ts @@ -23,6 +23,8 @@ interface SmtpClientOptions { console_debug?: boolean; unsecure?: boolean; mailFilter?: (box: string, domain: string, internalTag?: string | symbol | undefined) => (Promise | 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 { @@ -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) { @@ -81,6 +85,8 @@ export class SmtpClient { #idlePromise = Promise.resolve() #idleCB = () => {} + #encodeLB = false + #currentlySending = false; #sending: (() => void)[] = []; @@ -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", }); } @@ -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) + } } }