aboutsummaryrefslogtreecommitdiff
path: root/crates/secd/src/client/email/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/secd/src/client/email/mod.rs')
-rw-r--r--crates/secd/src/client/email/mod.rs18
1 files changed, 12 insertions, 6 deletions
diff --git a/crates/secd/src/client/email/mod.rs b/crates/secd/src/client/email/mod.rs
index 7c7b233..9e591ba 100644
--- a/crates/secd/src/client/email/mod.rs
+++ b/crates/secd/src/client/email/mod.rs
@@ -42,7 +42,7 @@ pub enum MessengerType {
pub(crate) struct LocalMailer {}
impl LocalMailer {
- pub fn new() -> Arc<dyn EmailMessenger + Send + Sync + 'static> {
+ pub fn new_ref() -> Arc<dyn EmailMessenger + Send + Sync + 'static> {
warn!("You are using the local mailer, which will not work in production!");
Arc::new(LocalMailer {})
}
@@ -59,7 +59,7 @@ pub(crate) struct Sendgrid {
pub api_key: String,
}
impl Sendgrid {
- pub fn new(api_key: String) -> Arc<dyn EmailMessenger + Send + Sync + 'static> {
+ pub fn new_ref(api_key: String) -> Arc<dyn EmailMessenger + Send + Sync + 'static> {
Arc::new(Sendgrid { api_key })
}
}
@@ -89,7 +89,7 @@ impl Sendable for EmailValidationMessage {
.subject(self.subject.clone())
.multipart(MultiPart::alternative_plain_html(
"".to_string(),
- String::from(self.body.clone()),
+ self.body.clone(),
))?;
let mailer = lettre::SmtpTransport::unencrypted_localhost();
@@ -135,7 +135,7 @@ pub(crate) fn parse_email_template(
validation_secret: Option<String>,
validation_code: Option<String>,
) -> Result<String, EmailMessengerError> {
- let mut t = template.clone().to_string();
+ let mut t = String::from(template);
// We do not allow substutions for a variety of reasons, but mainly security ones.
// The only things we want to share are those which secd allows. In this case, that
// means we only send an email with static content as provided by the filter, except
@@ -143,8 +143,14 @@ pub(crate) fn parse_email_template(
// present in the email.
t = t.replace("{{secd::validation_id}}", &validation_id.to_string());
- validation_secret.map(|secret| t = t.replace("{{secd::validation_secret}}", &secret));
- validation_code.map(|code| t = t.replace("{{secd::validation_code}}", &code));
+
+ if let Some(secret) = validation_secret {
+ t = t.replace("{{secd::validation_secret}}", &secret);
+ }
+
+ if let Some(code) = validation_code {
+ t = t.replace("{{secd::validation_code}}", &code);
+ }
Ok(t)
}