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.
This commit is contained in:
2026-08-12 12:45:52 +02:00
parent 5d3997b7e1
commit 7b5596f3e5

View File

@@ -79,62 +79,6 @@ public class LimilabsImapEmailService(
}
}
public async Task<IEnumerable<long>> FetchEmailUidsAsync(
EmailAccountDto account,
MailSearchFilter filter,
CancellationToken cancellationToken = default)
{
using var imap = await OpenAsync(account, filter.Folder);
try
{
List<long> 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<ReceivedEmailContext?> 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<List<long>> FetchEmailUidsAsync(
private static async Task<List<long>> FetchEmailUidsAsync(
Imap imap,
MailSearchFilter filter,
CancellationToken cancellationToken = default)