Preserving binary data as bytevectors in mime parsing.

This commit is contained in:
Alex Shinn 2014-03-21 21:53:02 +09:00
parent 8a8e856ee6
commit 31aaaef062
2 changed files with 23 additions and 13 deletions

View file

@ -234,21 +234,29 @@
(else
(lp (cons line res))))))))
(define (mime-convert-part str cte enc)
(let ((str (cond
(define (mime-convert-part str text? cte enc)
(let ((res (cond
((and (string? cte) (string-ci=? cte "quoted-printable"))
(quoted-printable-decode-string str))
(if text?
(quoted-printable-decode-string str)
(quoted-printable-decode-bytevector (string->utf8 str))))
((and (string? cte) (string-ci=? cte "base64"))
(base64-decode-string str))
(if text?
(base64-decode-string str)
(base64-decode-bytevector (string->utf8 str))))
(text?
str)
(else
str))))
(if (string? enc) (ces-convert str enc) str)))
(string->utf8 str)))))
(if (string? res) (ces-convert res enc) res)))
(define (mime-read-part port cte enc boundary next final)
(mime-read-to-boundary
port boundary
(lambda (x) (next (mime-convert-part x cte enc)))
(lambda (x) (final (mime-convert-part x cte enc)))))
(define (mime-read-part port type cte enc boundary next final)
(let ((text? (and (symbol? type)
(string-prefix? "text/" (symbol->string type)))))
(mime-read-to-boundary
port boundary
(lambda (x) (next (mime-convert-part x text? cte enc)))
(lambda (x) (final (mime-convert-part x text? cte enc))))))
;;> \section{RFC2045 MIME Encoding}
@ -335,7 +343,7 @@
(next (kons-up headers seed x)))))))))
(else
(mime-read-part
port cte enc boundary
port type cte enc boundary
(lambda (x) (next (kons parent-headers headers x seed)))
(lambda (x) (final (kons parent-headers headers x seed)))))))))))

View file

@ -65,7 +65,9 @@ Content-Type: text/plain
. "attachment; filename=\"file2.gif\"")
(content-type . "image/gif")
(content-transfer-encoding . "binary"))
" ...contents of file2.gif...")))
#u8(32 32 46 46 46 99 111 110 116 101 110
116 115 32 111 102 32 102 105 108 101
50 46 103 105 102 46 46 46))))
(call-with-input-string
"Content-type: multipart/form-data, boundary=AaB03x