IMAP Improvements (#558)

* Fixing an issue where scrollviewer overrides a part of template in mail list. Adjusted zoomed out header grid's corner radius.

* IDLE implementation, imap synchronization strategies basics and condstore synchronization.

* Adding iCloud and Yahoo as special IMAP handling scenario.

* iCloud special imap handling.

* Support for killing synchronizers.

* Update privacy policy url.

* Batching condstore downloads into 50, using SORT extension for searches if supported.

* Bumping some nugets. More on the imap synchronizers.

* Delegating idle synchronizations to server to post-sync operations.

* Update mailkit to resolve qresync bug with iCloud.

* Fixing remote highest mode seq checks for qresync and condstore synchronizers.

* Yahoo custom settings.

* Bump google sdk package.

* Fixing the build issue....

* NRE on canceled token accounts during setup.

* Server crash handlers.

* Remove ARM32. Upgrade server to .NET 9.

* Fix icons for yahoo and apple.

* Fixed an issue where disabled folders causing an exception on forced sync.

* Remove smtp encoding constraint.

* Remove commented code.

* Fixing merge conflict

* Addressing double registrations for mailkit remote folder events in synchronizers.

* Making sure idle canceled result is not reported.

* Fixing custom imap server dialog opening.

* Fixing the issue with account creation making the previously selected account as selected as well.

* Fixing app close behavior and logging app close.
This commit is contained in:
Burak Kaan Köse
2025-02-15 12:53:32 +01:00
committed by GitHub
parent 30f1257983
commit ee9e41c5a7
108 changed files with 2092 additions and 1166 deletions

View File

@@ -72,6 +72,12 @@ namespace Wino.Core.Domain.Entities.Shared
/// </summary>
public Guid? MergedInboxId { get; set; }
/// <summary>
/// Gets or sets the additional IMAP provider assignment for the account.
/// Providers that use IMAP as a synchronizer but have special requirements.
/// </summary>
public SpecialImapProvider SpecialImapProvider { get; set; }
/// <summary>
/// Contains the merged inbox this account belongs to.
/// Ignored for all SQLite operations.
@@ -95,7 +101,7 @@ namespace Wino.Core.Domain.Entities.Shared
/// <summary>
/// Gets whether the account can perform ProfileInformation sync type.
/// </summary>
public bool IsProfileInfoSyncSupported => ProviderType == MailProviderType.Outlook || ProviderType == MailProviderType.Office365 || ProviderType == MailProviderType.Gmail;
public bool IsProfileInfoSyncSupported => ProviderType == MailProviderType.Outlook || ProviderType == MailProviderType.Gmail;
/// <summary>
/// Gets whether the account can perform AliasInformation sync type.

View File

@@ -4,8 +4,6 @@
{
Outlook,
Gmail,
Office365,
Yahoo,
IMAP4
IMAP4 = 4 // 2-3 were removed after release. Don't change for backward compatibility.
}
}

View File

@@ -2,13 +2,13 @@
{
public enum MailSynchronizationType
{
// Shared
UpdateProfile, // Only update profile information
ExecuteRequests, // Run the queued requests, and then synchronize if needed.
FoldersOnly, // Only synchronize folder metadata.
InboxOnly, // Only Inbox, Sent and Draft folders.
InboxOnly, // Only Inbox, Sent, Draft and Deleted folders.
CustomFolders, // Only sync folders that are specified in the options.
FullFolders, // Synchronize all folders. This won't update profile or alias information.
Alias, // Only update alias information
IMAPIdle // Idle client triggered synchronization.
}
}

View File

@@ -0,0 +1,9 @@
namespace Wino.Core.Domain.Enums
{
public enum SpecialImapProvider
{
None,
iCloud,
Yahoo
}
}

View File

@@ -0,0 +1,10 @@
namespace Wino.Core.Domain.Exceptions
{
public class ImapSynchronizerStrategyException : System.Exception
{
public ImapSynchronizerStrategyException(string message) : base(message)
{
}
}
}

View File

