From f285ebd91c8d2e506d3954eade2b4b4ca6302159 Mon Sep 17 00:00:00 2001 From: shove Date: Mon, 29 Aug 2022 14:19:46 +0800 Subject: [PATCH] smtp: add base64 encoding to the body of the emails and use utf8, to prevent format confusion (#15589) --- vlib/net/smtp/smtp.v | 7 ++++--- vlib/net/smtp/smtp_test.v | 8 ++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/vlib/net/smtp/smtp.v b/vlib/net/smtp/smtp.v index cd0974885..57f1ab68b 100644 --- a/vlib/net/smtp/smtp.v +++ b/vlib/net/smtp/smtp.v @@ -245,12 +245,13 @@ fn (mut c Client) send_body(cfg Mail) ? { } if is_html { - sb.write_string('Content-Type: text/html; charset=UTF-8') + sb.write_string('Content-Type: text/html; charset=UTF-8\r\n') } else { - sb.write_string('Content-Type: text/plain; charset=UTF-8') + sb.write_string('Content-Type: text/plain; charset=UTF-8\r\n') } + sb.write_string('Content-Transfer-Encoding: base64') sb.write_string('\r\n\r\n') - sb.write_string(cfg.body) + sb.write_string(base64.encode_str(cfg.body)) sb.write_string('\r\n.\r\n') c.send_str(sb.str())? c.expect_reply(.action_ok)? diff --git a/vlib/net/smtp/smtp_test.v b/vlib/net/smtp/smtp_test.v index 3002e32e7..c8f6cf7ea 100644 --- a/vlib/net/smtp/smtp_test.v +++ b/vlib/net/smtp/smtp_test.v @@ -131,3 +131,11 @@ fn test_smtp_multiple_recipients() ? { assert true } + +fn test_smtp_body_base64encode() ? { + $if !network ? { + return + } + + assert true +} -- 2.30.2