@@ -22,6 +22,25 @@ Deno.test('SmtpMessage accepts safe custom headers', () => {
2222 assertMatch ( formattedMessage , / X - T r a c e _ I d : t r a c e - 1 2 3 / )
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 , / C o n t e n t - T r a n s f e r - E n c o d i n g : b a s e 6 4 / )
41+ assertMatch ( formattedMessage , / S G V s b G 8 = / )
42+ } )
43+
2544Deno . 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 , / h e l l o / )
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 , / C o n t e n t - T r a n s f e r - E n c o d i n g : q u o t e d - p r i n t a b l e / )
85+ assertMatch ( formattedMessage , / H a l o = C 3 = B 1 / )
86+ } )
87+
5088Deno . 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+
118178Deno . test ( 'SmtpMessage rejects reserved custom header names' , ( ) => {
119179 assertThrows (
120180 ( ) =>
0 commit comments