From 1da2cedffd1c802af4c197200e85f154bf2f1457 Mon Sep 17 00:00:00 2001 From: rockstardev <5191402+rockstardev@users.noreply.github.com> Date: Wed, 5 Mar 2025 22:14:06 -0600 Subject: [PATCH] Reverting changes, validate email only if it was provided --- .../GreenField/GreenfieldServerEmailController.cs | 6 +++--- .../GreenField/GreenfieldStoreEmailController.cs | 6 +++--- BTCPayServer/Controllers/UIServerController.cs | 4 ++-- BTCPayServer/Controllers/UIStoresController.Email.cs | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/BTCPayServer/Controllers/GreenField/GreenfieldServerEmailController.cs b/BTCPayServer/Controllers/GreenField/GreenfieldServerEmailController.cs index eb8ce55a5..c1fd39144 100644 --- a/BTCPayServer/Controllers/GreenField/GreenfieldServerEmailController.cs +++ b/BTCPayServer/Controllers/GreenField/GreenfieldServerEmailController.cs @@ -50,11 +50,11 @@ namespace BTCPayServer.Controllers.GreenField [HttpPut("~/api/v1/server/email")] public async Task ServerEmailSettings(ServerEmailSettingsData request) { - if (!MailboxAddressValidator.IsMailboxAddress(request.From)) - { + if (!string.IsNullOrWhiteSpace(request.From) && !MailboxAddressValidator.IsMailboxAddress(request.From)) ModelState.AddModelError(nameof(request.From), "Invalid email address"); + + if (!ModelState.IsValid) return this.CreateValidationError(ModelState); - } if (_policiesSettings.DisableStoresToUseServerEmailSettings == request.EnableStoresToUseServerEmailSettings) { diff --git a/BTCPayServer/Controllers/GreenField/GreenfieldStoreEmailController.cs b/BTCPayServer/Controllers/GreenField/GreenfieldStoreEmailController.cs index 2ca96fd26..409e0a8dd 100644 --- a/BTCPayServer/Controllers/GreenField/GreenfieldStoreEmailController.cs +++ b/BTCPayServer/Controllers/GreenField/GreenfieldStoreEmailController.cs @@ -70,11 +70,11 @@ namespace BTCPayServer.Controllers.GreenField [HttpPut("~/api/v1/stores/{storeId}/email")] public async Task UpdateStoreEmailSettings(string storeId, EmailSettingsData request) { - if (!MailboxAddressValidator.IsMailboxAddress(request.From)) - { + if (!string.IsNullOrWhiteSpace(request.From) && !MailboxAddressValidator.IsMailboxAddress(request.From)) ModelState.AddModelError(nameof(request.From), "Invalid email address"); + + if (!ModelState.IsValid) return this.CreateValidationError(ModelState); - } var store = HttpContext.GetStoreData(); var blob = store.GetStoreBlob(); diff --git a/BTCPayServer/Controllers/UIServerController.cs b/BTCPayServer/Controllers/UIServerController.cs index 4f35a74e7..3c206ca94 100644 --- a/BTCPayServer/Controllers/UIServerController.cs +++ b/BTCPayServer/Controllers/UIServerController.cs @@ -1256,8 +1256,8 @@ namespace BTCPayServer.Controllers return RedirectToAction(nameof(Emails)); } - // save - if (!MailboxAddressValidator.IsMailboxAddress(model.Settings.From)) + // save if user provided valid email; this will also clear settings if no model.Settings.From + if (model.Settings.From is not null && !MailboxAddressValidator.IsMailboxAddress(model.Settings.From)) { ModelState.AddModelError("Settings.From", StringLocalizer["Invalid email"]); return View(model); diff --git a/BTCPayServer/Controllers/UIStoresController.Email.cs b/BTCPayServer/Controllers/UIStoresController.Email.cs index 10d9253ba..27d649a5f 100644 --- a/BTCPayServer/Controllers/UIStoresController.Email.cs +++ b/BTCPayServer/Controllers/UIStoresController.Email.cs @@ -209,7 +209,7 @@ public partial class UIStoresController if (model.IsCustomSMTP) { model.Settings.Validate("Settings.", ModelState); - if (!MailboxAddressValidator.IsMailboxAddress(model.Settings.From)) + if (model.Settings.From is not null && !MailboxAddressValidator.IsMailboxAddress(model.Settings.From)) { ModelState.AddModelError("Settings.From", StringLocalizer["Invalid email"]); }