@@ -2,7 +2,7 @@ use crate::app::AppState;
22use crate :: auth:: AuthCheck ;
33use crate :: controllers:: helpers:: authorization:: Rights ;
44use crate :: controllers:: krate:: CratePath ;
5- use crate :: email:: Email ;
5+ use crate :: email:: EmailMessage ;
66use crate :: models:: NewDeletedCrate ;
77use crate :: schema:: { crate_downloads, crates, dependencies} ;
88use crate :: util:: errors:: { AppResult , BoxedAppError , custom} ;
@@ -18,6 +18,8 @@ use diesel_async::scoped_futures::ScopedFutureExt;
1818use diesel_async:: { AsyncConnection , AsyncPgConnection , RunQueryDsl } ;
1919use http:: StatusCode ;
2020use http:: request:: Parts ;
21+ use minijinja:: context;
22+ use tracing:: error;
2123
2224const DOWNLOADS_PER_MONTH_LIMIT : u64 = 500 ;
2325const AVAILABLE_AFTER : TimeDelta = TimeDelta :: hours ( 24 ) ;
@@ -147,10 +149,13 @@ pub async fn delete_crate(
147149
148150 let email_future = async {
149151 if let Some ( recipient) = user. email ( & mut conn) . await ? {
150- let email = CrateDeletionEmail {
151- user : & user. gh_login ,
152- krate : & crate_name,
153- } ;
152+ let email = EmailMessage :: from_template (
153+ "crate_deletion" ,
154+ context ! {
155+ user => user. gh_login,
156+ krate => crate_name
157+ } ,
158+ ) ?;
154159
155160 app. emails . send ( & recipient, email) . await ?
156161 }
@@ -193,33 +198,6 @@ async fn has_rev_dep(conn: &mut AsyncPgConnection, crate_id: i32) -> QueryResult
193198 Ok ( rev_dep. is_some ( ) )
194199}
195200
196- /// Email template for notifying a crate owner about a crate being deleted.
197- ///
198- /// The owner usually should be aware of the deletion since they initiated it,
199- /// but this email can be helpful in detecting malicious account activity.
200- #[ derive( Debug , Clone ) ]
201- struct CrateDeletionEmail < ' a > {
202- user : & ' a str ,
203- krate : & ' a str ,
204- }
205-
206- impl Email for CrateDeletionEmail < ' _ > {
207- fn subject ( & self ) -> String {
208- format ! ( "crates.io: Deleted \" {}\" crate" , self . krate)
209- }
210-
211- fn body ( & self ) -> String {
212- format ! (
213- "Hi {},
214-
215- Your \" {}\" crate has been deleted, per your request.
216-
217- If you did not initiate this deletion, your account may have been compromised. Please contact us at [email protected] ." , 218- self . user, self . krate
219- )
220- }
221- }
222-
223201#[ cfg( test) ]
224202mod tests {
225203 use super :: * ;
0 commit comments