mirror of
https://github.com/ViViDboarder/bitwarden_rs.git
synced 2024-12-22 19:47:45 +00:00
Convert email domains to punycode
This commit is contained in:
parent
2798f623d4
commit
def174a517
2280
Cargo.lock
generated
2280
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];
|
||||
|
12
src/mail.rs
12
src/mail.rs
@ -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…
Reference in New Issue
Block a user