@@ -1,11 +1,12 @@
using System.Threading;
using System.Threading.Tasks;
using Wino.Core.Domain.Enums;
namespace Wino.Core.Domain.Interfaces
{
public interface IAccountCreationDialog
{
void ShowDialog(CancellationTokenSource cancellationTokenSource);
Task ShowDialogAsync(CancellationTokenSource cancellationTokenSource);
void Complete(bool cancel);
AccountCreationDialogState State { get; set; }
}

View File

@@ -23,12 +23,6 @@ namespace Wino.Core.Domain.Interfaces
/// <param name="request">Request to queue.</param>
void QueueRequest(IRequestBase request);
/// <summary>
/// TODO
/// </summary>
/// <returns>Whether active synchronization is stopped or not.</returns>
bool CancelActiveSynchronization();
/// <summary>
/// Synchronizes profile information with the server.
/// Sender name and Profile picture are updated.

View File

@@ -13,5 +13,10 @@ namespace Wino.Core.Domain.Interfaces
/// Which folders to sync after this operation?
/// </summary>
List<Guid> SynchronizationFolderIds { get; }
/// <summary>
/// If true, additional folders like Sent, Drafts and Deleted will not be synchronized
/// </summary>
bool ExcludeMustHaveFolders { get; }
}
}

View File

@@ -27,7 +27,7 @@ namespace Wino.Core.Domain.Interfaces
string dontAskAgainConfigurationKey = "");
Task<bool> ShowCustomThemeBuilderDialogAsync();
Task<AccountCreationDialogResult> ShowAccountProviderSelectionDialogAsync(List<IProviderDetail> availableProviders);
IAccountCreationDialog GetAccountCreationDialog(MailProviderType type);
IAccountCreationDialog GetAccountCreationDialog(AccountCreationDialogResult accountCreationDialogResult);
Task<List<SharedFile>> PickFilesAsync(params object[] typeFilters);
Task<string> PickFilePathAsync(string saveFileName);
}

View File

@@ -3,7 +3,7 @@ using Wino.Core.Domain.Entities.Shared;
namespace Wino.Core.Domain.Interfaces
{
public interface ICustomServerAccountCreationDialog : IAccountCreationDialog
public interface IImapAccountCreationDialog : IAccountCreationDialog
{
/// <summary>
/// Returns the custom server information from the dialog..

View File

@@ -0,0 +1,12 @@
using MailKit.Net.Imap;
namespace Wino.Core.Domain.Interfaces
{
/// <summary>
/// Provides a synchronization strategy for synchronizing IMAP folders based on the server capabilities.
/// </summary>
public interface IImapSynchronizationStrategyProvider
{
IImapSynchronizerStrategy GetSynchronizationStrategy(IImapClient client);
}
}

View File

@@ -0,0 +1,17 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Wino.Core.Domain.Entities.Mail;
using Wino.Core.Domain.Models.MailItem;
namespace Wino.Core.Domain.Interfaces
{
public interface IImapSynchronizer
{
uint InitialMessageDownloadCountPerFolder { get; }
Task<List<NewMailItemPackage>> CreateNewMailPackagesAsync(ImapMessageCreationPackage message, MailItemFolder assignedFolder, CancellationToken cancellationToken = default);
Task StartIdleClientAsync();
Task StopIdleClientAsync();
}
}

View File

@@ -0,0 +1,22 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using MailKit.Net.Imap;
using Wino.Core.Domain.Entities.Mail;
namespace Wino.Core.Domain.Interfaces
{
public interface IImapSynchronizerStrategy
{
/// <summary>
/// Synchronizes given folder with the ImapClient client from the client pool.
/// </summary>
/// <param name="client">Client to perform sync with. I love Mira and Jasminka</param>
/// <param name="folder">Folder to synchronize.</param>
/// <param name="synchronizer">Imap synchronizer that downloads messages.</param>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns>List of new downloaded message ids that don't exist locally.</returns>
Task<List<string>> HandleSynchronizationAsync(IImapClient client, MailItemFolder folder, IImapSynchronizer synchronizer, CancellationToken cancellationToken = default);
}
}

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using MailKit;
using Wino.Core.Domain.Entities.Mail;
using Wino.Core.Domain.Entities.Shared;
using Wino.Core.Domain.Models.MailItem;
@@ -108,5 +109,13 @@ namespace Wino.Core.Domain.Interfaces
/// <param name="draftCreationOptions">Options like new email/forward/draft.</param>
/// <returns>Draft MailCopy and Draft MimeMessage as base64.</returns>
Task<(MailCopy draftMailCopy, string draftBase64MimeMessage)> CreateDraftAsync(Guid accountId, DraftCreationOptions draftCreationOptions);
/// <summary>
/// Returns ids
/// </summary>
/// <param name="folderId"></param>
/// <param name="uniqueIds"></param>
/// <returns></returns>
Task<List<MailCopy>> GetExistingMailsAsync(Guid folderId, IEnumerable<UniqueId> uniqueIds);
}
}

