Skip to content

Commit 3c1639a

Browse files
committed
Adds new attachment tests to sendmail suite
1 parent 76c4abd commit 3c1639a

2 files changed

Lines changed: 82 additions & 21 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
content of info.txt
1+
content of info file

rosetta-test-suites/sendmail.ros

Lines changed: 81 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
; indepdenent of whether this is done with an API from the tested library directly or by using
66
; another library, e.g. a MIME library from the standard library.
77
(sources
8-
'("CPython SMTP tests" "Python Foundation" "https://github.com/python/cpython/blob/9ba2a4638d7b620c939face7642b2f53a9fadc4b/Lib/test/test_smtplib.py")
9-
'("Ruby net-smtp tests" "MRI maintainers" "https://github.com/ruby/net-smtp/blob/master/test/net/smtp/test_smtp.rb")
8+
'("Ruby mail gem spec" "Mikel Lindsaar" "https://github.com/mikel/mail")
109
'("SMTP RFC 2821" "IETF" "https://tools.ietf.org/html/rfc2821")
1110
'("SMTP RFC 5321" "IETF" "https://tools.ietf.org/html/rfc5321")
12-
'("SMTP RFC 4954" "IETF" "https://tools.ietf.org/html/rfc4954"))
11+
'("RFC 2183 - Content-Disposition" "IETF" "https://tools.ietf.org/html/rfc2183"))
1312

1413
(list
1514
; Socket
@@ -353,28 +352,47 @@
353352
; attachments-properties is a list of alists with the following keys:
354353
; "data", "file-name", "content-type", or "content-disposition"
355354
(define sendmail-send-with-attachments (lambda attachments-properties
356-
(sendmail-send-message-full
357-
smtp-connection
358-
"message content" "sender@sender.to" '("recipient@recipient.to")
359-
'() '()
360-
(make-hash-table)
361-
(map alist->hash-table attachments-properties)
362-
'() '())))
355+
(let
356+
((properties-hashs (map alist->hash-table attachments-properties)))
357+
(for-each
358+
(lambda (property-hash)
359+
(if (not (hash-table-exists? property-hash "content-disposition"))
360+
(hash-table-set! property-hash "content-disposition" "attachment")))
361+
properties-hashs)
362+
(sendmail-send-message-full
363+
smtp-connection
364+
"message content" "sender@sender.to" '("recipient@recipient.to")
365+
'() '()
366+
(make-hash-table)
367+
properties-hashs
368+
'() '()))))
363369

364-
(test "basic text attachment" (lambda ()
370+
(test "basic single text attachment" (lambda ()
365371
(sendmail-send-with-attachments
366372
'(("data" "info.txt")
367373
("file-name" "info.txt")
368374
("content-type" "text/plain")))
369375
(assert
370376
(or
371-
(server-message-contains? "content of info.txt")
372-
(server-message-contains? "Y29udGVudCBvZiBpbmZvLnR4dA=="))
377+
(server-message-contains? "content of info file")
378+
(server-message-contains? "Y29udGVudCBvZiBpbmZvIGZpbGU="))
373379
(string-append "Expected server to receive message with text attachment, but received: " (server-message-data server)))
374380
(assert
375381
(server-message-contains-ci? "content-disposition: attachment")
376382
(string-append "Expected server to receive message with content-disposition: attachment, but received: " (server-message-data server)))))
377383

384+
(test "basic multiple text attachments" (lambda ()
385+
(sendmail-send-with-attachments
386+
'(("data" "info.txt")
387+
("file-name" "info.txt")
388+
("content-type" "text/plain"))
389+
'(("data" "info.txt")
390+
("file-name" "second-info.txt")
391+
("content-type" "text/plain")))
392+
(assert
393+
(and (server-message-contains-ci? "info.txt") (server-message-contains-ci? "second-info.txt"))
394+
(string-append "Expected server to receive message with two attachments, but received: " (server-message-data server)))))
395+
378396
(test "basic image attachment" (lambda ()
379397
(sendmail-send-with-attachments
380398
'(("data" "test.png")
@@ -388,18 +406,61 @@
388406
(server-message-contains-ci? "content-disposition: attachment")
389407
(string-append "Expected server to receive message with content-disposition: attachment, but received: " (server-message-data server)))))
390408

391-
; - Multiple attachments with the same name
392-
; - Attachment without a name
393-
; - inline vs attachment content-disposition
394-
; - inline attachment with ?cid?
395-
; - content/type multipart/mixed?
409+
(test "multiple attachments with same name" (lambda ()
410+
(sendmail-send-with-attachments
411+
'(("data" "info.txt")
412+
("file-name" "info.txt")
413+
("content-type" "text/plain"))
414+
415+
'(("data" "info.txt")
416+
("file-name" "info.txt")
417+
("content-type" "text/plain")))
418+
(assert
419+
(= 2 (length (string-contains-every? (server-message-data server) "info.txt")))
420+
(string-append "Expected server to receive message with two text attachments with the same name, but received: " (server-message-data server)))))
421+
422+
; Filename property is optional: https://datatracker.ietf.org/doc/html/rfc2183#section-1
423+
(test "attachment without a name" (lambda ()
424+
(sendmail-send-with-attachments
425+
'(("data" "info.txt")
426+
("content-type" "text/plain")))
427+
(assert
428+
(server-message-contains-ci? "content-disposition: attachment")
429+
(string-append "Expected server to receive a message with an attachment, but received: " (server-message-data server)))
430+
(assert
431+
(not (server-message-contains-ci? "info.txt"))
432+
(string-append "Expected server to receive a message with an attachment without a name, but received: " (server-message-data server)))))
433+
434+
(test "image attachment with inline disposition" (lambda ()
435+
(sendmail-send-with-attachments
436+
'(("data" "test.png")
437+
("file-name" "test.png")
438+
("content-type" "image/png")
439+
("content-disposition" "inline")))
440+
(assert
441+
(server-message-contains-ci? "content-disposition: inline")
442+
(string-append "Expected server to receive a message with an inline attachment, but received: " (server-message-data server)))))
443+
444+
(test "text attachment with inline disposition" (lambda ()
445+
(sendmail-send-with-attachments
446+
'(("data" "info.txt")
447+
("file-name" "info.txt")
448+
("content-type" "text/plain")
449+
("content-disposition" "inline")))
450+
(assert
451+
(server-message-contains-ci? "content-disposition: inline")
452+
(string-append "Expected server to receive a message with an inline attachment, but received: " (server-message-data server)))))
453+
454+
; - inline attachment with cid? https://www.rfc-editor.org/rfc/rfc2392
455+
; => non-trivial as we either need to do it completely manually or use a template engine. A template engine has
456+
; custom syntax, so we can not create a general scenario for it
396457

397458
(capability 'automatic-mime-detection (list
398-
459+
399460
))
400461

401462
(capability 'unicode-file-name (list
402-
463+
403464
))
404465

405466
))

0 commit comments

Comments
 (0)