@@ -2,7 +2,7 @@ use crate::app::AppState;
2
2
use crate :: auth:: AuthCheck ;
3
3
use crate :: controllers:: helpers:: authorization:: Rights ;
4
4
use crate :: controllers:: krate:: CratePath ;
5
- use crate :: email:: Email ;
5
+ use crate :: email:: EmailMessage ;
6
6
use crate :: models:: NewDeletedCrate ;
7
7
use crate :: schema:: { crate_downloads, crates, dependencies} ;
8
8
use crate :: util:: errors:: { AppResult , BoxedAppError , custom} ;
@@ -18,6 +18,8 @@ use diesel_async::scoped_futures::ScopedFutureExt;
18
18
use diesel_async:: { AsyncConnection , AsyncPgConnection , RunQueryDsl } ;
19
19
use http:: StatusCode ;
20
20
use http:: request:: Parts ;
21
+ use minijinja:: context;
22
+ use tracing:: error;
21
23
22
24
const DOWNLOADS_PER_MONTH_LIMIT : u64 = 500 ;
23
25
const AVAILABLE_AFTER : TimeDelta = TimeDelta :: hours ( 24 ) ;
@@ -147,10 +149,13 @@ pub async fn delete_crate(
147
149
148
150
let email_future = async {
149
151
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
+ ) ?;
154
159
155
160
app. emails . send ( & recipient, email) . await ?
156
161
}
@@ -193,33 +198,6 @@ async fn has_rev_dep(conn: &mut AsyncPgConnection, crate_id: i32) -> QueryResult
193
198
Ok ( rev_dep. is_some ( ) )
194
199
}
195
200
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 help@crates.io." ,
218
- self . user, self . krate
219
- )
220
- }
221
- }
222
-
223
201
#[ cfg( test) ]
224
202
mod tests {
225
203
use super :: * ;
0 commit comments