|
33 | 33 | (sendmail-send-message-full connection message-content from to-list '() '() (make-hash-table) (make-hash-table) message-options to-list-options)) |
34 | 34 | (define (sendmail-send-message connection content from to-list) |
35 | 35 | (sendmail-send-message-with-options connection content from to-list '() '())) |
36 | | - (define (sendmail-send-message-with-headers connection content from to-list headers-hash-map) |
37 | | - (sendmail-send-message-full connection content from to-list '() '() headers-hash-map (make-hash-table) '() '())) |
38 | 36 |
|
39 | 37 | ; Response accessors |
40 | 38 | (placeholder '(send-success? response) "Return whether the sending was successful.") |
|
275 | 273 | (sendmail-disconnect smtp-connection) |
276 | 274 | (set! smtp-connection '()))) |
277 | 275 |
|
| 276 | + (define (sendmail-send-with-headers headers) |
| 277 | + (sendmail-send-message-full |
| 278 | + smtp-connection "message content" "sender@sender.to" '("user@recipient.to") '() '() (alist->hash-table headers) (make-hash-table) '() '())) |
| 279 | + |
278 | 280 | (test "set basic header" (lambda () |
279 | | - (sendmail-send-message-with-headers smtp-connection "message content" "sender@sender.to" '("user@recipient.to") (alist->hash-table '(("x-my-header" "some value")))) |
| 281 | + (sendmail-send-with-headers '(("x-my-header" "some value"))) |
280 | 282 | (assert (server-message-contains? "x-my-header: some value") (string-append "Expected x-my-header to be present, but instead got " (server-message-data server))))) |
281 | 283 |
|
282 | 284 | (test "set header with unicode value" (lambda () |
283 | | - (sendmail-send-message-with-headers smtp-connection "message content" "sender@sender.to" '("user@recipient.to") (alist->hash-table '(("x-my-header" "¡some value")))) |
| 285 | + (sendmail-send-with-headers '(("x-my-header" "¡some value"))) |
284 | 286 | (assert |
285 | 287 | (server-message-contains-ci? "x-my-header: =?utf-8?q?=C2=A1some?= value") |
286 | 288 | (string-append "Expected x-my-header to contain encoded ¡, but instead got " (server-message-data server))) |
|
289 | 291 | (string-append "Expected message content to be unaltered by unicode header value, but instead got" (server-message-data server))))) |
290 | 292 |
|
291 | 293 | (test "set override standard header" (lambda () |
292 | | - (sendmail-send-message-with-headers smtp-connection "message content" "sender@sender.to" '("user@recipient.to") (alist->hash-table '(("To" "another-user@recipient.to")))) |
| 294 | + (sendmail-send-with-headers '(("To" "another-user@recipient.to"))) |
293 | 295 | (assert (server-message-contains? "To: another-user@recipient.to") (string-append "Expected To header field to include another-user..., but instead got " (server-message-data server))))) |
294 | 296 |
|
295 | 297 | (capability 'crlf-injection (list |
|
300 | 302 | '(("1some\rvalue") ("2some\nvalue") ("3some\r\nvalue")) |
301 | 303 | (lambda (header-value) |
302 | 304 | (let |
303 | | - ((responses (sendmail-send-message-with-headers smtp-connection "message content" "sender@sender.to" '("user@recipient.to") (alist->hash-table (list (list "x-my-header" header-value)))))) |
| 305 | + ((responses (sendmail-send-with-headers (list (list "x-my-header" header-value))))) |
304 | 306 | (assert (all? send-error? responses) (string-append "The header value: " header-value " should have resulted in error but did not:" responses))))) |
305 | 307 |
|
306 | 308 | (data-test "CRLF detection in unicode header value" |
307 | 309 | '(("1¡some\rvalue") ("2¡some\nvalue") ("3¡some\r\nvalue")) |
308 | 310 | (lambda (header-value) |
309 | 311 | (let |
310 | | - ((responses (sendmail-send-message-with-headers smtp-connection "message content" "sender@sender.to" '("user@recipient.to") (alist->hash-table (list (list "x-my-header" header-value)))))) |
| 312 | + ((responses (sendmail-send-with-headers (list (list "x-my-header" header-value))))) |
311 | 313 | (assert (all? send-error? responses) (string-append "The header value: " header-value " should have resulted in error but did not:" responses))))) |
312 | 314 |
|
313 | 315 | )) |
|
318 | 320 | '(("1some\rvalue") ("2some\nvalue") ("3some\r\nvalue")) |
319 | 321 | (lambda (header-value) |
320 | 322 | (let |
321 | | - ((responses (sendmail-send-message-with-headers smtp-connection "message content" "sender@sender.to" '("user@recipient.to") (alist->hash-table (list (list "x-my-header" header-value)))))) |
| 323 | + ((responses (sendmail-send-with-headers (list (list "x-my-header" header-value))))) |
322 | 324 | (assert (all? send-success? responses) (string-append "Message was not sent successfully, instead got: " responses)) |
323 | 325 | (assert (not (server-message-contains? header-value)) (string-append "The header value: " header-value " should have been stripped of CRLF but did not:" (server-message-data server)))))) |
324 | 326 |
|
325 | 327 | (data-test "CRLF mitigation in unicode header value" |
326 | 328 | '(("1¡some \rvalue" "\rvalue") ("2¡some \nvalue" "\nvalue") ("3¡some \r\nvalue" "\r\nvalue")) |
327 | 329 | (lambda (header-value fragment) |
328 | 330 | (let |
329 | | - ((responses (sendmail-send-message-with-headers smtp-connection "message content" "sender@sender.to" '("user@recipient.to") (alist->hash-table (list (list "x-my-header" header-value)))))) |
| 331 | + ((responses (sendmail-send-with-headers (list (list "x-my-header" header-value))))) |
330 | 332 | (assert (all? send-success? responses) (string-append "Message was not sent successfully, instead got: " responses)) |
331 | 333 | (assert (not (server-message-contains? fragment)) (string-append "The header value: " header-value " should have been stripped of CRLF but did not: " (server-message-data server)))))) |
332 | 334 |
|
|
0 commit comments