diff --git a/lib/chibi/mime.scm b/lib/chibi/mime.scm index 5dd1a8a3..9649fe81 100644 --- a/lib/chibi/mime.scm +++ b/lib/chibi/mime.scm @@ -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))))))))))) diff --git a/tests/mime-tests.scm b/tests/mime-tests.scm index 4edcad69..400eab38 100644 --- a/tests/mime-tests.scm +++ b/tests/mime-tests.scm @@ -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