mirror of
https://github.com/dani-garcia/vaultwarden.git
synced 2025-09-10 18:55:57 +03:00
Merge branch 'master' of github.com:dani-garcia/bitwarden_rs into 2fa_enforcement
# Conflicts: # src/db/models/org_policy.rs # src/db/models/organization.rs
This commit is contained in:
26
src/mail.rs
26
src/mail.rs
@@ -1,4 +1,4 @@
|
||||
use std::{str::FromStr};
|
||||
use std::str::FromStr;
|
||||
|
||||
use chrono::{DateTime, Local};
|
||||
use percent_encoding::{percent_encode, NON_ALPHANUMERIC};
|
||||
@@ -62,11 +62,13 @@ fn mailer() -> SmtpTransport {
|
||||
let mut selected_mechanisms = vec![];
|
||||
for wanted_mechanism in mechanism.split(',') {
|
||||
for m in &allowed_mechanisms {
|
||||
if m.to_string().to_lowercase() == wanted_mechanism.trim_matches(|c| c == '"' || c == '\'' || c == ' ').to_lowercase() {
|
||||
if m.to_string().to_lowercase()
|
||||
== wanted_mechanism.trim_matches(|c| c == '"' || c == '\'' || c == ' ').to_lowercase()
|
||||
{
|
||||
selected_mechanisms.push(*m);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if !selected_mechanisms.is_empty() {
|
||||
smtp_client.authentication(selected_mechanisms)
|
||||
@@ -332,31 +334,23 @@ fn send_email(address: &str, subject: &str, body_html: String, body_text: String
|
||||
|
||||
let smtp_from = &CONFIG.smtp_from();
|
||||
let email = Message::builder()
|
||||
.message_id(Some(format!("<{}@{}>", crate::util::get_uuid(), smtp_from.split('@').collect::<Vec<&str>>()[1] )))
|
||||
.message_id(Some(format!("<{}@{}>", crate::util::get_uuid(), smtp_from.split('@').collect::<Vec<&str>>()[1])))
|
||||
.to(Mailbox::new(None, Address::from_str(&address)?))
|
||||
.from(Mailbox::new(
|
||||
Some(CONFIG.smtp_from_name()),
|
||||
Address::from_str(smtp_from)?,
|
||||
))
|
||||
.from(Mailbox::new(Some(CONFIG.smtp_from_name()), Address::from_str(smtp_from)?))
|
||||
.subject(subject)
|
||||
.multipart(
|
||||
MultiPart::alternative()
|
||||
.singlepart(text)
|
||||
.singlepart(html)
|
||||
)?;
|
||||
.multipart(MultiPart::alternative().singlepart(text).singlepart(html))?;
|
||||
|
||||
match mailer().send(&email) {
|
||||
Ok(_) => Ok(()),
|
||||
// Match some common errors and make them more user friendly
|
||||
Err(e) => {
|
||||
|
||||
if e.is_client() {
|
||||
err!(format!("SMTP Client error: {}", e));
|
||||
err!(format!("SMTP Client error: {}", e));
|
||||
} else if e.is_transient() {
|
||||
err!(format!("SMTP 4xx error: {:?}", e));
|
||||
} else if e.is_permanent() {
|
||||
err!(format!("SMTP 5xx error: {:?}", e));
|
||||
} else if e.is_timeout() {
|
||||
} else if e.is_timeout() {
|
||||
err!(format!("SMTP timeout error: {:?}", e));
|
||||
} else {
|
||||
Err(e.into())
|
||||
|
Reference in New Issue
Block a user