Send exactly one email when requesting deletion.

- Fixes #61.
This commit is contained in:
Justus Winter 2019-03-05 14:09:23 +01:00
parent abcaa95627
commit 2ee7526171
No known key found for this signature in database
GPG Key ID: 686F55B4AB2B3386
2 changed files with 16 additions and 12 deletions

View File

@ -57,14 +57,15 @@ impl Service {
};
self.send(
userid,
&vec![userid.clone()],
"Please verify your email address",
"verify",
ctx,
)
}
pub fn send_confirmation(&self, userid: &Email, token: &str, domain: &str)
pub fn send_confirmation(&self, userids: &[Email], token: &str,
domain: &str)
-> Result<()> {
let ctx = Context {
token: token.to_string(),
@ -73,14 +74,14 @@ impl Service {
};
self.send(
userid,
userids,
"Please confirm deletion of your key",
"confirm",
ctx,
)
}
fn send<T>(&self, to: &Email, subject: &str, template: &str, ctx: T)
fn send<T>(&self, to: &[Email], subject: &str, template: &str, ctx: T)
-> Result<()>
where T: Serialize + Clone,
{
@ -97,14 +98,19 @@ impl Service {
}
};
let email = EmailBuilder::new()
.to(to.to_string())
let mut email = EmailBuilder::new()
.from(self.from.clone())
.subject(subject)
.alternative(
html.ok_or(failure::err_msg("Email template failed to render"))?,
txt.ok_or(failure::err_msg("Email template failed to render"))?,
)
);
for recipient in to.iter() {
email.add_to(recipient.to_string());
}
let email = email
.build()
.unwrap();

View File

@ -498,11 +498,9 @@ fn manage_post(
commit: env!("VERGEN_SHA_SHORT").to_string(),
};
for uid in uids {
if let Err(e) = mail_service.send_confirmation(
&uid, &token, &domain.0) {
return MyResponse::ise(e);
}
if let Err(e) = mail_service.send_confirmation(
&uids, &token, &domain.0) {
return MyResponse::ise(e);
}
MyResponse::ok("delete", context)