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:
parent
1cf683d482
commit
c2b763655d
@ -228,13 +228,20 @@ fn (mut c Client) send_data() ? {
|
||||
fn (mut c Client) send_body(cfg Mail) ? {
|
||||
is_html := cfg.body_type == .html
|
||||
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)
|
||||
sb.write_string('From: $cfg.from\r\n')
|
||||
sb.write_string('To: <$cfg.to>\r\n')
|
||||
sb.write_string('Cc: <$cfg.cc>\r\n')
|
||||
sb.write_string('Bcc: <$cfg.bcc>\r\n')
|
||||
sb.write_string('Date: $date\r\n')
|
||||
sb.write_string('Subject: $cfg.subject\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')
|
||||
}
|
||||
|
||||
if is_html {
|
||||
sb.write_string('Content-Type: text/html; charset=UTF-8')
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user