Remove HasAttachments filter; enhance FetchEmails response

The `MailSearchFilter` class was updated to remove the `HasAttachments` property, simplifying the filtering logic. Corresponding client-side filtering logic in `LimilabsImapEmailService` was also removed. The IMAP search query now defaults to `Expression.All` when no criteria are provided.

The `FetchEmails` method in `EmailController` was enhanced with a new optional `firstHtmlBodyOnly` parameter. This allows returning only the HTML body of the first email or a `404 Not Found` response if no emails match the criteria. These changes improve flexibility and simplify the codebase.
This commit is contained in:
2026-08-10 14:22:45 +02:00
parent 74ec00ddd3
commit ee279c407b
3 changed files with 10 additions and 12 deletions

View File

@@ -78,7 +78,8 @@ public class LimilabsImapEmailService(
}
// Get UIDs to fetch
List<long> uids = [.. await imap.SearchAsync(Expression.And([.. criterions]), cancellationToken)];
var searchExpression = criterions.Count > 0 ? Expression.And([.. criterions]) : Expression.All();
List<long> uids = [.. await imap.SearchAsync(searchExpression, cancellationToken)];
// Apply requested sort order
if (filter.SortOrder == MailSortOrder.NewestFirst)
@@ -99,10 +100,6 @@ public class LimilabsImapEmailService(
var mail = new MailBuilder().CreateFromEml(eml);
var flags = await imap.GetFlagsByUIDAsync(uid, cancellationToken);
// Client-side attachment filter — IMAP has no native criterion for this
if (filter.HasAttachments && mail.Attachments.Count == 0 && mail.Visuals.Count == 0)
continue;
results.Add(MapToContext(uid, mail, flags, filter.WithAttachments));
}
catch (Exception ex)