Initial commit.

This commit is contained in:
Burak Kaan Köse
2024-04-18 01:44:37 +02:00
parent 524ea4c0e1
commit 12d3814626
671 changed files with 77295 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
using System;
namespace Wino.Core.Domain.Models.AutoDiscovery
{
public class AutoDiscoveryConnectionTestFailedPackage
{
public AutoDiscoveryConnectionTestFailedPackage(AutoDiscoverySettings settings, Exception error)
{
Settings = settings ?? throw new ArgumentNullException(nameof(settings));
Error = error ?? throw new ArgumentNullException(nameof(error));
}
public AutoDiscoveryConnectionTestFailedPackage(Exception error)
{
Error = error ?? throw new ArgumentNullException(nameof(error));
}
public AutoDiscoverySettings Settings { get; set; }
public Exception Error { get; set; }
}
}

View File

@@ -0,0 +1,9 @@
namespace Wino.Core.Domain.Models.AutoDiscovery
{
public class AutoDiscoveryMinimalSettings
{
public string DisplayName { get; set; }
public string Email { get; set; }
public string Password { get; set; }
}
}

View File

@@ -0,0 +1,22 @@
using Newtonsoft.Json;
namespace Wino.Core.Domain.Models.AutoDiscovery
{
public class AutoDiscoveryProviderSetting
{
[JsonProperty("protocol")]
public string Protocol { get; set; }
[JsonProperty("address")]
public string Address { get; set; }
[JsonProperty("port")]
public int Port { get; set; }
[JsonProperty("secure")]
public string Secure { get; set; }
[JsonProperty("username")]
public string Username { get; set; }
}
}

View File

@@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Wino.Core.Domain.Entities;
namespace Wino.Core.Domain.Models.AutoDiscovery
{
public class AutoDiscoverySettings
{
[JsonProperty("domain")]
public string Domain { get; set; }
[JsonProperty("password")]
public string Password { get; set; }
[JsonProperty("settings")]
public List<AutoDiscoveryProviderSetting> Settings { get; set; }
/// <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 _);
public AutoDiscoveryMinimalSettings UserMinimalSettings { get; set; }
public CustomServerInformation ToServerInformation()
{
var imapSettings = GetImapSettings();
var smtpSettings = GetSmptpSettings();
if (imapSettings == null || smtpSettings == null) return null;
bool imapRequiresSSL = imapSettings.Secure == "SSL";
bool smtpRequiresSSL = smtpSettings.Secure == "SSL";
string imapUrl = imapSettings.Address;
string smtpUrl = smtpSettings.Address;
string imapUsername = imapSettings.Username;
string smtpUsername = smtpSettings.Username;
int imapPort = imapSettings.Port;
int smtpPort = smtpSettings.Port;
var serverInfo = new CustomServerInformation
{
Id = Guid.NewGuid(),
DisplayName = UserMinimalSettings.DisplayName,
Address = UserMinimalSettings.Email,
IncomingServerPassword = UserMinimalSettings.Password,
OutgoingServerPassword = UserMinimalSettings.Password,
IncomingRequiresSSL = imapRequiresSSL,
OutgoingRequresSSL = smtpRequiresSSL,
IncomingServer = imapUrl,
OutgoingServer = smtpUrl,
IncomingServerPort = imapPort.ToString(),
OutgoingServerPort = smtpPort.ToString(),
IncomingServerType = Enums.CustomIncomingServerType.IMAP4,
IncomingServerUsername = imapUsername,
OutgoingServerUsername = smtpUsername
};
return serverInfo;
}
public AutoDiscoveryProviderSetting GetImapSettings()
=> Settings?.Find(a => a.Protocol == "IMAP");
public AutoDiscoveryProviderSetting GetSmptpSettings()
=> Settings?.Find(a => a.Protocol == "SMTP");
}
}