Add project files

This commit is contained in:
Sean Greenawalt 2025-05-10 05:16:40 -04:00
commit 8cf01ead74
Signed by: seang96
GPG key ID: 504F02B511005571
40 changed files with 3967 additions and 0 deletions

View file

@ -0,0 +1,41 @@
using AdOrbitSDK;
using StalwartSimpleLoginMiddleware.Constants;
namespace StalwartSimpleLoginMiddleware.Services;
public class StalwartClient() : IDisposable
{
private Client _userClient;
private static HttpClient HttpClient => new()
{
BaseAddress = new Uri(Environment.GetEnvironmentVariable(EnvironmentVariable.MailServerUri) + "/api/")
};
public async Task<Client> GetClient()
{
if (_userClient != null) return _userClient;
return GetClient(Environment.GetEnvironmentVariable(EnvironmentVariable.MailServerApiKey) ?? string.Empty);
}
private Client GetClient(string apiKey)
{
if (_userClient != null) return _userClient;
if (string.IsNullOrEmpty(HttpClient.BaseAddress?.AbsoluteUri))
throw new NullReferenceException($"{EnvironmentVariable.MailServerUri} is missing in environment.");
if (string.IsNullOrEmpty(apiKey))
throw new NullReferenceException($"{EnvironmentVariable.MailServerApiKey} is missing in environment.");
_userClient = new Client(HttpClient, apiKey);
return _userClient;
}
public void Dispose()
{
HttpClient.Dispose();
GC.SuppressFinalize(this);
}
}