aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStefan Melmuk <[email protected]>2022-10-06 11:59:47 +0200
committerDaniel GarcĂ­a <[email protected]>2022-10-19 20:39:13 +0200
commit0e6f6e612ab22c975ea9cbedaac17c403e691ee7 (patch)
treeddd57f8fe3341bda267e2ea2fe04d05df3619a1e /src
parent4d1b860dada9bf56d71aa8beea87419fb0e087d3 (diff)
downloadvaultwarden-0e6f6e612ab22c975ea9cbedaac17c403e691ee7.tar.gz
vaultwarden-0e6f6e612ab22c975ea9cbedaac17c403e691ee7.zip
use static_files() for email attachments
Apply suggestions from code review Co-authored-by: Mathijs van Veluw <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/api/mod.rs1
-rw-r--r--src/api/web.rs2
-rw-r--r--src/config.rs2
-rw-r--r--src/mail.rs4
4 files changed, 5 insertions, 4 deletions
diff --git a/src/api/mod.rs b/src/api/mod.rs
index b9e9f38c..7bff978b 100644
--- a/src/api/mod.rs
+++ b/src/api/mod.rs
@@ -22,6 +22,7 @@ pub use crate::api::{
notifications::{start_notification_server, Notify, UpdateType},
web::catchers as web_catchers,
web::routes as web_routes,
+ web::static_files,
};
use crate::util;
diff --git a/src/api/web.rs b/src/api/web.rs
index 2ad94db8..cfc4b9e0 100644
--- a/src/api/web.rs
+++ b/src/api/web.rs
@@ -89,7 +89,7 @@ fn alive(_conn: DbConn) -> Json<String> {
}
#[get("/vw_static/<filename>")]
-fn static_files(filename: String) -> Result<(ContentType, &'static [u8]), Error> {
+pub fn static_files(filename: String) -> Result<(ContentType, &'static [u8]), Error> {
match filename.as_ref() {
"mail-github.png" => Ok((ContentType::PNG, include_bytes!("../static/images/mail-github.png"))),
"logo-gray.png" => Ok((ContentType::PNG, include_bytes!("../static/images/logo-gray.png"))),
diff --git a/src/config.rs b/src/config.rs
index 4cac70eb..936f15df 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -767,7 +767,7 @@ fn generate_smtp_img_src(embed_images: bool, domain: &str) -> String {
if embed_images {
"cid:".to_string()
} else {
- format!("{}/vw_static/", domain)
+ format!("{domain}/vw_static/")
}
}
diff --git a/src/mail.rs b/src/mail.rs
index e613da6f..fce76e17 100644
--- a/src/mail.rs
+++ b/src/mail.rs
@@ -496,11 +496,11 @@ pub async fn send_test(address: &str) -> EmptyResult {
}
async fn send_email(address: &str, subject: &str, body_html: String, body_text: String) -> EmptyResult {
- let logo_gray_body = Body::new(include_bytes!("static/images/logo-gray.png").to_vec());
- let mail_github_body = Body::new(include_bytes!("static/images/mail-github.png").to_vec());
let smtp_from = &CONFIG.smtp_from();
let body = if CONFIG.smtp_embed_images() {
+ let logo_gray_body = Body::new(crate::api::static_files("logo-gray.png".to_string()).unwrap().1.to_vec());
+ let mail_github_body = Body::new(crate::api::static_files("mail-github.png".to_string()).unwrap().1.to_vec());
MultiPart::alternative().singlepart(SinglePart::plain(body_text)).multipart(
MultiPart::related()
.singlepart(SinglePart::html(body_html))