Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Separate email models (#2159)

Leendert de Borst1669bbb38d9b
diff --git a/apps/browser-extension/src/utils/dist/core/models/webapi/index.d.ts b/apps/browser-extension/src/utils/dist/core/models/webapi/index.d.ts
index baebb60e1..c64316ad6 100644
--- a/apps/browser-extension/src/utils/dist/core/models/webapi/index.d.ts
+++ b/apps/browser-extension/src/utils/dist/core/models/webapi/index.d.ts
@@ -211,12 +211,18 @@ type EmailAttachment = {
};
type Email = {
- /** The body of the email message */
- messageHtml: string;
- /** The plain text body of the email message */
- messagePlain: string;
- /** The raw RFC 822 source of the email message */
+ /** The body of the email message. Null for source-only stored emails: derive it by parsing the source */
+ messageHtml: string | null;
+ /** The plain text body of the email message. Null for source-only stored emails: derive it by parsing the source */
+ messagePlain: string | null;
+ /**
+ * The raw RFC 822 source of the email message (ciphertext, base64). For source-only stored emails the
+ * decrypted plaintext is gzip-compressed and starts with the gzip magic bytes 0x1f 0x8b; parse the
+ * (decompressed) source to derive the bodies and attachments.
+ */
messageSource: string;
+ /** The number of attachments contained in the email message */
+ attachmentCount: number;
/** The ID of the email */
id: number;
/** The subject of the email */
diff --git a/apps/server/AliasVault.Api/Controllers/V1/Email/EmailBoxController.cs b/apps/server/AliasVault.Api/Controllers/V1/Email/EmailBoxController.cs
index 5c860ad15..15369a035 100644
--- a/apps/server/AliasVault.Api/Controllers/V1/Email/EmailBoxController.cs
+++ b/apps/server/AliasVault.Api/Controllers/V1/Email/EmailBoxController.cs
@@ -10,7 +10,6 @@ namespace AliasVault.Api.Controllers.V1.Email;
using AliasServerDb;
using AliasVault.Api.Controllers.Abstracts;
using AliasVault.Auth.IpAddress;
-using AliasVault.Shared.Models.Spamok;
using AliasVault.Shared.Models.WebApi;
using AliasVault.Shared.Models.WebApi.V1.Email;
using Asp.Versioning;
diff --git a/apps/server/AliasVault.Api/Controllers/V1/Email/EmailController.cs b/apps/server/AliasVault.Api/Controllers/V1/Email/EmailController.cs
index 45c5a7b62..e872fe665 100644
--- a/apps/server/AliasVault.Api/Controllers/V1/Email/EmailController.cs
+++ b/apps/server/AliasVault.Api/Controllers/V1/Email/EmailController.cs
@@ -10,7 +10,7 @@ namespace AliasVault.Api.Controllers.V1.Email;
using AliasServerDb;
using AliasVault.Api.Controllers.Abstracts;
using AliasVault.Auth.IpAddress;
-using AliasVault.Shared.Models.Spamok;
+using AliasVault.Shared.Models.WebApi.V1.Email;
using Asp.Versioning;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
@@ -57,7 +57,6 @@ public class EmailController(ILogger<EmailController> logger, IAliasServerDbCont
MessageHtml = email.MessageHtml,
MessagePlain = email.MessagePlain,
MessageSource = email.MessageSourceBytes is not null ? Convert.ToBase64String(email.MessageSourceBytes) : email.MessageSource,
- AttachmentCount = email.AttachmentCount,
EncryptedSymmetricKey = personalWrap!.EncryptedSymmetricKey,
EncryptionKey = personalWrap.EncryptionKey.PublicKey,
};
diff --git a/apps/server/AliasVault.Api/Controllers/V2/Email/EmailController.cs b/apps/server/AliasVault.Api/Controllers/V2/Email/EmailController.cs
index 894b1651c..fdc50ad70 100644
--- a/apps/server/AliasVault.Api/Controllers/V2/Email/EmailController.cs
+++ b/apps/server/AliasVault.Api/Controllers/V2/Email/EmailController.cs
@@ -16,7 +16,6 @@ using Asp.Versioning;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
-using AttachmentApiModel = AliasVault.Shared.Models.Spamok.AttachmentApiModel;
/// <summary>
/// Email controller for retrieving emails from the database.
diff --git a/apps/server/Shared/AliasVault.Shared/Models/Spamok/AttachmentApiModel.cs b/apps/server/Shared/AliasVault.Shared/Models/Spamok/AttachmentApiModel.cs
index fc6254605..c232a083e 100644
--- a/apps/server/Shared/AliasVault.Shared/Models/Spamok/AttachmentApiModel.cs
+++ b/apps/server/Shared/AliasVault.Shared/Models/Spamok/AttachmentApiModel.cs
@@ -8,7 +8,7 @@
namespace AliasVault.Shared.Models.Spamok;
/// <summary>
-/// Represents an attachment for an email.
+/// Represents an attachment for an email of the external api.spamok.com API.
/// </summary>
public class AttachmentApiModel
{
diff --git a/apps/server/Shared/AliasVault.Shared/Models/Spamok/Base/EmailApiModelBase.cs b/apps/server/Shared/AliasVault.Shared/Models/Spamok/Base/EmailApiModelBase.cs
index 290e5f48d..412cd05a5 100644
--- a/apps/server/Shared/AliasVault.Shared/Models/Spamok/Base/EmailApiModelBase.cs
+++ b/apps/server/Shared/AliasVault.Shared/Models/Spamok/Base/EmailApiModelBase.cs
@@ -8,7 +8,7 @@
namespace AliasVault.Shared.Models.Spamok.Base;
/// <summary>
-/// Represents a mailbox email API model base.
+/// Represents a mailbox email API model base of the external api.spamok.com API.
/// </summary>
public abstract class EmailApiModelBase
{
diff --git a/apps/server/Shared/AliasVault.Shared/Models/Spamok/EmailApiModel.cs b/apps/server/Shared/AliasVault.Shared/Models/Spamok/EmailApiModel.cs
index 63c50d4bc..58eaab3df 100644
--- a/apps/server/Shared/AliasVault.Shared/Models/Spamok/EmailApiModel.cs
+++ b/apps/server/Shared/AliasVault.Shared/Models/Spamok/EmailApiModel.cs
@@ -10,7 +10,7 @@ namespace AliasVault.Shared.Models.Spamok;
using AliasVault.Shared.Models.Spamok.Base;
/// <summary>
-/// Represents an email API model.
+/// Represents an email API model of the external api.spamok.com API.
/// </summary>
public class EmailApiModel : EmailApiModelBase
{
diff --git a/apps/server/Shared/AliasVault.Shared/Models/Spamok/MailboxApiModel.cs b/apps/server/Shared/AliasVault.Shared/Models/Spamok/MailboxApiModel.cs
index dd63fdda8..01e8576b2 100644
--- a/apps/server/Shared/AliasVault.Shared/Models/Spamok/MailboxApiModel.cs
+++ b/apps/server/Shared/AliasVault.Shared/Models/Spamok/MailboxApiModel.cs
@@ -8,7 +8,7 @@
namespace AliasVault.Shared.Models.Spamok;
/// <summary>
-/// Represents a mailbox API model.
+/// Represents a mailbox API model of the external api.spamok.com API.
/// </summary>
public class MailboxApiModel
{
diff --git a/apps/server/Shared/AliasVault.Shared/Models/Spamok/MailboxEmailApiModel.cs b/apps/server/Shared/AliasVault.Shared/Models/Spamok/MailboxEmailApiModel.cs
index 4f848bcc5..e1f897a1a 100644
--- a/apps/server/Shared/AliasVault.Shared/Models/Spamok/MailboxEmailApiModel.cs
+++ b/apps/server/Shared/AliasVault.Shared/Models/Spamok/MailboxEmailApiModel.cs
@@ -10,7 +10,7 @@ namespace AliasVault.Shared.Models.Spamok;
using AliasVault.Shared.Models.Spamok.Base;
/// <summary>
-/// Represents a mailbox email API model.
+/// Represents a mailbox email API model of the external api.spamok.com API.
/// </summary>
public class MailboxEmailApiModel : EmailApiModelBase
{
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V1/Email/AttachmentApiModel.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V1/Email/AttachmentApiModel.cs
new file mode 100644
index 000000000..cf8247d64
--- /dev/null
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V1/Email/AttachmentApiModel.cs
@@ -0,0 +1,39 @@
+//-----------------------------------------------------------------------
+// <copyright file="AttachmentApiModel.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Shared.Models.WebApi.V1.Email;
+
+/// <summary>
+/// Represents an attachment of an email served by the AliasVault V1 email API.
+/// </summary>
+public class AttachmentApiModel
+{
+ /// <summary>
+ /// Gets or sets the ID of the attachment.
+ /// </summary>
+ public int Id { get; set; }
+
+ /// <summary>
+ /// Gets or sets the ID of the email the attachment belongs to.
+ /// </summary>
+ public int Email_Id { get; set; }
+
+ /// <summary>
+ /// Gets or sets the filename of the attachment.
+ /// </summary>
+ public string Filename { get; set; } = null!;
+
+ /// <summary>
+ /// Gets or sets the MIME type of the attachment.
+ /// </summary>
+ public string MimeType { get; set; } = null!;
+
+ /// <summary>
+ /// Gets or sets the size of the attachment in bytes.
+ /// </summary>
+ public int Filesize { get; set; }
+}
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V1/Email/EmailApiModel.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V1/Email/EmailApiModel.cs
new file mode 100644
index 000000000..15c816127
--- /dev/null
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V1/Email/EmailApiModel.cs
@@ -0,0 +1,39 @@
+//-----------------------------------------------------------------------
+// <copyright file="EmailApiModel.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Shared.Models.WebApi.V1.Email;
+
+/// <summary>
+/// Represents an email API model of the AliasVault V1 email API.
+/// </summary>
+public class EmailApiModel : EmailApiModelBase
+{
+ /// <summary>
+ /// Gets or sets the HTML content of the email message. Null for emails stored in the source-only
+ /// format, whose bodies live inside <see cref="MessageSource"/> only.
+ /// </summary>
+ public string? MessageHtml { get; set; }
+
+ /// <summary>
+ /// Gets or sets the plain text content of the email message. Null for emails stored in the source-only
+ /// format, whose bodies live inside <see cref="MessageSource"/> only.
+ /// </summary>
+ public string? MessagePlain { get; set; }
+
+ /// <summary>
+ /// Gets or sets the source content of the email message as base64 ciphertext. For emails stored in the
+ /// source-only format the decrypted plaintext is gzip-compressed, which clients detect via the gzip
+ /// magic bytes (0x1f 0x8b) before parsing the bodies and attachments out of it.
+ /// </summary>
+ public string? MessageSource { get; set; }
+
+ /// <summary>
+ /// Gets or sets the list of attachments in the email. Only populated for emails that carry separate
+ /// attachment records; emails stored in the source-only format have their attachments inside the source.
+ /// </summary>
+ public List<AttachmentApiModel> Attachments { get; set; } = [];
+}
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V1/Email/EmailApiModelBase.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V1/Email/EmailApiModelBase.cs
new file mode 100644
index 000000000..244f2e8c5
--- /dev/null
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V1/Email/EmailApiModelBase.cs
@@ -0,0 +1,76 @@
+//-----------------------------------------------------------------------
+// <copyright file="EmailApiModelBase.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Shared.Models.WebApi.V1.Email;
+
+/// <summary>
+/// Represents the base email API model of the AliasVault V1 email API.
+/// </summary>
+public abstract class EmailApiModelBase
+{
+ /// <summary>
+ /// Gets or sets the ID of the email.
+ /// </summary>
+ public int Id { get; set; }
+
+ /// <summary>
+ /// Gets or sets the subject of the email.
+ /// </summary>
+ public string Subject { get; set; } = string.Empty;
+
+ /// <summary>
+ /// Gets or sets the display name of the sender.
+ /// </summary>
+ public string FromDisplay { get; set; } = string.Empty;
+
+ /// <summary>
+ /// Gets or sets the domain of the sender's email address.
+ /// </summary>
+ public string FromDomain { get; set; } = string.Empty;
+
+ /// <summary>
+ /// Gets or sets the local part of the sender's email address.
+ /// </summary>
+ public string FromLocal { get; set; } = string.Empty;
+
+ /// <summary>
+ /// Gets or sets the domain of the recipient's email address.
+ /// </summary>
+ public string ToDomain { get; set; } = string.Empty;
+
+ /// <summary>
+ /// Gets or sets the local part of the recipient's email address.
+ /// </summary>
+ public string ToLocal { get; set; } = string.Empty;
+
+ /// <summary>
+ /// Gets or sets the date of the email.
+ /// </summary>
+ public DateTime Date { get; set; }
+
+ /// <summary>
+ /// Gets or sets the system date of the email.
+ /// </summary>
+ public DateTime DateSystem { get; set; }
+
+ /// <summary>
+ /// Gets or sets the number of seconds ago the email was received.
+ /// </summary>
+ public double SecondsAgo { get; set; }
+
+ /// <summary>
+ /// Gets or sets the encrypted symmetric key which was used to encrypt the email message.
+ /// This key is encrypted with the public key of the user. V1 always serves the personal wrap;
+ /// the per-manifest wrap list is a V2-only concept.
+ /// </summary>
+ public string EncryptedSymmetricKey { get; set; } = string.Empty;
+
+ /// <summary>
+ /// Gets or sets the public key of the user used to encrypt the symmetric key.
+ /// </summary>
+ public string EncryptionKey { get; set; } = string.Empty;
+}
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V1/Email/MailboxApiModel.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V1/Email/MailboxApiModel.cs
new file mode 100644
index 000000000..4335f4440
--- /dev/null
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V1/Email/MailboxApiModel.cs
@@ -0,0 +1,29 @@
+//-----------------------------------------------------------------------
+// <copyright file="MailboxApiModel.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Shared.Models.WebApi.V1.Email;
+
+/// <summary>
+/// Represents a mailbox API model of the AliasVault V1 email API.
+/// </summary>
+public class MailboxApiModel
+{
+ /// <summary>
+ /// Gets or sets the address of the mailbox.
+ /// </summary>
+ public string Address { get; set; } = string.Empty;
+
+ /// <summary>
+ /// Gets or sets a value indicating whether the mailbox is subscribed.
+ /// </summary>
+ public bool Subscribed { get; set; }
+
+ /// <summary>
+ /// Gets or sets the list of mailbox email API models.
+ /// </summary>
+ public List<MailboxEmailApiModel> Mails { get; set; } = [];
+}
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V1/Email/MailboxBulkResponse.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V1/Email/MailboxBulkResponse.cs
index 51c2bb3de..b3d6a0142 100644
--- a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V1/Email/MailboxBulkResponse.cs
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V1/Email/MailboxBulkResponse.cs
@@ -7,10 +7,8 @@
namespace AliasVault.Shared.Models.WebApi.V1.Email;
-using AliasVault.Shared.Models.Spamok;
-
/// <summary>
-/// Represents a mailbox API model.
+/// Represents a bulk mailbox response of the AliasVault V1 email API.
/// </summary>
public class MailboxBulkResponse
{
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V1/Email/MailboxEmailApiModel.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V1/Email/MailboxEmailApiModel.cs
new file mode 100644
index 000000000..a9091b2d6
--- /dev/null
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V1/Email/MailboxEmailApiModel.cs
@@ -0,0 +1,24 @@
+//-----------------------------------------------------------------------
+// <copyright file="MailboxEmailApiModel.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Shared.Models.WebApi.V1.Email;
+
+/// <summary>
+/// Represents a mailbox email API model of the AliasVault V1 email API.
+/// </summary>
+public class MailboxEmailApiModel : EmailApiModelBase
+{
+ /// <summary>
+ /// Gets or sets the preview of the email message.
+ /// </summary>
+ public string MessagePreview { get; set; } = string.Empty;
+
+ /// <summary>
+ /// Gets or sets a value indicating whether the email has attachments.
+ /// </summary>
+ public bool HasAttachments { get; set; }
+}
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Email/AttachmentApiModel.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Email/AttachmentApiModel.cs
new file mode 100644
index 000000000..9bf776c3a
--- /dev/null
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Email/AttachmentApiModel.cs
@@ -0,0 +1,39 @@
+//-----------------------------------------------------------------------
+// <copyright file="AttachmentApiModel.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Shared.Models.WebApi.V2.Email;
+
+/// <summary>
+/// Represents an attachment of an email served by the AliasVault V2 email API.
+/// </summary>
+public class AttachmentApiModel
+{
+ /// <summary>
+ /// Gets or sets the ID of the attachment.
+ /// </summary>
+ public int Id { get; set; }
+
+ /// <summary>
+ /// Gets or sets the ID of the email the attachment belongs to.
+ /// </summary>
+ public int Email_Id { get; set; }
+
+ /// <summary>
+ /// Gets or sets the filename of the attachment.
+ /// </summary>
+ public string Filename { get; set; } = null!;
+
+ /// <summary>
+ /// Gets or sets the MIME type of the attachment.
+ /// </summary>
+ public string MimeType { get; set; } = null!;
+
+ /// <summary>
+ /// Gets or sets the size of the attachment in bytes.
+ /// </summary>
+ public int Filesize { get; set; }
+}
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Email/EmailApiModel.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Email/EmailApiModel.cs
index 29855801e..bfe4f60bd 100644
--- a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Email/EmailApiModel.cs
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Email/EmailApiModel.cs
@@ -7,8 +7,6 @@
namespace AliasVault.Shared.Models.WebApi.V2.Email;
-using AliasVault.Shared.Models.Spamok;
-
/// <summary>
/// Represents the email API model.
/// </summary>