mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2026-01-01 13:14:30 +01:00
* Adding endpoint in Greenfield to allow server email settings * Adding related swagger file * Refactoring EmailSettingsData to be more readable * Adding server email masking * Adding tests * Update BTCPayServer/wwwroot/swagger/v1/swagger.template.serveremail.json Co-authored-by: d11n <mail@dennisreimann.de> * Masking smtp server email returned over greenfield api and test * Retaining password if password mask is used * Remove magic string ***** * Flatten request for server's settings. Fix bug on shared setting instances * Remove useless doc * Simplify code * Fix Store Email settings page --------- Co-authored-by: d11n <mail@dennisreimann.de> Co-authored-by: nicolas.dorier <nicolas.dorier@gmail.com>
63 lines
2.1 KiB
C#
63 lines
2.1 KiB
C#
#nullable enable
|
|
using System;
|
|
using System.Threading.Tasks;
|
|
using BTCPayServer.Data;
|
|
using BTCPayServer.Logging;
|
|
using BTCPayServer.Services.Stores;
|
|
|
|
namespace BTCPayServer.Services.Mails
|
|
{
|
|
class StoreEmailSender : EmailSender
|
|
{
|
|
public StoreEmailSender(StoreRepository storeRepository,
|
|
EmailSender? fallback,
|
|
IBackgroundJobClient backgroundJobClient,
|
|
string storeId,
|
|
Logs logs) : base(backgroundJobClient, logs)
|
|
{
|
|
StoreId = storeId ?? throw new ArgumentNullException(nameof(storeId));
|
|
StoreRepository = storeRepository;
|
|
FallbackSender = fallback;
|
|
}
|
|
|
|
public StoreRepository StoreRepository { get; }
|
|
public EmailSender? FallbackSender { get; }
|
|
public string StoreId { get; }
|
|
|
|
public override async Task<EmailSettings?> GetEmailSettings()
|
|
{
|
|
var store = await StoreRepository.FindStore(StoreId);
|
|
if (store is null)
|
|
return null;
|
|
var emailSettings = GetCustomSettings(store);
|
|
if (emailSettings is not null)
|
|
return emailSettings;
|
|
if (FallbackSender is not null)
|
|
return await FallbackSender.GetEmailSettings();
|
|
return null;
|
|
}
|
|
public async Task<EmailSettings?> GetCustomSettings()
|
|
{
|
|
var store = await StoreRepository.FindStore(StoreId);
|
|
if (store is null)
|
|
return null;
|
|
return GetCustomSettings(store);
|
|
}
|
|
EmailSettings? GetCustomSettings(StoreData store)
|
|
{
|
|
var emailSettings = store.GetStoreBlob().EmailSettings;
|
|
if (emailSettings?.IsComplete() is true)
|
|
{
|
|
return emailSettings;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public override async Task<string> GetPrefixedSubject(string subject)
|
|
{
|
|
var store = await StoreRepository.FindStore(StoreId);
|
|
return string.IsNullOrEmpty(store?.StoreName) ? subject : $"{store.StoreName}: {subject}";
|
|
}
|
|
}
|
|
}
|