Convert email domains to punycode

pull/866/head
Daniel García 5 years ago
parent 2798f623d4
commit def174a517
No known key found for this signature in database
GPG Key ID: FC8A7D14C3CD543A

2286
Cargo.lock generated

File diff suppressed because it is too large Load Diff

@ -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

@ -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];

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

Loading…
Cancel
Save