View File

@@ -5,6 +5,7 @@ namespace Wino.Core.Domain.Interfaces
public interface IProviderDetail
{
MailProviderType Type { get; }
SpecialImapProvider SpecialImapProvider { get; }
string Name { get; }
string Description { get; }
string ProviderImage { get; }

View File

@@ -0,0 +1,10 @@
using Wino.Core.Domain.Entities.Shared;
using Wino.Core.Domain.Models.Accounts;
namespace Wino.Core.Domain.Interfaces
{
public interface ISpecialImapProviderConfigResolver
{
CustomServerInformation GetServerInformation(MailAccount account, AccountCreationDialogResult dialogResult);
}
}

View File

@@ -7,5 +7,6 @@ namespace Wino.Core.Domain.Interfaces
{
Task<IWinoSynchronizerBase> GetAccountSynchronizerAsync(Guid accountId);
Task InitializeAsync();
Task DeleteSynchronizerAsync(Guid accountId);
}
}

View File

@@ -28,5 +28,12 @@ namespace Wino.Core.Domain.Interfaces
/// <param name="transferProgress">Optional progress reporting for download operation.</param>
/// <param name="cancellationToken">Cancellation token.</param>
Task DownloadMissingMimeMessageAsync(IMailItem mailItem, ITransferProgress transferProgress, CancellationToken cancellationToken = default);
/// <summary>
/// 1. Cancel active synchronization.
/// 2. Stop all running tasks.
/// 3. Dispose all resources.
/// </summary>
Task KillSynchronizerAsync();
}
}

View File

@@ -2,5 +2,5 @@
namespace Wino.Core.Domain.Models.Accounts
{
public record AccountCreationDialogResult(MailProviderType ProviderType, string AccountName, string AccountColorHex = "");
public record AccountCreationDialogResult(MailProviderType ProviderType, string AccountName, SpecialImapProviderDetails SpecialImapProviderDetails);
}

View File

