Refactor IMAP email fetching to use SearchFilter
Replaced individual parameters (`folder`, `unseenOnly`, `maxCount`) in `IImapEmailService` with a consolidated `SearchFilter` object to simplify method signatures and improve maintainability. Renamed `MailQuery` to `SearchFilter` in `FetchEmailsQuery` for better clarity. Updated `FetchEmailsQueryHandler` and `LimilabsImapEmailService` to use the new `SearchFilter` object, ensuring consistent handling of folder selection, unread message filtering, and message count limits. Improved logging in `LimilabsImapEmailService` to reflect the updated `SearchFilter` structure.
This commit is contained in:
@@ -11,15 +11,11 @@ public interface IImapEmailService
|
||||
/// Fetches emails from the specified mailbox folder.
|
||||
/// </summary>
|
||||
/// <param name="account">Account whose IMAP settings will be used.</param>
|
||||
/// <param name="folder">Mailbox folder name (e.g. "INBOX"). Defaults to INBOX.</param>
|
||||
/// <param name="unseenOnly">When <see langword="true"/> returns only unread messages.</param>
|
||||
/// <param name="maxCount">Maximum number of messages to retrieve (most-recent first). 0 = unlimited.</param>
|
||||
/// <param name="filter">Filter to apply when fetching emails.</param>
|
||||
/// <param name="cancellationToken">Cancellation token.</param>
|
||||
Task<IEnumerable<ReceivedEmailContext>> FetchEmailsAsync(
|
||||
EmailAccountDto account,
|
||||
string folder = "INBOX",
|
||||
bool unseenOnly = false,
|
||||
int maxCount = 50,
|
||||
FetchEmailsQuery.SearchFilter filter,
|
||||
CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -19,9 +19,9 @@ public record FetchEmailsQuery : IRequest<IEnumerable<ReceivedEmailContext>>
|
||||
/// <summary>
|
||||
/// Mail query used to filter and limit the emails retrieved.
|
||||
/// </summary>
|
||||
public MailQuery Mail { get; init; } = new();
|
||||
public SearchFilter Mail { get; init; } = new();
|
||||
|
||||
public record MailQuery
|
||||
public record SearchFilter
|
||||
{
|
||||
/// <summary>
|
||||
/// Mailbox folder to read from (default: "INBOX").
|
||||
@@ -56,9 +56,7 @@ public class FetchEmailsQueryHandler(
|
||||
|
||||
return await ImapService.FetchEmailsAsync(
|
||||
account,
|
||||
request.Mail.Folder,
|
||||
request.Mail.UnseenOnly,
|
||||
request.Mail.MaxCount,
|
||||
request.Mail,
|
||||
cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user