Skip to content

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

Add email retrieval logic (#541)

Leendert de Borst0a39857d127d
diff --git a/browser-extensions/chrome/src/pages/EmailsList.tsx b/browser-extensions/chrome/src/pages/EmailsList.tsx
index bcf5a0d8f..0cb8da279 100644
--- a/browser-extensions/chrome/src/pages/EmailsList.tsx
+++ b/browser-extensions/chrome/src/pages/EmailsList.tsx
@@ -1,13 +1,128 @@
+import React, { useEffect, useState, useCallback } from 'react';
+import { MailboxBulkResponse, MailboxEmailApiModel } from '../models/email';
+import { useDb } from '../context/DbContext';
+import { useWebApi } from '../context/WebApiContext';
+import { MailboxBulkRequest } from '../types/webapi/MailboxBulk';
+import LoadingSpinner from '../components/LoadingSpinner';
import React from 'react';
+import { useMinDurationLoading } from '../hooks/useMinDurationLoading';
/**
* Emails list page.
*/
const EmailsList: React.FC = () => {
+ const dbContext = useDb();
+ const webApi = useWebApi();
+ const [error, setError] = useState<string | null>(null);
+ const [emails, setEmails] = useState<MailboxEmailApiModel[]>([]);
+ const [currentPage, setCurrentPage] = useState(1);
+ const [pageSize] = useState(50);
+ const [totalRecords, setTotalRecords] = useState(0);
+
+ /**
+ * Loading state with minimum duration for more fluid UX.
+ */
+ const [isLoading, setIsLoading] = useMinDurationLoading(true, 150);
+
+ /**
+ * Loads emails from the web API.
+ */
+ const loadEmails = useCallback(async () : Promise<void> => {
+ try {
+ setIsLoading(true);
+ setError(null);
+
+ if (!dbContext?.sqliteClient) {
+ return;
+ }
+
+ const credentials = dbContext.sqliteClient.getAllCredentials();
+
+ // Get unique email addresses from all credentials.
+ const emailAddresses = credentials
+ .map(cred => cred.Email.trim()) // Trim whitespace
+ .filter((email, index, self) => self.indexOf(email) === index);
+
+ try {
+ const data = await webApi.post<MailboxBulkRequest, MailboxBulkResponse>('EmailBox/bulk', {
+ addresses: emailAddresses,
+ page: currentPage,
+ pageSize: pageSize,
+ });
+
+ setEmails(data.mails);
+ setTotalRecords(data.totalRecords);
+ } catch (error) {
+ console.error(error);
+ throw new Error('Failed to load emails');
+ }
+ } catch (err) {
+ setError(err instanceof Error ? err.message : 'An error occurred');
+ } finally {
+ setIsLoading(false);
+ }
+ }, [currentPage, dbContext?.sqliteClient, pageSize, webApi]);
+
+ useEffect(() => {
+ loadEmails();
+ }, [loadEmails]);
+
+ if (isLoading) {
+ return (
+ <div className="flex justify-center items-center p-8">
+ <LoadingSpinner />
+ </div>
+ );
+ }
+
+ if (error) {
+ return <div className="text-red-500">Error: {error}</div>;
+ }
+
+ if (emails.length === 0) {
+ return (
+ <div>
+ <h2 className="text-gray-900 dark:text-white text-xl mb-4">Emails</h2>
+ <p className="text-gray-500 dark:text-gray-400">No emails found</p>
+ </div>
+ );
+ }
+
return (
<div>
<h2 className="text-gray-900 dark:text-white text-xl mb-4">Emails</h2>
- <p className="text-gray-500 dark:text-gray-400">No emails found</p>
+ <div className="overflow-x-auto">
+ <table className="min-w-full divide-y divide-gray-200 dark:divide-gray-600">
+ <thead className="bg-gray-50 dark:bg-gray-700">
+ <tr>
+ <th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
+ Subject
+ </th>
+ <th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
+ From
+ </th>
+ <th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
+ Date
+ </th>
+ </tr>
+ </thead>
+ <tbody className="bg-white divide-y divide-gray-200 dark:bg-gray-800">
+ {emails.map((email) => (
+ <tr key={email.id} className="hover:bg-gray-50 dark:hover:bg-gray-700">
+ <td className="px-6 py-4 whitespace-nowrap text-gray-900 dark:text-white">
+ {email.subject}
+ </td>
+ <td className="px-6 py-4 whitespace-nowrap text-gray-500 dark:text-gray-400">
+ {email.fromDisplay}
+ </td>
+ <td className="px-6 py-4 whitespace-nowrap text-gray-500 dark:text-gray-400">
+ {new Date(email.dateSystem).toLocaleString()}
+ </td>
+ </tr>
+ ))}
+ </tbody>
+ </table>
+ </div>
</div>
);
};
diff --git a/browser-extensions/chrome/src/types/Credential.ts b/browser-extensions/chrome/src/types/Credential.ts
index 0b6f56687..fed03ae16 100644
--- a/browser-extensions/chrome/src/types/Credential.ts
+++ b/browser-extensions/chrome/src/types/Credential.ts
@@ -3,6 +3,7 @@ export type Credential = {
Username: string;
ServiceId: string;
ServiceName: string;
+ Email: string;
ServiceUrl: string;
Logo: Uint8Array;
Password: string;
diff --git a/browser-extensions/chrome/src/types/webapi/MailboxBulk.ts b/browser-extensions/chrome/src/types/webapi/MailboxBulk.ts
new file mode 100644
index 000000000..9d8c63151
--- /dev/null
+++ b/browser-extensions/chrome/src/types/webapi/MailboxBulk.ts
@@ -0,0 +1,15 @@
+import { MailboxEmail } from "./MailboxEmail";
+
+export type MailboxBulkRequest = {
+ addresses: string[];
+ page: number;
+ pageSize: number;
+}
+
+export type MailboxBulkResponse = {
+ addresses: string[];
+ currentPage: number;
+ pageSize: number;
+ totalRecords: number;
+ mails: MailboxEmail[];
+}
\ No newline at end of file
diff --git a/browser-extensions/chrome/src/types/webapi/MailboxEmail.ts b/browser-extensions/chrome/src/types/webapi/MailboxEmail.ts
new file mode 100644
index 000000000..dd15b9ae4
--- /dev/null
+++ b/browser-extensions/chrome/src/types/webapi/MailboxEmail.ts
@@ -0,0 +1,46 @@
+export type MailboxEmail = {
+ /** The preview of the email message */
+ messagePreview: string;
+
+ /** Indicates whether the email has attachments */
+ hasAttachments: boolean;
+
+ /** The ID of the email */
+ id: number;
+
+ /** The subject of the email */
+ subject: string;
+
+ /** The display name of the sender */
+ fromDisplay: string;
+
+ /** The domain of the sender's email address */
+ fromDomain: string;
+
+ /** The local part of the sender's email address */
+ fromLocal: string;
+
+ /** The domain of the recipient's email address */
+ toDomain: string;
+
+ /** The local part of the recipient's email address */
+ toLocal: string;
+
+ /** The date of the email */
+ date: string;
+
+ /** The system date of the email */
+ dateSystem: string;
+
+ /** The number of seconds ago the email was received */
+ secondsAgo: number;
+
+ /**
+ * The encrypted symmetric key which was used to encrypt the email message.
+ * This key is encrypted with the public key of the user.
+ */
+ encryptedSymmetricKey: string;
+
+ /** The public key of the user used to encrypt the symmetric key */
+ encryptionKey: string;
+}
\ No newline at end of file
diff --git a/browser-extensions/chrome/src/utils/SqliteClient.tsx b/browser-extensions/chrome/src/utils/SqliteClient.tsx
index 3a6d32cc2..304d53351 100644
--- a/browser-extensions/chrome/src/utils/SqliteClient.tsx
+++ b/browser-extensions/chrome/src/utils/SqliteClient.tsx
@@ -106,10 +106,12 @@ class SqliteClient {
s.Name as ServiceName,
s.Url as ServiceUrl,
s.Logo as Logo,
- MAX(p.Value) as Password
+ MAX(p.Value) as Password,
+ a.Email as Email
FROM Credentials c
JOIN Services s ON s.Id = c.ServiceId
LEFT JOIN Passwords p ON p.CredentialId = c.Id
+ LEFT JOIN Aliases a ON a.Id = c.AliasId AND a.IsDeleted = 0
WHERE c.IsDeleted = 0
GROUP BY c.Id, c.Username, c.ServiceId, s.Name, s.Url, s.Logo
`);
diff --git a/src/AliasVault.Client/Services/Database/DbService.cs b/src/AliasVault.Client/Services/Database/DbService.cs
index 5d73f4eac..364d91d58 100644
--- a/src/AliasVault.Client/Services/Database/DbService.cs
+++ b/src/AliasVault.Client/Services/Database/DbService.cs
@@ -438,7 +438,7 @@ public sealed class DbService : IDisposable
.Select(email => email!)
.ToListAsync();
- // Filter the list of email addresses to only include those that are in the allowed domains.
+ // Filter the list of email addresses to only include those that are in the supported private email domains.
emailAddresses = emailAddresses
.Where(email => _config.PrivateEmailDomains.Exists(domain => email.EndsWith(domain)))
.ToList();
diff --git a/src/Services/WebApiService.ts b/src/Services/WebApiService.ts
deleted file mode 100644
index 0519ecba6..000000000
--- a/src/Services/WebApiService.ts
+++ /dev/null
@@ -1 +0,0 @@
-
\ No newline at end of file