1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

net.smtp: handle UTF-8 subjects according to RFC 1342 (#14410)

This commit is contained in:
WoodyAtHome 2022-05-16 10:09:36 +02:00 committed by GitHub
parent 1cf683d482
commit c2b763655d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -228,13 +228,20 @@ fn (mut c Client) send_data() ? {
fn (mut c Client) send_body(cfg Mail) ? { fn (mut c Client) send_body(cfg Mail) ? {
is_html := cfg.body_type == .html is_html := cfg.body_type == .html
date := cfg.date.custom_format('ddd, D MMM YYYY HH:mm ZZ') date := cfg.date.custom_format('ddd, D MMM YYYY HH:mm ZZ')
nonascii_subject := cfg.subject.bytes().any(it < u8(` `) || it > u8(`~`))
mut sb := strings.new_builder(200) mut sb := strings.new_builder(200)
sb.write_string('From: $cfg.from\r\n') sb.write_string('From: $cfg.from\r\n')
sb.write_string('To: <$cfg.to>\r\n') sb.write_string('To: <$cfg.to>\r\n')
sb.write_string('Cc: <$cfg.cc>\r\n') sb.write_string('Cc: <$cfg.cc>\r\n')
sb.write_string('Bcc: <$cfg.bcc>\r\n') sb.write_string('Bcc: <$cfg.bcc>\r\n')
sb.write_string('Date: $date\r\n') sb.write_string('Date: $date\r\n')
if nonascii_subject {
// handle UTF-8 subjects according RFC 1342
sb.write_string('Subject: =?utf-8?B?' + base64.encode_str(cfg.subject) + '?=\r\n')
} else {
sb.write_string('Subject: $cfg.subject\r\n') sb.write_string('Subject: $cfg.subject\r\n')
}
if is_html { if is_html {
sb.write_string('Content-Type: text/html; charset=UTF-8') sb.write_string('Content-Type: text/html; charset=UTF-8')
} else { } else {