@@ -6,18 +6,32 @@ namespace Wino.Core.Domain.Models.Accounts
public class ProviderDetail : IProviderDetail
{
public MailProviderType Type { get; }
public SpecialImapProvider SpecialImapProvider { get; }
public string Name { get; }
public string Description { get; }
public string ProviderImage => $"/Wino.Core.UWP/Assets/Providers/{Type}.png";
public string ProviderImage
{
get
{
if (SpecialImapProvider == SpecialImapProvider.None)
{
return $"/Wino.Core.UWP/Assets/Providers/{Type}.png";
}
else
{
return $"/Wino.Core.UWP/Assets/Providers/{SpecialImapProvider}.png";
}
}
}
public bool IsSupported => Type == MailProviderType.Outlook || Type == MailProviderType.Gmail || Type == MailProviderType.IMAP4;
public ProviderDetail(MailProviderType type)
public ProviderDetail(MailProviderType type, SpecialImapProvider specialImapProvider)
{
Type = type;
SpecialImapProvider = specialImapProvider;
switch (Type)
{
@@ -25,21 +39,29 @@ namespace Wino.Core.Domain.Models.Accounts
Name = "Outlook";
Description = "Outlook.com, Live.com, Hotmail, MSN";
break;
case MailProviderType.Office365:
Name = "Office 365";
Description = "Office 365, Exchange";
break;
case MailProviderType.Gmail:
Name = "Gmail";
Description = Translator.ProviderDetail_Gmail_Description;
break;
case MailProviderType.Yahoo:
Name = "Yahoo";
Description = "Yahoo Mail";
break;
case MailProviderType.IMAP4:
Name = Translator.ProviderDetail_IMAP_Title;
Description = Translator.ProviderDetail_IMAP_Description;
switch (specialImapProvider)
{
case SpecialImapProvider.None:
Name = Translator.ProviderDetail_IMAP_Title;
Description = Translator.ProviderDetail_IMAP_Description;
break;
case SpecialImapProvider.iCloud:
Name = Translator.ProviderDetail_iCloud_Title;
Description = Translator.ProviderDetail_iCloud_Description;
break;
case SpecialImapProvider.Yahoo:
Name = Translator.ProviderDetail_Yahoo_Title;
Description = Translator.ProviderDetail_Yahoo_Description;
break;
default:
break;
}
break;
}
}

View File

@@ -0,0 +1,6 @@
using Wino.Core.Domain.Enums;
namespace Wino.Core.Domain.Models.Accounts
{
public record SpecialImapProviderDetails(string Address, string Password, string SenderName, SpecialImapProvider SpecialImapProvider);
}

View File

@@ -0,0 +1,20 @@
using MailKit;
using MimeKit;
namespace Wino.Core.Domain.Models.MailItem
{
/// <summary>
/// Encapsulates all required information to create a MimeMessage for IMAP synchronizer.
/// </summary>
public class ImapMessageCreationPackage
{
public IMessageSummary MessageSummary { get; }
public MimeMessage MimeMessage { get; }
public ImapMessageCreationPackage(IMessageSummary messageSummary, MimeMessage mimeMessage)
{
MessageSummary = messageSummary;
MimeMessage = mimeMessage;
}
}
}

View File

@@ -9,7 +9,7 @@ namespace Wino.Core.Domain.Models.Synchronization
/// <summary>
/// Unique id of synchronization.
/// </summary>
public Guid Id { get; } = Guid.NewGuid();
public Guid Id { get; set; } = Guid.NewGuid();
/// <summary>
/// Account to execute synchronization for.
@@ -26,6 +26,12 @@ namespace Wino.Core.Domain.Models.Synchronization
/// </summary>
public List<Guid> SynchronizationFolderIds { get; set; }
/// <summary>
/// If true, additional folders like Sent,Drafts and Deleted will not be synchronized
/// with InboxOnly and CustomFolders sync type.
/// </summary>
public bool ExcludeMustHaveFolders { get; set; }
/// <summary>
/// When doing a linked inbox synchronization, we must ignore reporting completion to the caller for each folder.
/// This Id will help tracking that. Id is unique, but this one can be the same for all sync requests
@@ -33,6 +39,6 @@ namespace Wino.Core.Domain.Models.Synchronization
/// </summary>
public Guid? GroupedSynchronizationTrackingId { get; set; }
public override string ToString() => $"Type: {Type}, Folders: {(SynchronizationFolderIds == null ? "All" : string.Join(",", SynchronizationFolderIds))}";
public override string ToString() => $"Type: {Type}";
}
}

View File

@@ -403,6 +403,10 @@
"ProviderDetail_Gmail_Description": "Google Account",
"ProviderDetail_IMAP_Description": "Custom IMAP/SMTP server",
"ProviderDetail_IMAP_Title": "IMAP Server",
"ProviderDetail_Yahoo_Title": "Yahoo Mail",
"ProviderDetail_Yahoo_Description": "Yahoo Account",
"ProviderDetail_iCloud_Title": "iCloud",
"ProviderDetail_iCloud_Description": "Apple iCloud Account",
"ProtocolLogAvailable_Message": "Protocol logs are available for diagnostics.",
"Results": "Results",
"Right": "Right",