Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Add email view modal for external API (#117)
Leendert de Borst05a2e3942c1f
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.mdindex f3e133b0e..45e149a28 100644--- a/CONTRIBUTING.md+++ b/CONTRIBUTING.md@@ -80,6 +80,7 @@ Here is an example file with the various options explained:```{"ApiUrl": "http://localhost:5092",+ "SmtpAllowedDomains": ["example.tld"],"UseDebugEncryptionKey": "true"}```diff --git a/src/AliasVault.Client/Main/Components/Email/EmailModal.razor b/src/AliasVault.Client/Main/Components/Email/EmailModal.razornew file mode 100644index 000000000..62c9497b7--- /dev/null+++ b/src/AliasVault.Client/Main/Components/Email/EmailModal.razor@@ -0,0 +1,81 @@+@using AliasVault.Client.Main.Models.Spamok++<div class="fixed inset-0 z-50 overflow-auto bg-gray-500 bg-opacity-75 flex items-center justify-center">+ <div class="relative p-8 bg-white w-full max-w-md flex-col flex rounded-lg shadow-xl">+ <div class="flex items-center justify-between">+ <h2 class="text-2xl font-bold text-gray-900 dark:text-white"><a target="_blank" href="https://spamok.com/@(Email!.ToLocal)/@(Email!.Id)">@Email?.Subject</a></h2>+ <button @onclick="Close" class="text-gray-400 hover:text-gray-500">+ <svg class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/>+ </svg>+ </button>+ </div>+ <div class="mt-4">+ <p class="text-sm text-gray-500 dark:text-gray-400">From: @Email?.FromDisplay</p>+ <p class="text-sm text-gray-500 dark:text-gray-400">Date: @Email?.DateSystem</p>+ </div>+ <div class="mt-4 text-gray-700 dark:text-gray-300">+ <div>+ <iframe class="w-full h-[700px]" srcdoc="@(EmailBody ?? "<div>This email has no HTML content.</div>")">+ </iframe>+ </div>+ </div>+ <div class="mt-6 flex justify-end">+ <button @onclick="Close" class="px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600">Close</button>+ </div>+ </div>+</div>++@code {+ /// <summary>+ /// The email to show in the modal.+ /// </summary>+ [Parameter]+ public EmailApiModel? Email { get; set; }++ /// <summary>+ /// Callback when the modal is closed.+ /// </summary>+ [Parameter]+ public EventCallback<bool> OnClose { get; set; }++ /// <summary>+ /// The message body to display+ /// </summary>+ private string EmailBody = string.Empty;++ /// <inheritdoc />+ protected override async Task OnInitializedAsync()+ {+ await base.OnInitializedAsync();++ // Determine email body+ if (Email != null)+ {+ // Check if there is HTML content, if not, then set default viewtype to plain+ if (Email.MessageHtml is not null && !string.IsNullOrWhiteSpace(Email.MessageHtml))+ {+ // No HTML is available+ EmailBody = Email.MessageHtml;+ }+ else if (Email.MessagePlain is not null)+ {+ // HTML is available+ EmailBody = Email.MessagePlain;+ }+ else+ {+ // No HTML is available+ EmailBody = "[This email has no body.]";+ }+ }+ }++ /// <summary>+ /// Close the modal.+ /// </summary>+ private Task Close()+ {+ return OnClose.InvokeAsync(false);+ }+}diff --git a/src/AliasVault.Client/Main/Components/Email/RecentEmails.razor b/src/AliasVault.Client/Main/Components/Email/RecentEmails.razorindex acba2eb0a..71c1b72a0 100644--- a/src/AliasVault.Client/Main/Components/Email/RecentEmails.razor+++ b/src/AliasVault.Client/Main/Components/Email/RecentEmails.razor@@ -2,6 +2,11 @@@inherits ComponentBase@inject IHttpClientFactory HttpClientFactory+@if (EmailModalVisible)+{+ <EmailModal Email="@Email" OnClose="CloseEmailModal" />+}+@if (ShowComponent){<div class="p-4 mb-4 bg-white border border-gray-200 rounded-lg shadow-sm 2xl:col-span-2 dark:border-gray-700 sm:p-6 dark:bg-gray-800">@@ -42,10 +47,10 @@{<tr class="hover:bg-gray-50 dark:hover:bg-gray-600"><td class="p-4 text-sm font-normal text-gray-900 whitespace-nowrap dark:text-white">- <a target="_blank" href="https://spamok.com/@mail.ToLocal/@mail.Id">@(mail.Subject.Substring(0, mail.Subject.Length > 30 ? 30 : mail.Subject.Length))...</a>+ <span class="cursor-pointer" @onclick="() => OpenEmail(mail.Id)">@(mail.Subject.Substring(0, mail.Subject.Length > 30 ? 30 : mail.Subject.Length))...</span></td><td class="p-4 text-sm font-normal text-gray-500 whitespace-nowrap dark:text-gray-400">- <a target="_blank" href="https://spamok.com/@mail.ToLocal/@mail.Id">@mail.DateSystem</a>+ <span class="cursor-pointer" @onclick="() => OpenEmail(mail.Id)">@mail.DateSystem</span></td></tr>}@@ -64,11 +69,13 @@/// The email address to show recent emails for./// </summary>[Parameter]- public string Email { get; set; } = string.Empty;+ public string EmailAddress { get; set; } = string.Empty;private List<MailboxEmailApiModel> MailboxEmails { get; set; } = new();private bool IsLoading { get; set; } = true;private bool ShowComponent { get; set; } = false;+ private EmailApiModel Email { get; set; } = new();+ private bool EmailModalVisible { get; set; }/// <inheritdoc />protected override async Task OnInitializedAsync()@@ -76,7 +83,7 @@await base.OnInitializedAsync();// Check if email has a known SpamOK domain, if not, don't show this component.- if (Email.EndsWith("@landmail.nl"))+ if (EmailAddress.EndsWith("@landmail.nl")){ShowComponent = true;}@@ -109,17 +116,47 @@StateHasChanged();// Get email prefix, which is the part before the @ symbol.- string emailPrefix = Email.Split('@')[0];+ string emailPrefix = EmailAddress.Split('@')[0];var client = HttpClientFactory.CreateClient("EmailClient");MailboxApiModel? mailbox = await client.GetFromJsonAsync<MailboxApiModel>($"https://api.spamok.com/v2/EmailBox/{emailPrefix}");if (mailbox?.Mails != null){- MailboxEmails = mailbox.Mails;+ // Show maximum of 10 recent emails.+ MailboxEmails = mailbox.Mails.Take(10).ToList();}IsLoading = false;StateHasChanged();}++ /// <summary>+ /// Open the email modal.+ /// </summary>+ private async Task OpenEmail(int emailId)+ {+ // Get email prefix, which is the part before the @ symbol.+ string emailPrefix = EmailAddress.Split('@')[0];++ // Load email from API+ var client = HttpClientFactory.CreateClient("EmailClient");+ EmailApiModel? mail = await client.GetFromJsonAsync<EmailApiModel>($"https://api.spamok.com/v2/Email/{emailPrefix}/{emailId}");++ if (mail != null)+ {+ Email = mail;+ EmailModalVisible = true;+ StateHasChanged();+ }+ }++ /// <summary>+ /// Close the email modal.+ /// </summary>+ private void CloseEmailModal()+ {+ EmailModalVisible = false;+ StateHasChanged();+ }}diff --git a/src/AliasVault.Client/Main/Pages/Credentials/View.razor b/src/AliasVault.Client/Main/Pages/Credentials/View.razorindex 43fb63592..63515cb8c 100644--- a/src/AliasVault.Client/Main/Pages/Credentials/View.razor+++ b/src/AliasVault.Client/Main/Pages/Credentials/View.razor@@ -42,7 +42,7 @@ else</div></div></div>- <RecentEmails Email="@Alias.Alias.Email" />+ <RecentEmails EmailAddress="@Alias.Alias.Email" />@if (Alias.Notes != null && Alias.Notes.Length > 0){<div class="p-4 mb-4 bg-white border border-gray-200 rounded-lg shadow-sm 2xl:col-span-2 dark:border-gray-700 sm:p-6 dark:bg-gray-800">diff --git a/src/AliasVault.Client/package-lock.json b/src/AliasVault.Client/package-lock.jsonindex 3c29e29e9..f15dcd52a 100644--- a/src/AliasVault.Client/package-lock.json+++ b/src/AliasVault.Client/package-lock.json@@ -1,11 +1,11 @@{- "name": "AliasVault.Client",+ "name": "aliasvault.client","version": "1.0.0","lockfileVersion": 3,"requires": true,"packages": {"": {- "name": "AliasVault.Client",+ "name": "aliasvault.client","version": "1.0.0","license": "ISC","dependencies": {diff --git a/src/AliasVault.Client/wwwroot/css/tailwind.css b/src/AliasVault.Client/wwwroot/css/tailwind.cssindex 661759319..2e58d1d8b 100644--- a/src/AliasVault.Client/wwwroot/css/tailwind.css+++ b/src/AliasVault.Client/wwwroot/css/tailwind.css@@ -795,6 +795,10 @@ video {height: 2.25rem;}+.h-\[700px\] {+ height: 700px;+}+.h-full {height: 100%;}@@ -1017,6 +1021,10 @@ video {align-self: center;}+.overflow-auto {+ overflow: auto;+}+.overflow-hidden {overflow: hidden;}@@ -1087,6 +1095,11 @@ video {border-color: rgb(34 197 94 / var(--tw-border-opacity));}+.bg-blue-500 {+ --tw-bg-opacity: 1;+ background-color: rgb(59 130 246 / var(--tw-bg-opacity));+}+.bg-blue-600 {--tw-bg-opacity: 1;background-color: rgb(37 99 235 / var(--tw-bg-opacity));@@ -1132,6 +1145,11 @@ video {background-color: rgb(22 163 74 / var(--tw-bg-opacity));}+.bg-primary-200 {+ --tw-bg-opacity: 1;+ background-color: rgb(251 203 116 / var(--tw-bg-opacity));+}+.bg-primary-600 {--tw-bg-opacity: 1;background-color: rgb(214 131 56 / var(--tw-bg-opacity));@@ -1157,10 +1175,19 @@ video {background-color: rgb(255 255 255 / var(--tw-bg-opacity));}+.bg-gray-500 {+ --tw-bg-opacity: 1;+ background-color: rgb(107 114 128 / var(--tw-bg-opacity));+}+.bg-opacity-50 {--tw-bg-opacity: 0.5;}+.bg-opacity-75 {+ --tw-bg-opacity: 0.75;+}+.fill-primary-600 {fill: #d68338;}@@ -1483,6 +1510,11 @@ video {transition-duration: 300ms;}+.hover\:bg-blue-600:hover {+ --tw-bg-opacity: 1;+ background-color: rgb(37 99 235 / var(--tw-bg-opacity));+}+.hover\:bg-blue-700:hover {--tw-bg-opacity: 1;background-color: rgb(29 78 216 / var(--tw-bg-opacity));@@ -1533,6 +1565,11 @@ video {background-color: rgb(153 27 27 / var(--tw-bg-opacity));}+.hover\:text-gray-500:hover {+ --tw-text-opacity: 1;+ color: rgb(107 114 128 / var(--tw-text-opacity));+}+.hover\:text-gray-900:hover {--tw-text-opacity: 1;color: rgb(17 24 39 / var(--tw-text-opacity));diff --git a/src/Databases/AliasServerDb/Migrations/20240729142520_AddEncryptionKeyTables.Designer.cs b/src/Databases/AliasServerDb/Migrations/20240729150925_AddEncryptionKeyTables.Designer.cssimilarity index 99%rename from src/Databases/AliasServerDb/Migrations/20240729142520_AddEncryptionKeyTables.Designer.csrename to src/Databases/AliasServerDb/Migrations/20240729150925_AddEncryptionKeyTables.Designer.csindex c88bc6263..b3aba7713 100644--- a/src/Databases/AliasServerDb/Migrations/20240729142520_AddEncryptionKeyTables.Designer.cs+++ b/src/Databases/AliasServerDb/Migrations/20240729150925_AddEncryptionKeyTables.Designer.cs@@ -11,7 +11,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;namespace AliasServerDb.Migrations{[DbContext(typeof(AliasServerDbContext))]- [Migration("20240729142520_AddEncryptionKeyTables")]+ [Migration("20240729150925_AddEncryptionKeyTables")]partial class AddEncryptionKeyTables{/// <inheritdoc />@@ -421,6 +421,9 @@ namespace AliasServerDb.Migrationsb.HasKey("Id");+ b.HasIndex("Address")+ .IsUnique();+b.HasIndex("UserId");b.ToTable("UserEmailClaims");diff --git a/src/Databases/AliasServerDb/Migrations/20240729142520_AddEncryptionKeyTables.cs b/src/Databases/AliasServerDb/Migrations/20240729150925_AddEncryptionKeyTables.cssimilarity index 96%rename from src/Databases/AliasServerDb/Migrations/20240729142520_AddEncryptionKeyTables.csrename to src/Databases/AliasServerDb/Migrations/20240729150925_AddEncryptionKeyTables.csindex 371fe7ff6..eeae4f616 100644--- a/src/Databases/AliasServerDb/Migrations/20240729142520_AddEncryptionKeyTables.cs+++ b/src/Databases/AliasServerDb/Migrations/20240729150925_AddEncryptionKeyTables.cs@@ -80,6 +80,12 @@ namespace AliasServerDb.Migrationstable: "Emails",column: "UserEncryptionKeyId");+ migrationBuilder.CreateIndex(+ name: "IX_UserEmailClaims_Address",+ table: "UserEmailClaims",+ column: "Address",+ unique: true);+migrationBuilder.CreateIndex(name: "IX_UserEmailClaims_UserId",table: "UserEmailClaims",diff --git a/src/Databases/AliasServerDb/Migrations/AliasServerDbContextModelSnapshot.cs b/src/Databases/AliasServerDb/Migrations/AliasServerDbContextModelSnapshot.csindex 61a524f27..b6a9df86f 100644--- a/src/Databases/AliasServerDb/Migrations/AliasServerDbContextModelSnapshot.cs+++ b/src/Databases/AliasServerDb/Migrations/AliasServerDbContextModelSnapshot.cs@@ -418,6 +418,9 @@ namespace AliasServerDb.Migrationsb.HasKey("Id");+ b.HasIndex("Address")+ .IsUnique();+b.HasIndex("UserId");b.ToTable("UserEmailClaims");diff --git a/src/Databases/AliasServerDb/UserEmailClaim.cs b/src/Databases/AliasServerDb/UserEmailClaim.csindex 4392bfbc4..a9fe28613 100644--- a/src/Databases/AliasServerDb/UserEmailClaim.cs+++ b/src/Databases/AliasServerDb/UserEmailClaim.cs@@ -4,14 +4,17 @@// Licensed under the MIT license. See LICENSE.md file in the project root for full license information.// </copyright>//-----------------------------------------------------------------------+namespace AliasServerDb;using System.ComponentModel.DataAnnotations;using System.ComponentModel.DataAnnotations.Schema;+using Microsoft.EntityFrameworkCore;/// <summary>/// UserEmailClaim object. This object is used to reserve an email address for a user./// </summary>+[Index(nameof(Address), IsUnique = true)]public class UserEmailClaim{/// <summary>