Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Merge branch 'main' into 188-add-email-anchor-tags-translation-to-open-in-new-tabs-instead-of-iframe
Leendert de Borstb0c74d3ce238
diff --cc src/AliasVault.Api/Controllers/Email/EmailController.csindex 2bf1b9685,dc9ef851e..0022e662b--- a/src/AliasVault.Api/Controllers/Email/EmailController.cs+++ b/src/AliasVault.Api/Controllers/Email/EmailController.cs@@@ -58,8 -43,9 +43,8 @@@ public class EmailController(ILogger<Vavar returnEmail = new EmailApiModel{- Id = email.Id,+ Id = email!.Id,Subject = email.Subject,- FromDisplay = ConversionHelper.ConvertFromToFromDisplay(email.From),FromDomain = email.FromDomain,FromLocal = email.FromLocal,ToDomain = email.ToDomain,@@@ -85,6 -71,83 +70,77 @@@returnEmail.Attachments = attachments;- // Enrich HTML by changing all anchor tags to open in new tab- if (returnEmail.MessageHtml != null && !string.IsNullOrEmpty(email.MessageHtml))- {- returnEmail.MessageHtml = ConversionHelper.ConvertAnchorTagsToOpenInNewTab(email.MessageHtml);- }-return Ok(returnEmail);}++ /// <summary>+ /// Deletes an email for the current user.+ /// </summary>+ /// <param name="id">The email ID to delete.</param>+ /// <returns>A response indicating the success or failure of the deletion.</returns>+ [HttpDelete(template: "{id}", Name = "DeleteEmail")]+ public async Task<IActionResult> DeleteEmail(int id)+ {+ await using var context = await dbContextFactory.CreateDbContextAsync();++ var (email, errorResult) = await AuthenticateAndRetrieveEmailAsync(id, context);+ if (errorResult != null)+ {+ return errorResult;+ }++ // Delete associated attachments+ context.EmailAttachments.RemoveRange(email!.Attachments);++ // Delete the email+ context.Emails.Remove(email);++ try+ {+ await context.SaveChangesAsync();+ return Ok();+ }+ catch (Exception ex)+ {+ // Log the exception+ logger.LogError(ex, "An error occurred while deleting email with ID {id}.", id);+ return StatusCode(500, $"An error occurred while deleting the email: {ex.Message}");+ }+ }++ /// <summary>+ /// Authenticates the user and retrieves the requested email.+ /// </summary>+ /// <param name="id">The email ID to retrieve.</param>+ /// <param name="context">The database context.</param>+ /// <returns>A tuple containing the authenticated user, the email, and an IActionResult if there's an error.</returns>+ private async Task<(Email? Email, IActionResult? ErrorResult)> AuthenticateAndRetrieveEmailAsync(int id, AliasServerDbContext context)+ {+ var user = await GetCurrentUserAsync();+ if (user is null)+ {+ return (null, Unauthorized("Not authenticated."));+ }++ // Retrieve email from database.+ var email = await context.Emails+ .Include(x => x.Attachments)+ .FirstOrDefaultAsync(x => x.Id == id);++ if (email is null)+ {+ return (null, NotFound("Email not found."));+ }++ // See if this user has a valid claim to the email address.+ var emailClaim = await context.UserEmailClaims+ .FirstOrDefaultAsync(x => x.UserId == user.Id && x.Address == email.To);++ if (emailClaim is null)+ {+ return (null, Unauthorized("User does not have a claim to this email address."));+ }++ return (email, null);+ }}diff --cc src/AliasVault.Client/Main/Components/Email/EmailModal.razorindex 14dd4abd0,ab6a89277..a2053e68f--- a/src/AliasVault.Client/Main/Components/Email/EmailModal.razor+++ b/src/AliasVault.Client/Main/Components/Email/EmailModal.razor@@@ -1,6 -1,8 +1,9 @@@@using AliasVault.Shared.Models.Spamok+@using AliasVault.Shared.Utilities@inject JsInteropService JsInteropService+ @inject GlobalNotificationService GlobalNotificationService+ @inject IHttpClientFactory HttpClientFactory+ @inject HttpClient HttpClient<ClickOutsideHandler OnClose="OnClose" ContentId="emailModal"><div class="fixed inset-0 z-50 overflow-auto bg-gray-500 bg-opacity-75 flex items-center justify-center">diff --cc src/Tests/AliasVault.E2ETests/Tests/Client/EmailDecryptionTests.csindex 96a7e4f8e,1da33a210..ddfa98529--- a/src/Tests/AliasVault.E2ETests/Tests/Client/EmailDecryptionTests.cs+++ b/src/Tests/AliasVault.E2ETests/Tests/Client/EmailDecryptionTests.cs@@@ -121,9 -109,15 +122,19 @@@ public class EmailDecryptionTests : Cliawait Page.Locator("text=" + textSubject).First.ClickAsync();await WaitForUrlAsync("emails**", "Delete");+ // Assert that the anchor tag in the email iframe has target="_blank" attribute.+ var anchorTag = await Page.Locator("iframe").First.GetAttributeAsync("srcdoc");+ Assert.That(anchorTag, Does.Contain("target=\"_blank\""), "Anchor tag in email iframe does not have target=\"_blank\" attribute. Check email decryption logic.");+++ // Click the delete button to delete the email.+ await Page.Locator("id=delete-email").First.ClickAsync();++ // Wait for the email delete confirm message to show up.+ await WaitForUrlAsync("emails**", "Email deleted successfully");++ // Assert that the email is no longer visible on the page.+ var body = await Page.TextContentAsync("body");+ Assert.That(body, Does.Not.Contain(textSubject), "Email not deleted from page after deletion. Check email deletion logic.");}/// <summary>