Skip to content

Commit 6d4c9e1

Browse files
authored
censor new email address in email change emails (#8239)
1 parent b7b7dfd commit 6d4c9e1

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

‎apps/labrinth/src/queue/email/templates.rs‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ async fn collect_template_variables(
739739
new_email,
740740
to_email: _,
741741
} => {
742-
map.insert(EMAILCHANGED_NEW_EMAIL, new_email.clone());
742+
map.insert(EMAILCHANGED_NEW_EMAIL, censor_email_address(new_email));
743743

744744
Ok(EmailTemplate::Static(map))
745745
}
@@ -939,6 +939,23 @@ async fn dynamic_email_body(
939939
.await
940940
}
941941

942+
fn censor_email_address(email: &str) -> String {
943+
const MASK: &str = "***";
944+
945+
let Some((local, domain)) = email.rsplit_once('@') else {
946+
return mask_local_part(email, MASK);
947+
};
948+
949+
format!("{}@{domain}", mask_local_part(local, MASK))
950+
}
951+
952+
fn mask_local_part(local: &str, mask: &str) -> String {
953+
match local.chars().next() {
954+
Some(first) => format!("{first}{mask}"),
955+
None => mask.to_string(),
956+
}
957+
}
958+
942959
fn date_human_readable(date: chrono::DateTime<chrono::Utc>) -> String {
943960
date.format("%B %d, %Y").to_string()
944961
}

0 commit comments

Comments
 (0)