2025-02-15 12:53:32 +01:00
|
|
|
using Wino.Core.Domain.Entities.Shared;
|
|
|
|
|
using Wino.Core.Domain.Enums;
|
|
|
|
|
using Wino.Core.Domain.Interfaces;
|
|
|
|
|
using Wino.Core.Domain.Models.Accounts;
|
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
namespace Wino.Services;
|
|
|
|
|
|
|
|
|
|
public class SpecialImapProviderConfigResolver : ISpecialImapProviderConfigResolver
|
2025-02-15 12:53:32 +01:00
|
|
|
{
|
2025-02-16 11:54:23 +01:00
|
|
|
public CustomServerInformation GetServerInformation(MailAccount account, AccountCreationDialogResult dialogResult)
|
|
|
|
|
{
|
|
|
|
|
CustomServerInformation resolvedConfig = null;
|
2026-02-15 11:27:30 +01:00
|
|
|
var details = dialogResult.SpecialImapProviderDetails;
|
2025-02-15 12:53:32 +01:00
|
|
|
|
2026-02-15 11:27:30 +01:00
|
|
|
if (details.SpecialImapProvider == SpecialImapProvider.iCloud)
|
2025-02-16 11:54:23 +01:00
|
|
|
{
|
2026-04-22 09:55:13 +02:00
|
|
|
var iCloudMailboxUsername = GetICloudMailboxUsername(details.Address);
|
|
|
|
|
|
2026-02-15 11:27:30 +01:00
|
|
|
resolvedConfig = new CustomServerInformation()
|
|
|
|
|
{
|
|
|
|
|
IncomingServer = "imap.mail.me.com",
|
|
|
|
|
IncomingServerPort = "993",
|
|
|
|
|
IncomingServerType = CustomIncomingServerType.IMAP4,
|
|
|
|
|
IncomingServerSocketOption = ImapConnectionSecurity.Auto,
|
|
|
|
|
IncomingAuthenticationMethod = ImapAuthenticationMethod.Auto,
|
|
|
|
|
OutgoingServer = "smtp.mail.me.com",
|
|
|
|
|
OutgoingServerPort = "587",
|
|
|
|
|
OutgoingServerSocketOption = ImapConnectionSecurity.Auto,
|
|
|
|
|
OutgoingAuthenticationMethod = ImapAuthenticationMethod.Auto,
|
|
|
|
|
MaxConcurrentClients = 5,
|
|
|
|
|
CalDavServiceUrl = "https://caldav.icloud.com/"
|
|
|
|
|
};
|
2025-02-16 11:35:43 +01:00
|
|
|
|
2026-04-22 09:55:13 +02:00
|
|
|
// iCloud IMAP/SMTP authentication uses only the local-part mailbox username.
|
|
|
|
|
resolvedConfig.IncomingServerUsername = iCloudMailboxUsername;
|
|
|
|
|
resolvedConfig.OutgoingServerUsername = iCloudMailboxUsername;
|
2025-02-16 11:54:23 +01:00
|
|
|
}
|
2026-02-15 11:27:30 +01:00
|
|
|
else if (details.SpecialImapProvider == SpecialImapProvider.Yahoo)
|
2025-02-16 11:54:23 +01:00
|
|
|
{
|
2026-02-15 11:27:30 +01:00
|
|
|
resolvedConfig = new CustomServerInformation()
|
|
|
|
|
{
|
|
|
|
|
IncomingServer = "imap.mail.yahoo.com",
|
|
|
|
|
IncomingServerPort = "993",
|
|
|
|
|
IncomingServerType = CustomIncomingServerType.IMAP4,
|
|
|
|
|
IncomingServerSocketOption = ImapConnectionSecurity.Auto,
|
|
|
|
|
IncomingAuthenticationMethod = ImapAuthenticationMethod.Auto,
|
|
|
|
|
OutgoingServer = "smtp.mail.yahoo.com",
|
|
|
|
|
OutgoingServerPort = "587",
|
|
|
|
|
OutgoingServerSocketOption = ImapConnectionSecurity.Auto,
|
|
|
|
|
OutgoingAuthenticationMethod = ImapAuthenticationMethod.Auto,
|
|
|
|
|
MaxConcurrentClients = 5,
|
|
|
|
|
CalDavServiceUrl = "https://caldav.calendar.yahoo.com/"
|
|
|
|
|
};
|
2025-02-16 11:43:30 +01:00
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
// Yahoo uses full address for both incoming and outgoing.
|
2026-02-15 11:27:30 +01:00
|
|
|
resolvedConfig.IncomingServerUsername = details.Address;
|
|
|
|
|
resolvedConfig.OutgoingServerUsername = details.Address;
|
2025-02-16 11:43:30 +01:00
|
|
|
}
|
2025-02-16 11:54:23 +01:00
|
|
|
|
|
|
|
|
// Fill in account details.
|
2026-02-15 11:27:30 +01:00
|
|
|
resolvedConfig.Address = details.Address;
|
|
|
|
|
resolvedConfig.IncomingServerPassword = details.Password;
|
|
|
|
|
resolvedConfig.OutgoingServerPassword = details.Password;
|
|
|
|
|
resolvedConfig.DisplayName = details.SenderName;
|
|
|
|
|
resolvedConfig.CalendarSupportMode = details.CalendarSupportMode;
|
|
|
|
|
resolvedConfig.CalDavUsername = details.Address;
|
|
|
|
|
resolvedConfig.CalDavPassword = details.Password;
|
|
|
|
|
|
|
|
|
|
if (details.CalendarSupportMode != ImapCalendarSupportMode.CalDav)
|
|
|
|
|
{
|
|
|
|
|
resolvedConfig.CalDavServiceUrl = string.Empty;
|
|
|
|
|
resolvedConfig.CalDavUsername = string.Empty;
|
|
|
|
|
resolvedConfig.CalDavPassword = string.Empty;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
return resolvedConfig;
|
2025-02-15 12:53:32 +01:00
|
|
|
}
|
2026-04-22 09:55:13 +02:00
|
|
|
|
|
|
|
|
private static string GetICloudMailboxUsername(string address)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(address))
|
|
|
|
|
return string.Empty;
|
|
|
|
|
|
|
|
|
|
var normalizedAddress = address.Trim();
|
|
|
|
|
var atIndex = normalizedAddress.IndexOf('@');
|
|
|
|
|
|
|
|
|
|
return atIndex > 0
|
|
|
|
|
? normalizedAddress[..atIndex]
|
|
|
|
|
: normalizedAddress;
|
|
|
|
|
}
|
2025-02-15 12:53:32 +01:00
|
|
|
}
|