From 7b5596f3e5f2ee8ba73fe7e1fd79c5608d118b30 Mon Sep 17 00:00:00 2001 From: TekH Date: Wed, 12 Aug 2026 12:45:52 +0200 Subject: [PATCH] Refactor email fetching methods in Limilabs service Removed public methods `FetchEmailUidsAsync` and `FetchEmailByUidAsync` from `LimilabsImapEmailService` to simplify the public API. Refactored `FetchEmailUidsAsync` into a private static helper method that operates directly on an `Imap` instance. Removed exception handling logic specific to the removed methods. These changes aim to encapsulate email fetching functionality and streamline the service's design. --- .../Services/LimilabsImapEmailService.cs | 58 +------------------ 1 file changed, 1 insertion(+), 57 deletions(-) diff --git a/src/infrastructure/DigitalData.MessagingService.Infrastructure/Services/LimilabsImapEmailService.cs b/src/infrastructure/DigitalData.MessagingService.Infrastructure/Services/LimilabsImapEmailService.cs index ccbc0b3..b4077f2 100644 --- a/src/infrastructure/DigitalData.MessagingService.Infrastructure/Services/LimilabsImapEmailService.cs +++ b/src/infrastructure/DigitalData.MessagingService.Infrastructure/Services/LimilabsImapEmailService.cs @@ -79,62 +79,6 @@ public class LimilabsImapEmailService( } } - public async Task> FetchEmailUidsAsync( - EmailAccountDto account, - MailSearchFilter filter, - CancellationToken cancellationToken = default) - { - using var imap = await OpenAsync(account, filter.Folder); - try - { - List uids = await FetchEmailUidsAsync(imap, filter, cancellationToken); - - await imap.CloseAsync(cancellationToken); - return uids; - } - catch (Limilabs.Client.ServerException ex) - { - await imap.CloseSafelyAsync(); - throw new AuthenticationFailedException( - $"IMAP authentication failed for account '{account.Username}'.", ex); - } - catch (Exception ex) when (ex is not OperationCanceledException) - { - await imap.CloseSafelyAsync(); - throw new InvalidOperationException( - $"Failed to fetch email UIDs from IMAP server '{account.ImapServer}'.", ex); - } - } - - public async Task FetchEmailByUidAsync( - EmailAccountDto account, - long uid, - string folder = "INBOX", - bool withAttachments = false, - CancellationToken cancellationToken = default) - { - using var imap = await OpenAsync(account, folder); - try - { - var mail = await FetchEmailByUidAsync(imap, uid, withAttachments, cancellationToken); - - await imap.CloseAsync(cancellationToken); - return mail; - } - catch (Limilabs.Client.ServerException ex) - { - await imap.CloseSafelyAsync(); - throw new AuthenticationFailedException( - $"IMAP authentication failed for account '{account.Username}'.", ex); - } - catch (Exception ex) when (ex is not OperationCanceledException) - { - await imap.CloseSafelyAsync(); - Logger.LogWarning(ex, "Failed to fetch IMAP message UID={Uid} from folder {Folder}.", uid, folder); - return null; - } - } - public async Task MarkAsSeenAsync( EmailAccountDto account, long uid, @@ -162,7 +106,7 @@ public class LimilabsImapEmailService( } // Private helpers - private async Task> FetchEmailUidsAsync( + private static async Task> FetchEmailUidsAsync( Imap imap, MailSearchFilter filter, CancellationToken cancellationToken = default)