Skip to content

Commit 9330a7b

Browse files
committed
handle non-string content in mime_multipart()
1 parent f003ea2 commit 9330a7b

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/mime.jl

+10-3
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,24 @@ function mime_multipart(header::AbstractString, parts::Array)
5353
for (filename, content_type, content) in parts
5454

5555
if filename != ""
56-
mime *= "Content-Disposition: attachment; filename=$filename\n"
56+
mime *= "Content-Disposition: attachment;\n filename=$filename\n"
57+
end
58+
59+
if isa(content, AbstractString)
60+
mime *= "Content-Transfer-Encoding: binary\n"
61+
else
62+
mime *= "Content-Transfer-Encoding: base64\n"
63+
b64 = base64encode(content)
64+
b64 = [b64[i:min(length(b64),i+75)] for i in 1:76:length(b64)]
65+
content = join(b64, "\n")
5766
end
5867

5968
mime *= """Content-Type: $content_type
60-
Content-Transfer-Encoding: binary
6169
6270
$content
6371
--$boundary
6472
"""
6573
end
66-
6774
return mime
6875
end
6976

0 commit comments

Comments
 (0)