Skip to content

Commit 10e9fff

Browse files
LawnGnomeTurbo87
authored andcommitted
email: add notification e-mail for potential typosquatting
1 parent 9105a52 commit 10e9fff

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/email.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,35 @@ or go to https://{domain}/me/pending-invites to manage all of your crate ownersh
9191
self.send(email, subject, &body)
9292
}
9393

94+
/// Attempts to send a notification that a new crate may be typosquatting another crate.
95+
pub fn send_possible_typosquat_notification(
96+
&self,
97+
email: &str,
98+
crate_name: &str,
99+
squats: &[typomania::checks::Squat],
100+
) -> AppResult<()> {
101+
let domain = crate::config::domain_name();
102+
let subject = "Possible typosquatting in new crate";
103+
let body = format!(
104+
"New crate {crate_name} may be typosquatting one or more other crates.\n
105+
Visit https://{domain}/crates/{crate_name} to see the offending crate.\n
106+
\n
107+
Specific squat checks that triggered:\n
108+
\n
109+
{squats}",
110+
squats = squats
111+
.iter()
112+
.map(|squat| format!(
113+
"- {squat} (https://{domain}/crates/{crate_name})\n",
114+
crate_name = squat.package()
115+
))
116+
.collect::<Vec<_>>()
117+
.join(""),
118+
);
119+
120+
self.send(email, subject, &body)
121+
}
122+
94123
/// Attempts to send an API token exposure notification email
95124
pub fn send_token_exposed_notification(
96125
&self,

0 commit comments

Comments
 (0)