Skip to content

Commit f285ebd

Browse files
authored
smtp: add base64 encoding to the body of the emails and use utf8, to prevent format confusion (#15589)
1 parent 72056f3 commit f285ebd

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

vlib/net/smtp/smtp.v

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,13 @@ fn (mut c Client) send_body(cfg Mail) ? {
245245
}
246246

247247
if is_html {
248-
sb.write_string('Content-Type: text/html; charset=UTF-8')
248+
sb.write_string('Content-Type: text/html; charset=UTF-8\r\n')
249249
} else {
250-
sb.write_string('Content-Type: text/plain; charset=UTF-8')
250+
sb.write_string('Content-Type: text/plain; charset=UTF-8\r\n')
251251
}
252+
sb.write_string('Content-Transfer-Encoding: base64')
252253
sb.write_string('\r\n\r\n')
253-
sb.write_string(cfg.body)
254+
sb.write_string(base64.encode_str(cfg.body))
254255
sb.write_string('\r\n.\r\n')
255256
c.send_str(sb.str())?
256257
c.expect_reply(.action_ok)?

vlib/net/smtp/smtp_test.v

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,11 @@ fn test_smtp_multiple_recipients() ? {
131131

132132
assert true
133133
}
134+
135+
fn test_smtp_body_base64encode() ? {
136+
$if !network ? {
137+
return
138+
}
139+
140+
assert true
141+
}

0 commit comments

Comments
 (0)