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
No known key found for this signature in database
GPG Key ID: FC8A7D14C3CD543A
4 changed files with 1150 additions and 1146 deletions

2280
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -111,6 +111,8 @@ openssl = "0.10.26"
# URL encoding library
percent-encoding = "2.1.0"
# Punycode conversion
idna = "0.2.0"
[patch.crates-io]
# Use newest ring

View File

@ -271,7 +271,7 @@ impl EmailTokenData {
/// Takes an email address and obscures it by replacing it with asterisks except two characters.
pub fn obscure_email(email: &str) -> String {
let split: Vec<&str> = email.split('@').collect();
let split: Vec<&str> = email.rsplitn(2, '@').collect();
let mut name = split[0].to_string();
let domain = &split[1];

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"))