Files

72 lines
2.6 KiB
C#
Raw Permalink Normal View History

2024-04-18 01:44:37 +02:00
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;
using Wino.Core.Domain.Entities.Shared;
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
namespace Wino.Core.Domain.Models.AutoDiscovery;
public class AutoDiscoverySettings
2024-04-18 01:44:37 +02:00
{
2025-02-16 11:54:23 +01:00
[JsonPropertyName("domain")]
public string Domain { get; set; }
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
[JsonPropertyName("password")]
public string Password { get; set; }
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
[JsonPropertyName("settings")]
public List<AutoDiscoveryProviderSetting> Settings { get; set; }
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
/// <summary>
/// Gets whether this domain requires additional steps for password like app-specific password or sth.
/// </summary>
public bool IsPasswordSupportLinkAvailable => !string.IsNullOrEmpty(Password) && Uri.TryCreate(Password, UriKind.Absolute, out _);
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
public AutoDiscoveryMinimalSettings UserMinimalSettings { get; set; }
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
public CustomServerInformation ToServerInformation()
{
var imapSettings = GetImapSettings();
var smtpSettings = GetSmptpSettings();
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
if (imapSettings == null || smtpSettings == null) return null;
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
string imapUrl = imapSettings.Address;
string smtpUrl = smtpSettings.Address;
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
string imapUsername = imapSettings.Username;
string smtpUsername = smtpSettings.Username;
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
int imapPort = imapSettings.Port;
int smtpPort = smtpSettings.Port;
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
var serverInfo = new CustomServerInformation
{
Id = Guid.NewGuid(),
DisplayName = UserMinimalSettings.DisplayName,
Address = UserMinimalSettings.Email,
IncomingServerPassword = UserMinimalSettings.Password,
OutgoingServerPassword = UserMinimalSettings.Password,
IncomingAuthenticationMethod = Enums.ImapAuthenticationMethod.Auto,
OutgoingAuthenticationMethod = Enums.ImapAuthenticationMethod.Auto,
OutgoingServerSocketOption = Enums.ImapConnectionSecurity.Auto,
IncomingServerSocketOption = Enums.ImapConnectionSecurity.Auto,
IncomingServer = imapUrl,
OutgoingServer = smtpUrl,
IncomingServerPort = imapPort.ToString(),
OutgoingServerPort = smtpPort.ToString(),
IncomingServerType = Enums.CustomIncomingServerType.IMAP4,
IncomingServerUsername = imapUsername,
OutgoingServerUsername = smtpUsername,
MaxConcurrentClients = 5
};
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
return serverInfo;
}
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
public AutoDiscoveryProviderSetting GetImapSettings()
=> Settings?.Find(a => a.Protocol == "IMAP");
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
public AutoDiscoveryProviderSetting GetSmptpSettings()
=> Settings?.Find(a => a.Protocol == "SMTP");
2024-04-18 01:44:37 +02:00
}