1
0
Fork 1
Spiegel von https://github.com/dani-garcia/vaultwarden.git synchronisiert 2024-11-06 02:38:00 +01:00

make mail work with multi-domains

the domain chosen is always the first domain
Dieser Commit ist enthalten in:
BlockListed 2023-09-09 11:10:13 +02:00
Ursprung e313745f7c
Commit 0d7e678c2e
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 2D204777C477B588

Datei anzeigen

@ -118,6 +118,10 @@ fn get_template(template_name: &str, data: &serde_json::Value) -> Result<(String
Ok((subject, body)) Ok((subject, body))
} }
fn mail_domain() -> String {
CONFIG.main_domain()
}
pub async fn send_password_hint(address: &str, hint: Option<String>) -> EmptyResult { pub async fn send_password_hint(address: &str, hint: Option<String>) -> EmptyResult {
let template_name = if hint.is_some() { let template_name = if hint.is_some() {
"email/pw_hint_some" "email/pw_hint_some"
@ -128,7 +132,7 @@ pub async fn send_password_hint(address: &str, hint: Option<String>) -> EmptyRes
let (subject, body_html, body_text) = get_text( let (subject, body_html, body_text) = get_text(
template_name, template_name,
json!({ json!({
"url": CONFIG.domain(), "url": mail_domain(),
"img_src": CONFIG._smtp_img_src(), "img_src": CONFIG._smtp_img_src(),
"hint": hint, "hint": hint,
}), }),
@ -144,7 +148,7 @@ pub async fn send_delete_account(address: &str, uuid: &str) -> EmptyResult {
let (subject, body_html, body_text) = get_text( let (subject, body_html, body_text) = get_text(
"email/delete_account", "email/delete_account",
json!({ json!({
"url": CONFIG.domain(), "url": mail_domain(),
"img_src": CONFIG._smtp_img_src(), "img_src": CONFIG._smtp_img_src(),
"user_id": uuid, "user_id": uuid,
"email": percent_encode(address.as_bytes(), NON_ALPHANUMERIC).to_string(), "email": percent_encode(address.as_bytes(), NON_ALPHANUMERIC).to_string(),
@ -162,7 +166,7 @@ pub async fn send_verify_email(address: &str, uuid: &str) -> EmptyResult {
let (subject, body_html, body_text) = get_text( let (subject, body_html, body_text) = get_text(
"email/verify_email", "email/verify_email",
json!({ json!({
"url": CONFIG.domain(), "url": mail_domain(),
"img_src": CONFIG._smtp_img_src(), "img_src": CONFIG._smtp_img_src(),
"user_id": uuid, "user_id": uuid,
"email": percent_encode(address.as_bytes(), NON_ALPHANUMERIC).to_string(), "email": percent_encode(address.as_bytes(), NON_ALPHANUMERIC).to_string(),
@ -177,7 +181,7 @@ pub async fn send_welcome(address: &str) -> EmptyResult {
let (subject, body_html, body_text) = get_text( let (subject, body_html, body_text) = get_text(
"email/welcome", "email/welcome",
json!({ json!({
"url": CONFIG.domain(), "url": mail_domain(),
"img_src": CONFIG._smtp_img_src(), "img_src": CONFIG._smtp_img_src(),
}), }),
)?; )?;
@ -192,7 +196,7 @@ pub async fn send_welcome_must_verify(address: &str, uuid: &str) -> EmptyResult
let (subject, body_html, body_text) = get_text( let (subject, body_html, body_text) = get_text(
"email/welcome_must_verify", "email/welcome_must_verify",
json!({ json!({
"url": CONFIG.domain(), "url": mail_domain(),
"img_src": CONFIG._smtp_img_src(), "img_src": CONFIG._smtp_img_src(),
"user_id": uuid, "user_id": uuid,
"token": verify_email_token, "token": verify_email_token,
@ -206,7 +210,7 @@ pub async fn send_2fa_removed_from_org(address: &str, org_name: &str) -> EmptyRe
let (subject, body_html, body_text) = get_text( let (subject, body_html, body_text) = get_text(
"email/send_2fa_removed_from_org", "email/send_2fa_removed_from_org",
json!({ json!({
"url": CONFIG.domain(), "url": mail_domain(),
"img_src": CONFIG._smtp_img_src(), "img_src": CONFIG._smtp_img_src(),
"org_name": org_name, "org_name": org_name,
}), }),
@ -219,7 +223,7 @@ pub async fn send_single_org_removed_from_org(address: &str, org_name: &str) ->
let (subject, body_html, body_text) = get_text( let (subject, body_html, body_text) = get_text(
"email/send_single_org_removed_from_org", "email/send_single_org_removed_from_org",
json!({ json!({
"url": CONFIG.domain(), "url": mail_domain(),
"img_src": CONFIG._smtp_img_src(), "img_src": CONFIG._smtp_img_src(),
"org_name": org_name, "org_name": org_name,
}), }),
@ -248,7 +252,7 @@ pub async fn send_invite(
let (subject, body_html, body_text) = get_text( let (subject, body_html, body_text) = get_text(
"email/send_org_invite", "email/send_org_invite",
json!({ json!({
"url": CONFIG.domain(), "url": mail_domain(),
"img_src": CONFIG._smtp_img_src(), "img_src": CONFIG._smtp_img_src(),
"org_id": org_id.as_deref().unwrap_or("_"), "org_id": org_id.as_deref().unwrap_or("_"),
"org_user_id": org_user_id.as_deref().unwrap_or("_"), "org_user_id": org_user_id.as_deref().unwrap_or("_"),
@ -282,7 +286,7 @@ pub async fn send_emergency_access_invite(
let (subject, body_html, body_text) = get_text( let (subject, body_html, body_text) = get_text(
"email/send_emergency_access_invite", "email/send_emergency_access_invite",
json!({ json!({
"url": CONFIG.domain(), "url": mail_domain(),
"img_src": CONFIG._smtp_img_src(), "img_src": CONFIG._smtp_img_src(),
"emer_id": emer_id, "emer_id": emer_id,
"email": percent_encode(address.as_bytes(), NON_ALPHANUMERIC).to_string(), "email": percent_encode(address.as_bytes(), NON_ALPHANUMERIC).to_string(),
@ -298,7 +302,7 @@ pub async fn send_emergency_access_invite_accepted(address: &str, grantee_email:
let (subject, body_html, body_text) = get_text( let (subject, body_html, body_text) = get_text(
"email/emergency_access_invite_accepted", "email/emergency_access_invite_accepted",
json!({ json!({
"url": CONFIG.domain(), "url": mail_domain(),
"img_src": CONFIG._smtp_img_src(), "img_src": CONFIG._smtp_img_src(),
"grantee_email": grantee_email, "grantee_email": grantee_email,
}), }),
@ -311,7 +315,7 @@ pub async fn send_emergency_access_invite_confirmed(address: &str, grantor_name:
let (subject, body_html, body_text) = get_text( let (subject, body_html, body_text) = get_text(
"email/emergency_access_invite_confirmed", "email/emergency_access_invite_confirmed",
json!({ json!({
"url": CONFIG.domain(), "url": mail_domain(),
"img_src": CONFIG._smtp_img_src(), "img_src": CONFIG._smtp_img_src(),
"grantor_name": grantor_name, "grantor_name": grantor_name,
}), }),
@ -324,7 +328,7 @@ pub async fn send_emergency_access_recovery_approved(address: &str, grantor_name
let (subject, body_html, body_text) = get_text( let (subject, body_html, body_text) = get_text(
"email/emergency_access_recovery_approved", "email/emergency_access_recovery_approved",
json!({ json!({
"url": CONFIG.domain(), "url": mail_domain(),
"img_src": CONFIG._smtp_img_src(), "img_src": CONFIG._smtp_img_src(),
"grantor_name": grantor_name, "grantor_name": grantor_name,
}), }),
@ -342,7 +346,7 @@ pub async fn send_emergency_access_recovery_initiated(
let (subject, body_html, body_text) = get_text( let (subject, body_html, body_text) = get_text(
"email/emergency_access_recovery_initiated", "email/emergency_access_recovery_initiated",
json!({ json!({
"url": CONFIG.domain(), "url": mail_domain(),
"img_src": CONFIG._smtp_img_src(), "img_src": CONFIG._smtp_img_src(),
"grantee_name": grantee_name, "grantee_name": grantee_name,
"atype": atype, "atype": atype,
@ -362,7 +366,7 @@ pub async fn send_emergency_access_recovery_reminder(
let (subject, body_html, body_text) = get_text( let (subject, body_html, body_text) = get_text(
"email/emergency_access_recovery_reminder", "email/emergency_access_recovery_reminder",
json!({ json!({
"url": CONFIG.domain(), "url": mail_domain(),
"img_src": CONFIG._smtp_img_src(), "img_src": CONFIG._smtp_img_src(),
"grantee_name": grantee_name, "grantee_name": grantee_name,
"atype": atype, "atype": atype,
@ -377,7 +381,7 @@ pub async fn send_emergency_access_recovery_rejected(address: &str, grantor_name
let (subject, body_html, body_text) = get_text( let (subject, body_html, body_text) = get_text(
"email/emergency_access_recovery_rejected", "email/emergency_access_recovery_rejected",
json!({ json!({
"url": CONFIG.domain(), "url": mail_domain(),
"img_src": CONFIG._smtp_img_src(), "img_src": CONFIG._smtp_img_src(),
"grantor_name": grantor_name, "grantor_name": grantor_name,
}), }),
@ -390,7 +394,7 @@ pub async fn send_emergency_access_recovery_timed_out(address: &str, grantee_nam
let (subject, body_html, body_text) = get_text( let (subject, body_html, body_text) = get_text(
"email/emergency_access_recovery_timed_out", "email/emergency_access_recovery_timed_out",
json!({ json!({
"url": CONFIG.domain(), "url": mail_domain(),
"img_src": CONFIG._smtp_img_src(), "img_src": CONFIG._smtp_img_src(),
"grantee_name": grantee_name, "grantee_name": grantee_name,
"atype": atype, "atype": atype,
@ -404,7 +408,7 @@ pub async fn send_invite_accepted(new_user_email: &str, address: &str, org_name:
let (subject, body_html, body_text) = get_text( let (subject, body_html, body_text) = get_text(
"email/invite_accepted", "email/invite_accepted",
json!({ json!({
"url": CONFIG.domain(), "url": mail_domain(),
"img_src": CONFIG._smtp_img_src(), "img_src": CONFIG._smtp_img_src(),
"email": new_user_email, "email": new_user_email,
"org_name": org_name, "org_name": org_name,
@ -418,7 +422,7 @@ pub async fn send_invite_confirmed(address: &str, org_name: &str) -> EmptyResult
let (subject, body_html, body_text) = get_text( let (subject, body_html, body_text) = get_text(
"email/invite_confirmed", "email/invite_confirmed",
json!({ json!({
"url": CONFIG.domain(), "url": mail_domain(),
"img_src": CONFIG._smtp_img_src(), "img_src": CONFIG._smtp_img_src(),
"org_name": org_name, "org_name": org_name,
}), }),
@ -435,7 +439,7 @@ pub async fn send_new_device_logged_in(address: &str, ip: &str, dt: &NaiveDateTi
let (subject, body_html, body_text) = get_text( let (subject, body_html, body_text) = get_text(
"email/new_device_logged_in", "email/new_device_logged_in",
json!({ json!({
"url": CONFIG.domain(), "url": mail_domain(),
"img_src": CONFIG._smtp_img_src(), "img_src": CONFIG._smtp_img_src(),
"ip": ip, "ip": ip,
"device": device, "device": device,
@ -454,7 +458,7 @@ pub async fn send_incomplete_2fa_login(address: &str, ip: &str, dt: &NaiveDateTi
let (subject, body_html, body_text) = get_text( let (subject, body_html, body_text) = get_text(
"email/incomplete_2fa_login", "email/incomplete_2fa_login",
json!({ json!({
"url": CONFIG.domain(), "url": mail_domain(),
"img_src": CONFIG._smtp_img_src(), "img_src": CONFIG._smtp_img_src(),
"ip": ip, "ip": ip,
"device": device, "device": device,
@ -470,7 +474,7 @@ pub async fn send_token(address: &str, token: &str) -> EmptyResult {
let (subject, body_html, body_text) = get_text( let (subject, body_html, body_text) = get_text(
"email/twofactor_email", "email/twofactor_email",
json!({ json!({
"url": CONFIG.domain(), "url": mail_domain(),
"img_src": CONFIG._smtp_img_src(), "img_src": CONFIG._smtp_img_src(),
"token": token, "token": token,
}), }),
@ -483,7 +487,7 @@ pub async fn send_change_email(address: &str, token: &str) -> EmptyResult {
let (subject, body_html, body_text) = get_text( let (subject, body_html, body_text) = get_text(
"email/change_email", "email/change_email",
json!({ json!({
"url": CONFIG.domain(), "url": mail_domain(),
"img_src": CONFIG._smtp_img_src(), "img_src": CONFIG._smtp_img_src(),
"token": token, "token": token,
}), }),
@ -496,7 +500,7 @@ pub async fn send_test(address: &str) -> EmptyResult {
let (subject, body_html, body_text) = get_text( let (subject, body_html, body_text) = get_text(
"email/smtp_test", "email/smtp_test",
json!({ json!({
"url": CONFIG.domain(), "url": mail_domain(),
"img_src": CONFIG._smtp_img_src(), "img_src": CONFIG._smtp_img_src(),
}), }),
)?; )?;
@ -508,7 +512,7 @@ pub async fn send_admin_reset_password(address: &str, user_name: &str, org_name:
let (subject, body_html, body_text) = get_text( let (subject, body_html, body_text) = get_text(
"email/admin_reset_password", "email/admin_reset_password",
json!({ json!({
"url": CONFIG.domain(), "url": mail_domain(),
"img_src": CONFIG._smtp_img_src(), "img_src": CONFIG._smtp_img_src(),
"user_name": user_name, "user_name": user_name,
"org_name": org_name, "org_name": org_name,