Skip to content

Commit 7a9de5e

Browse files
committed
test(smtp): cover transfer encodings and sort cases 🧮
- Add base64 string attachment encoding expectation coverage - Add quoted-printable UTF-8 attachment encoding expectation coverage - Reject non-ASCII attachment strings under seven-bit transfer encoding rules - Reorder Message.test.ts case titles alphabetically for readability
1 parent effee3f commit 7a9de5e

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

tests/smtp/Message.test.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,25 @@ Deno.test('SmtpMessage accepts safe custom headers', () => {
2222
assertMatch(formattedMessage, /X-Trace_Id: trace-123/)
2323
})
2424

25+
Deno.test('SmtpMessage base64 encodes string attachment content', () => {
26+
const formattedMessage = smtpMessage.formatMessage({
27+
from: 'sender@example.com',
28+
to: 'receiver@example.com',
29+
subject: 'Attachment',
30+
text: 'body',
31+
attachments: [
32+
{
33+
filename: 'hello.txt',
34+
content: 'Hello',
35+
contentType: 'text/plain',
36+
encoding: 'base64'
37+
}
38+
]
39+
})
40+
assertMatch(formattedMessage, /Content-Transfer-Encoding: base64/)
41+
assertMatch(formattedMessage, /SGVsbG8=/)
42+
})
43+
2544
Deno.test('SmtpMessage formats multipart html and text', () => {
2645
const formattedMessage = smtpMessage.formatMessage({
2746
from: 'sender@example.com',
@@ -47,6 +66,25 @@ Deno.test('SmtpMessage formats plain text message', () => {
4766
assertMatch(formattedMessage, /hello/)
4867
})
4968

69+
Deno.test('SmtpMessage quoted-printable encodes utf8 attachment content', () => {
70+
const formattedMessage = smtpMessage.formatMessage({
71+
from: 'sender@example.com',
72+
to: 'receiver@example.com',
73+
subject: 'Attachment',
74+
text: 'body',
75+
attachments: [
76+
{
77+
filename: 'hello.txt',
78+
content: 'Halo ñ',
79+
contentType: 'text/plain',
80+
encoding: 'quoted-printable'
81+
}
82+
]
83+
})
84+
assertMatch(formattedMessage, /Content-Transfer-Encoding: quoted-printable/)
85+
assertMatch(formattedMessage, /Halo =C3=B1/)
86+
})
87+
5088
Deno.test('SmtpMessage rejects custom header names with invalid characters', () => {
5189
assertThrows(
5290
() =>
@@ -115,6 +153,28 @@ Deno.test('SmtpMessage rejects empty custom header names', () => {
115153
)
116154
})
117155

156+
Deno.test('SmtpMessage rejects non-ascii attachment for 7bit encoding', () => {
157+
assertThrows(
158+
() =>
159+
smtpMessage.formatMessage({
160+
from: 'sender@example.com',
161+
to: 'receiver@example.com',
162+
subject: 'Attachment',
163+
text: 'body',
164+
attachments: [
165+
{
166+
filename: 'hello.txt',
167+
content: 'Halo ñ',
168+
contentType: 'text/plain',
169+
encoding: '7bit'
170+
}
171+
]
172+
}),
173+
Error,
174+
'7bit encoding requires ASCII-only content'
175+
)
176+
})
177+
118178
Deno.test('SmtpMessage rejects reserved custom header names', () => {
119179
assertThrows(
120180
() =>

0 commit comments

Comments
 (0)