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)