Skip to content

Commit

Permalink
feat: add encoding to subject and email name (#37)
Browse files Browse the repository at this point in the history
* add encoding to subject and email name

* format code

* update SECURITY information

* fix security fmt
  • Loading branch information
mathe42 authored Sep 4, 2022
1 parent c602679 commit e775947
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
8 changes: 4 additions & 4 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

We provide security updates currently for these version.

| Version | Supported |
| ------- | ----------------------------------- |
| 1.x | :white_check_mark: |
| 0.x | :white_check_mark: (until 31.07.21) |
| Version | Supported |
| ------- | ------------------ |
| 1.x | :white_check_mark: |
| 0.x | :x: |

We will provide security updates after 1.0 only for the latest version of that
major. We will deprecate major versions so you should always upgrade! Note that
Expand Down
10 changes: 6 additions & 4 deletions config/mail/email.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { quotedPrintableEncodeInline } from "./encoding.ts";

export interface mailObject {
mail: string;
name?: string;
Expand All @@ -23,7 +25,7 @@ export function parseSingleEmail(mail: singleMail): saveMailObject {
if (typeof mail !== "string") {
return {
mail: mail.mail,
name: mail.name ?? "",
name: quotedPrintableEncodeInline(mail.name ?? ""),
};
}

Expand All @@ -41,7 +43,7 @@ export function parseSingleEmail(mail: singleMail): saveMailObject {
const [_, name, email] = res;

return {
name: name.trim(),
name: quotedPrintableEncodeInline(name.trim()),
mail: email.trim(),
};
}
Expand All @@ -53,12 +55,12 @@ export function parseMailList(list: mailList): saveMailObject[] {
if ("mail" in list) {
return [{
mail: list.mail,
name: list.name ?? "",
name: quotedPrintableEncodeInline(list.name ?? ""),
}];
}

return Object.entries(list as mailListObject).map(([name, mail]) => ({
name,
name: quotedPrintableEncodeInline(name),
mail,
}));
}
Expand Down
13 changes: 13 additions & 0 deletions config/mail/encoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,16 @@ export function quotedPrintableEncode(data: string, encLB = false) {

return ret;
}

function hasNonAsciiCharacters(str: string) {
// deno-lint-ignore no-control-regex
return /[^\u0000-\u007f]/.test(str);
}

export function quotedPrintableEncodeInline(data: string) {
if (hasNonAsciiCharacters(data)) {
return `=?utf-8?Q?${quotedPrintableEncode(data)}?=`;
}

return data;
}
3 changes: 2 additions & 1 deletion config/mail/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
} from "./email.ts";
import { ResolvedClientOptions } from "../client.ts";
import { Headers, validateHeaders } from "./headers.ts";
import { quotedPrintableEncodeInline } from "./encoding.ts";
/**
* Config for a mail
*/
Expand Down Expand Up @@ -90,7 +91,7 @@ export function resolveSendConfig(config: SendConfig): ResolvedSendConfig {
}),
replyTo: replyTo ? parseSingleEmail(replyTo) : undefined,
inReplyTo,
subject,
subject: quotedPrintableEncodeInline(subject),
attachments: attachments
? attachments.map((attachment) => resolveAttachment(attachment))
: [],
Expand Down

0 comments on commit e775947

Please sign in to comment.