diff --git a/src/presentation/DigitalData.MessagingService.API/Controllers/EmailController.cs b/src/presentation/DigitalData.MessagingService.API/Controllers/EmailController.cs
index c6c9ce3..316bce6 100644
--- a/src/presentation/DigitalData.MessagingService.API/Controllers/EmailController.cs
+++ b/src/presentation/DigitalData.MessagingService.API/Controllers/EmailController.cs
@@ -87,23 +87,44 @@ public class EmailController(IMediator mediator) : ControllerBase
return NotFound("No emails found matching the specified criteria.");
if (firstHtmlBodyOnly && emails.FirstOrDefault()?.HtmlBody is string htmlBody)
- return Ok(htmlBody);
+ return Content(htmlBody, "text/html");
return Ok(emails);
}
+ ///
+ /// Fetch only the UIDs of emails matching the given filter from an IMAP mailbox.
+ ///
+ /// Query parameters for filtering emails.
+ /// Cancellation token.
+ /// HTTP 200 with the list of matching UIDs, or HTTP 404 if none found.
+ [HttpGet("uid")]
+ [ProducesResponseType(StatusCodes.Status200OK)]
+ [ProducesResponseType(StatusCodes.Status400BadRequest)]
+ [ProducesResponseType(StatusCodes.Status404NotFound)]
+ public async Task FetchEmailUids([FromQuery] FetchEmailUidsQuery query, CancellationToken cancellationToken = default)
+ {
+ var uids = await mediator.Send(query, cancellationToken);
+
+ if (!uids.Any())
+ return NotFound("No emails found matching the specified criteria.");
+
+ return Ok(uids);
+ }
+
///
/// Fetch a single email by its UID from an IMAP mailbox.
///
/// The unique identifier (UID) of the message.
/// Query parameters including account, folder and attachment flag.
+ ///
/// Cancellation token.
/// HTTP 200 with the matched email, or HTTP 404 if not found.
[HttpGet("{uid:long}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
- public async Task FetchEmailByUid([FromRoute] long uid, [FromQuery] FetchEmailByUidQuery query, CancellationToken cancellationToken = default)
+ public async Task FetchEmailByUid([FromRoute] long uid, [FromQuery] FetchEmailByUidQuery query, [FromQuery] bool htmlBodyOnly = false, CancellationToken cancellationToken = default)
{
var queryWithUid = query.WithUid(uid);
var email = await mediator.Send(queryWithUid, cancellationToken);
@@ -111,6 +132,9 @@ public class EmailController(IMediator mediator) : ControllerBase
if (email is null)
return NotFound($"No email found with UID {uid}.");
+ if (htmlBodyOnly)
+ return Content(email.HtmlBody, "text/html");
+
return Ok(email);
}