using System; 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; namespace Wino.Core.Domain.Interfaces; public interface IMailService { Task GetSingleMailItemAsync(string mailCopyId, string remoteFolderId); Task GetSingleMailItemAsync(Guid uniqueMailId); /// /// Returns the single mail item with the given mail copy id. /// Caution: This method is not safe. Use other overrides. /// /// /// Task GetSingleMailItemAsync(string mailCopyId); Task> FetchMailsAsync(MailListInitializationOptions options, CancellationToken cancellationToken = default); /// /// Deletes all mail copies for all folders. /// /// Account to remove from /// Mail copy id to remove. Task DeleteMailAsync(Guid accountId, string mailCopyId); Task ChangeReadStatusAsync(string mailCopyId, bool isRead); Task ChangeFlagStatusAsync(string mailCopyId, bool isFlagged); Task CreateAssignmentAsync(Guid accountId, string mailCopyId, string remoteFolderId); Task DeleteAssignmentAsync(Guid accountId, string mailCopyId, string remoteFolderId); Task CreateMailAsync(Guid accountId, NewMailItemPackage package); /// /// Maps new mail item with the existing local draft copy. /// In case of failure, it returns false. /// Then synchronizers must insert a new mail item. /// /// Id of the account. It's important to map to the account since if the user use the same account with different providers, this call must map the correct one. /// UniqueId of the local draft copy. /// New assigned remote mail item id. /// New assigned draft id if exists. /// New message's thread/conversation id. /// True if mapping is done. False if local copy doesn't exists. Task MapLocalDraftAsync(Guid accountId, Guid localDraftCopyUniqueId, string newMailCopyId, string newDraftId, string newThreadId); /// /// Maps new mail item with the existing local draft copy. /// /// /// /// Task MapLocalDraftAsync(string newMailCopyId, string newDraftId, string newThreadId); Task UpdateMailAsync(MailCopy mailCopy); /// /// Gets the new inserted unread mails after the synchronization. /// /// Account id. /// /// Mail ids that synchronizer tried to download. If there was an issue with the /// Items that tried and actually downloaded may differ. This function will return only new inserted ones. /// /// Newly inserted unread mails inside the Inbox folder. Task> GetDownloadedUnreadMailsAsync(Guid accountId, IEnumerable downloadedMailCopyIds); /// /// Returns the account that this mail copy unique id is assigned. /// Used in toast notification handler. /// /// Unique id of the mail item. /// Account that mail belongs to. Task GetMailAccountByUniqueIdAsync(Guid uniqueMailId); /// /// Checks whether the given mail copy id exists in the database. /// Safely used for Outlook to prevent downloading the same mail twice. /// For Gmail, it should be avoided since one mail may belong to multiple folders. /// /// Native mail id of the message. Task IsMailExistsAsync(string mailCopyId); /// /// Returns all mails for given folder id. /// /// Folder id to get mails for Task> GetMailsByFolderIdAsync(Guid folderId); /// /// Returns all unread mails for given folder id. /// /// Folder id to get unread mails for. Task> GetUnreadMailsByFolderIdAsync(Guid folderId); /// /// Checks whether the mail exists in the folder. /// When deciding Create or Update existing mail, we need to check if the mail exists in the folder. /// /// MailCopy id /// Folder's local id. /// Whether mail exists in the folder or not. Task IsMailExistsAsync(string mailCopyId, Guid folderId); /// /// Creates a draft MailCopy and MimeMessage based on the given options. /// For forward/reply it would include the referenced message. /// /// AccountId which should have new draft. /// Options like new email/forward/draft. /// Draft MailCopy and Draft MimeMessage as base64. Task<(MailCopy draftMailCopy, string draftBase64MimeMessage)> CreateDraftAsync(Guid accountId, DraftCreationOptions draftCreationOptions); /// /// Returns ids /// /// /// /// Task> GetExistingMailsAsync(Guid folderId, IEnumerable uniqueIds); /// /// Creates a new mail from a package without doing any existence check. /// Use it with caution. /// /// Account that mail belongs to. /// Assigned folder. /// Mail creation package. /// Task CreateMailRawAsync(MailAccount account, MailItemFolder mailItemFolder, NewMailItemPackage package); /// /// Checks whether the account has any draft mail locally. /// /// Account id. Task HasAccountAnyDraftAsync(Guid accountId); /// /// Compares the ids returned from online search result for Archive folder against the local database. /// /// Archive folder id. /// Retrieved MailCopy ids from search result. /// Result model that contains added and removed mail copy ids. Task GetGmailArchiveComparisonResultAsync(Guid archiveFolderId, List onlineArchiveMailIds); }