1
0
Fork 1
Spiegel von https://github.com/dani-garcia/vaultwarden.git synchronisiert 2024-11-22 05:10:29 +01:00

use static_files() for email attachments

Apply suggestions from code review

Co-authored-by: Mathijs van Veluw <black.dex@gmail.com>
Dieser Commit ist enthalten in:
Stefan Melmuk 2022-10-06 11:59:47 +02:00 committet von Daniel García
Ursprung 4d1b860dad
Commit 0e6f6e612a
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: FC8A7D14C3CD543A
4 geänderte Dateien mit 5 neuen und 4 gelöschten Zeilen

Datei anzeigen

@ -22,6 +22,7 @@ pub use crate::api::{
notifications::{start_notification_server, Notify, UpdateType}, notifications::{start_notification_server, Notify, UpdateType},
web::catchers as web_catchers, web::catchers as web_catchers,
web::routes as web_routes, web::routes as web_routes,
web::static_files,
}; };
use crate::util; use crate::util;

Datei anzeigen

@ -89,7 +89,7 @@ fn alive(_conn: DbConn) -> Json<String> {
} }
#[get("/vw_static/<filename>")] #[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() { match filename.as_ref() {
"mail-github.png" => Ok((ContentType::PNG, include_bytes!("../static/images/mail-github.png"))), "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"))), "logo-gray.png" => Ok((ContentType::PNG, include_bytes!("../static/images/logo-gray.png"))),

Datei anzeigen

@ -767,7 +767,7 @@ fn generate_smtp_img_src(embed_images: bool, domain: &str) -> String {
if embed_images { if embed_images {
"cid:".to_string() "cid:".to_string()
} else { } else {
format!("{}/vw_static/", domain) format!("{domain}/vw_static/")
} }
} }

Datei anzeigen

@ -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 { 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 smtp_from = &CONFIG.smtp_from();
let body = if CONFIG.smtp_embed_images() { 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::alternative().singlepart(SinglePart::plain(body_text)).multipart(
MultiPart::related() MultiPart::related()
.singlepart(SinglePart::html(body_html)) .singlepart(SinglePart::html(body_html))