From 8f9b3e238cb502ba21bf137ff37f5653ec7205ea Mon Sep 17 00:00:00 2001 From: Alexander Demin Date: Mon, 21 Aug 2023 19:15:39 +0100 Subject: [PATCH 1/6] Disable hasNonAsciiCharacters --- config/mail/encoding.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/mail/encoding.ts b/config/mail/encoding.ts index f1a9e8c..d7c7bb6 100644 --- a/config/mail/encoding.ts +++ b/config/mail/encoding.ts @@ -70,7 +70,7 @@ export function quotedPrintableEncode(data: string, encLB = false) { function hasNonAsciiCharacters(str: string) { // deno-lint-ignore no-control-regex - return /[^\u0000-\u007f]/.test(str); + return false && [^\u0000-\u007f]/.test(str); } export function quotedPrintableEncodeInline(data: string) { From 1c70dbfa19dfea2f5c2dc2820acd86e06e7891d6 Mon Sep 17 00:00:00 2001 From: Alexander Demin Date: Mon, 21 Aug 2023 19:22:11 +0100 Subject: [PATCH 2/6] Update encoding.ts --- config/mail/encoding.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config/mail/encoding.ts b/config/mail/encoding.ts index d7c7bb6..106a8ed 100644 --- a/config/mail/encoding.ts +++ b/config/mail/encoding.ts @@ -74,6 +74,8 @@ function hasNonAsciiCharacters(str: string) { } export function quotedPrintableEncodeInline(data: string) { + console.log("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); + return data; if (hasNonAsciiCharacters(data) || data.startsWith("=?")) { return `=?utf-8?Q?${quotedPrintableEncode(data)}?=`; } From 437dfc468192cbb92f9a6a890830634c1e80d0dd Mon Sep 17 00:00:00 2001 From: Alexander Demin Date: Mon, 21 Aug 2023 19:25:42 +0100 Subject: [PATCH 3/6] Update encoding.ts --- config/mail/encoding.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/config/mail/encoding.ts b/config/mail/encoding.ts index 106a8ed..d283593 100644 --- a/config/mail/encoding.ts +++ b/config/mail/encoding.ts @@ -70,12 +70,10 @@ export function quotedPrintableEncode(data: string, encLB = false) { function hasNonAsciiCharacters(str: string) { // deno-lint-ignore no-control-regex - return false && [^\u0000-\u007f]/.test(str); + return false && /[^\u0000-\u007f]/.test(str); } export function quotedPrintableEncodeInline(data: string) { - console.log("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); - return data; if (hasNonAsciiCharacters(data) || data.startsWith("=?")) { return `=?utf-8?Q?${quotedPrintableEncode(data)}?=`; } From 048043f62971bbe2edf5350ad91b49dbba58e414 Mon Sep 17 00:00:00 2001 From: Alexander Demin Date: Tue, 22 Aug 2023 10:35:23 +0100 Subject: [PATCH 4/6] Add rawSubject option to skip encoding subject --- config/mail/encoding.ts | 2 +- config/mail/mod.ts | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/config/mail/encoding.ts b/config/mail/encoding.ts index d283593..f1a9e8c 100644 --- a/config/mail/encoding.ts +++ b/config/mail/encoding.ts @@ -70,7 +70,7 @@ export function quotedPrintableEncode(data: string, encLB = false) { function hasNonAsciiCharacters(str: string) { // deno-lint-ignore no-control-regex - return false && /[^\u0000-\u007f]/.test(str); + return /[^\u0000-\u007f]/.test(str); } export function quotedPrintableEncodeInline(data: string) { diff --git a/config/mail/mod.ts b/config/mail/mod.ts index 80ad9b5..7aea909 100644 --- a/config/mail/mod.ts +++ b/config/mail/mod.ts @@ -39,6 +39,7 @@ export interface SendConfig { */ internalTag?: string | symbol; headers?: Headers; + rawSubject?: boolean; } export interface ResolvedSendConfig { @@ -76,6 +77,7 @@ export function resolveSendConfig(config: SendConfig): ResolvedSendConfig { attachments, internalTag, headers, + rawSubject, } = config; return { @@ -91,7 +93,7 @@ export function resolveSendConfig(config: SendConfig): ResolvedSendConfig { }), replyTo: replyTo ? parseSingleEmail(replyTo) : undefined, inReplyTo, - subject: quotedPrintableEncodeInline(subject), + subject: rawSubject ? quotedPrintableEncodeInline(subject) : subject, attachments: attachments ? attachments.map((attachment) => resolveAttachment(attachment)) : [], From 9ca4fed757097ee86436496f39868a04813bbebf Mon Sep 17 00:00:00 2001 From: Alexander Demin Date: Tue, 22 Aug 2023 10:42:08 +0100 Subject: [PATCH 5/6] Fix the condition --- config/mail/mod.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/mail/mod.ts b/config/mail/mod.ts index 7aea909..e8a4578 100644 --- a/config/mail/mod.ts +++ b/config/mail/mod.ts @@ -93,7 +93,7 @@ export function resolveSendConfig(config: SendConfig): ResolvedSendConfig { }), replyTo: replyTo ? parseSingleEmail(replyTo) : undefined, inReplyTo, - subject: rawSubject ? quotedPrintableEncodeInline(subject) : subject, + subject: rawSubject ? subject : quotedPrintableEncodeInline(subject), attachments: attachments ? attachments.map((attachment) => resolveAttachment(attachment)) : [], From d472f0e73131a1bbe7ecf08985a8219d4266e36e Mon Sep 17 00:00:00 2001 From: Alexander Demin Date: Tue, 22 Aug 2023 10:49:48 +0100 Subject: [PATCH 6/6] Add rawSubject to README --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 2d942b1..1450deb 100644 --- a/README.md +++ b/README.md @@ -275,6 +275,7 @@ export interface SendConfig { */ internalTag?: string | symbol; headers: Record; + rawSubject?: boolean; } ``` @@ -307,6 +308,14 @@ to binary. This can be used with preprocessors so you can give mail a type, for example `'registration'`, `'newsletter'` etc. supports symbols and strings. +#### rawSubject + +The library always encodes the email subject to quoted-printable to conform to the standards. + +Unfortunately, some popular UI clients, for example, Gmail, do not display quoted-printable subjects correctly. Instead, though, they deal perfectly with non-ascii values in the subject, displaying them correctly. + +`rawSubject` option disables quoted-printable encoding for the subject. + ### Allowed Mail Formats A single address `mail@example.de` with the name `NAME` can be encoded in the