|
5 | 5 | ; indepdenent of whether this is done with an API from the tested library directly or by using |
6 | 6 | ; another library, e.g. a MIME library from the standard library. |
7 | 7 | (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") |
10 | 9 | '("SMTP RFC 2821" "IETF" "https://tools.ietf.org/html/rfc2821") |
11 | 10 | '("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")) |
13 | 12 |
|
14 | 13 | (list |
15 | 14 | ; Socket |
|
353 | 352 | ; attachments-properties is a list of alists with the following keys: |
354 | 353 | ; "data", "file-name", "content-type", or "content-disposition" |
355 | 354 | (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 | + '() '())))) |
363 | 369 |
|
364 | | - (test "basic text attachment" (lambda () |
| 370 | + (test "basic single text attachment" (lambda () |
365 | 371 | (sendmail-send-with-attachments |
366 | 372 | '(("data" "info.txt") |
367 | 373 | ("file-name" "info.txt") |
368 | 374 | ("content-type" "text/plain"))) |
369 | 375 | (assert |
370 | 376 | (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=")) |
373 | 379 | (string-append "Expected server to receive message with text attachment, but received: " (server-message-data server))) |
374 | 380 | (assert |
375 | 381 | (server-message-contains-ci? "content-disposition: attachment") |
376 | 382 | (string-append "Expected server to receive message with content-disposition: attachment, but received: " (server-message-data server))))) |
377 | 383 |
|
| 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 | + |
378 | 396 | (test "basic image attachment" (lambda () |
379 | 397 | (sendmail-send-with-attachments |
380 | 398 | '(("data" "test.png") |
|
388 | 406 | (server-message-contains-ci? "content-disposition: attachment") |
389 | 407 | (string-append "Expected server to receive message with content-disposition: attachment, but received: " (server-message-data server))))) |
390 | 408 |
|
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 |
396 | 457 |
|
397 | 458 | (capability 'automatic-mime-detection (list |
398 | | - |
| 459 | + |
399 | 460 | )) |
400 | 461 |
|
401 | 462 | (capability 'unicode-file-name (list |
402 | | - |
| 463 | + |
403 | 464 | )) |
404 | 465 |
|
405 | 466 | )) |
|
0 commit comments