Convert email domains to punycode

This commit is contained in:
Daniel García
2020-01-30 22:11:53 +01:00
parent 2798f623d4
commit def174a517
4 changed files with 1150 additions and 1146 deletions

View File

@@ -259,6 +259,18 @@ pub fn send_change_email(address: &str, token: &str) -> EmptyResult {
}
fn send_email(address: &str, subject: &str, body_html: &str, body_text: &str) -> EmptyResult {
let address_split: Vec<&str> = address.rsplitn(2, '@').collect();
if address_split.len() != 2 {
err!("Invalid email address (no @)");
}
let domain_puny = match idna::domain_to_ascii_strict(address_split[1]) {
Ok(d) => d,
Err(_) => err!("Can't convert email domain to ASCII representation"),
};
let address = format!("{}@{}", address_split[0], domain_puny);
let html = PartBuilder::new()
.body(encode_to_str(body_html))
.header(("Content-Type", "text/html; charset=utf-8"))