Skip to content

Commit 8e05edd

Browse files
committed
email: Remove sync send() fn
1 parent 1dc63f8 commit 8e05edd

File tree

11 files changed

+14
-23
lines changed

11 files changed

+14
-23
lines changed

src/controllers/github/secret_scanning.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ async fn send_notification_email(
199199
url: &alert.url,
200200
};
201201

202-
state.emails.async_send(&recipient, email).await?;
202+
state.emails.send(&recipient, email).await?;
203203

204204
Ok(())
205205
}

src/controllers/krate/owners.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ async fn modify_owners(
243243
for email in emails {
244244
let addr = email.recipient_email_address().to_string();
245245

246-
if let Err(e) = app.emails.async_send(&addr, email).await {
246+
if let Err(e) = app.emails.send(&addr, email).await {
247247
warn!("Failed to send co-owner invite email: {e}");
248248
}
249249
}

src/controllers/token.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ pub async fn new(
154154
// At this point the token has been created so failing to send the
155155
// email should not cause an error response to be returned to the
156156
// caller.
157-
let email_ret = app.emails.async_send(&recipient, email).await;
157+
let email_ret = app.emails.send(&recipient, email).await;
158158
if let Err(e) = email_ret {
159159
error!("Failed to send token creation email: {e}")
160160
}

src/controllers/user/resend.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub async fn regenerate_token_and_send(
4545

4646
state
4747
.emails
48-
.async_send(&email.email, email1)
48+
.send(&email.email, email1)
4949
.await
5050
.map_err(BoxedAppError::from)
5151
}

src/controllers/user/update.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub async fn update_user(
5858
domain: &state.emails.domain,
5959
};
6060

61-
if let Err(error) = state.emails.async_send(&email_address, email).await {
61+
if let Err(error) = state.emails.send(&email_address, email).await {
6262
warn!("Failed to send publish notifications unsubscribe email to {email_address}: {error}");
6363
}
6464
}
@@ -103,7 +103,7 @@ pub async fn update_user(
103103
token,
104104
};
105105

106-
let _ = state.emails.async_send(user_email, email).await;
106+
let _ = state.emails.send(user_email, email).await;
107107
}
108108

109109
ok_true()

src/email.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use lettre::transport::stub::AsyncStubTransport;
1010
use lettre::{Address, AsyncTransport, Message, Tokio1Executor};
1111
use rand::distributions::{Alphanumeric, DistString};
1212
use std::sync::Arc;
13-
use tokio::runtime::Handle;
1413

1514
pub trait Email {
1615
fn subject(&self) -> String;
@@ -115,15 +114,7 @@ impl Emails {
115114
Ok(message)
116115
}
117116

118-
pub fn send<E: Email>(&self, recipient: &str, email: E) -> Result<(), EmailError> {
119-
let email = self.build_message(recipient, email)?;
120-
121-
Handle::current()
122-
.block_on(self.backend.send(email))
123-
.map_err(EmailError::TransportError)
124-
}
125-
126-
pub async fn async_send<E: Email>(&self, recipient: &str, email: E) -> Result<(), EmailError> {
117+
pub async fn send<E: Email>(&self, recipient: &str, email: E) -> Result<(), EmailError> {
127118
let email = self.build_message(recipient, email)?;
128119

129120
self.backend
@@ -195,14 +186,14 @@ mod tests {
195186
let emails = Emails::new_in_memory();
196187

197188
let address = "String.Format(\"{0}.{1}@live.com\", FirstName, LastName)";
198-
assert_err!(emails.async_send(address, TestEmail).await);
189+
assert_err!(emails.send(address, TestEmail).await);
199190
}
200191

201192
#[tokio::test]
202193
async fn sending_to_valid_email_succeeds() {
203194
let emails = Emails::new_in_memory();
204195

205196
let address = "[email protected]";
206-
assert_ok!(emails.async_send(address, TestEmail).await);
197+
assert_ok!(emails.send(address, TestEmail).await);
207198
}
208199
}

src/models/user.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ impl<'a> NewUser<'a> {
192192
domain: &emails.domain,
193193
token,
194194
};
195-
let _ = emails.async_send(user_email, email).await;
195+
let _ = emails.send(user_email, email).await;
196196
}
197197
}
198198

src/worker/jobs/expiry_notification.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ async fn handle_expiring_token(
8484
token_name: &token.name,
8585
expiry_date: token.expired_at.unwrap().and_utc(),
8686
};
87-
emails.async_send(&recipient, email).await?;
87+
emails.send(&recipient, email).await?;
8888
} else {
8989
info!(
9090
"User {} has no email address set. Skipping expiry notification.",

src/worker/jobs/send_publish_notifications.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl BackgroundJob for SendPublishNotificationsJob {
9595
};
9696

9797
debug!("Sending publish notification for {krate}@{version} to {email_address}…");
98-
let result = ctx.emails.async_send(&email_address, email).await.inspect_err(|err| {
98+
let result = ctx.emails.send(&email_address, email).await.inspect_err(|err| {
9999
warn!("Failed to send publish notification for {krate}@{version} to {email_address}: {err}")
100100
});
101101

src/worker/jobs/sync_admins.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ impl BackgroundJob for SyncAdmins {
144144
for database_admin in &database_admins {
145145
let (_, _, email_address) = database_admin;
146146
if let Some(email_address) = email_address {
147-
if let Err(error) = ctx.emails.async_send(email_address, email.clone()).await {
147+
if let Err(error) = ctx.emails.send(email_address, email.clone()).await {
148148
warn!(
149149
"Failed to send email to admin {} ({}, github_id: {}): {}",
150150
database_admin.1, email_address, database_admin.0, error

0 commit comments

Comments
 (0)