Add support for optional email attachments fetching
Introduced a `withAttachments` parameter to the `FetchEmailsAsync` method in `IImapEmailService` and related layers, allowing callers to include or exclude attachment data when fetching emails. Updated `FetchEmailsQuery` and `FetchEmailsQueryHandler` to propagate this parameter. Refactored `LimilabsImapEmailService` to conditionally process attachments and inline visuals based on the `withAttachments` flag, improving performance when attachments are not required. Replaced `Flag.Unseen` with `Expression.HasFlag(Flag.Unseen)` for better criteria handling. Cleaned up attachment-processing logic for improved readability and maintainability.
This commit is contained in:
@@ -13,10 +13,12 @@ public interface IImapEmailService
|
||||
/// </summary>
|
||||
/// <param name="account">Account whose IMAP settings will be used.</param>
|
||||
/// <param name="filter">Filter to apply when fetching emails.</param>
|
||||
/// <param name="withAttachments">When <see langword="true"/>, attachment data is included in the results; otherwise attachments are omitted. Defaults to <see langword="false"/>.</param>
|
||||
/// <param name="cancellationToken">Cancellation token.</param>
|
||||
Task<IEnumerable<ReceivedEmailContext>> FetchEmailsAsync(
|
||||
EmailAccountDto account,
|
||||
MailSearchFilter filter,
|
||||
bool withAttachments = false,
|
||||
CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -21,6 +21,12 @@ public record FetchEmailsQuery : IRequest<IEnumerable<ReceivedEmailContext>>
|
||||
/// Mail query used to filter and limit the emails retrieved.
|
||||
/// </summary>
|
||||
public MailSearchFilter Mail { get; init; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// When <see langword="true"/>, attachment data is included in the results; otherwise attachments are omitted.
|
||||
/// Defaults to <see langword="false"/>.
|
||||
/// </summary>
|
||||
public bool WithAttachments { get; init; } = false;
|
||||
}
|
||||
|
||||
public class FetchEmailsQueryHandler(
|
||||
@@ -40,6 +46,7 @@ public class FetchEmailsQueryHandler(
|
||||
return await ImapService.FetchEmailsAsync(
|
||||
account,
|
||||
request.Mail,
|
||||
request.WithAttachments,
|
||||
cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user