Skip to content

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

Add email render components (#2413)

Leendert de Borstd098b8ee67f6
diff --git a/apps/web/src/components/email/EmailModal.tsx b/apps/web/src/components/email/EmailModal.tsx
new file mode 100644
index 000000000..2d62af6ce
--- /dev/null
+++ b/apps/web/src/components/email/EmailModal.tsx
@@ -0,0 +1,247 @@
+import React, { useCallback, useEffect, useRef, useState } from 'react';
+import { useTranslation } from 'react-i18next';
+import { useNavigate } from 'react-router-dom';
+
+import SkeletonBase from '@/components/loading/SkeletonBase';
+import ModalHeaderAction from '@/components/shared/ModalHeaderAction';
+import { useConfirmModal } from '@/context/ConfirmModalContext';
+import { useDb } from '@/context/DbContext';
+import { useNotifications } from '@/context/NotificationContext';
+import { useWebApi } from '@/context/WebApiContext';
+import { useEmailBody } from '@/hooks/useEmailBody';
+import { type EmailAttachmentViewModel, type EmailViewModel, getAttachmentBytes, spamOkRequest } from '@/utils/EmailViewModel';
+import { downloadBytes } from '@/utils/FileDownload';
+import { itemRoute } from '@/utils/ItemRoute';
+
+import type { ItemRef } from '@aliasvault/client/database/ItemRef';
+
+type EmailModalProps = {
+ email: EmailViewModel | null;
+ onClose: () => void;
+ onEmailDeleted: (emailId: number) => void;
+ showItemLink?: boolean;
+};
+
+/**
+ * A single skeleton line.
+ */
+const SkeletonLine: React.FC<{ height: number; widthClass: string }> = ({ height, widthClass }) => (
+ <SkeletonBase height={height} additionalClasses={widthClass}>
+ <div className="w-full h-full bg-gray-300 dark:bg-gray-600 rounded"></div>
+ </SkeletonBase>
+);
+
+/**
+ * Modal showing a single email.
+ */
+const EmailModal: React.FC<EmailModalProps> = ({ email, onClose, onEmailDeleted, showItemLink = false }) => {
+ const { t } = useTranslation();
+ const navigate = useNavigate();
+ const dbContext = useDb();
+ const webApi = useWebApi();
+ const notifications = useNotifications();
+ const { showConfirmation } = useConfirmModal();
+ const [isBodyLoading, setIsBodyLoading] = useState(false);
+ const [item, setItem] = useState<{ ref: ItemRef; name: string } | null>(null);
+ const panelRef = useRef<HTMLDivElement>(null);
+ const onBodyLoading = useCallback((loading: boolean): void => setIsBodyLoading(loading), []);
+ const { emailBody, availableModes, formatLabel, cycleViewMode } = useEmailBody(email, onBodyLoading);
+
+ useEffect(() => {
+ /**
+ * Enter and Escape close the modal.
+ */
+ const onKeyDown = (event: KeyboardEvent): void => {
+ if (event.key === 'Escape' || event.key === 'Enter') {
+ onClose();
+ }
+ };
+ document.addEventListener('keydown', onKeyDown);
+ return (): void => document.removeEventListener('keydown', onKeyDown);
+ }, [onClose]);
+
+ /*
+ * Resolve the vault item that owns the recipient address when the caller asks for the item row. SpamOK mail is not
+ * backed by a vault item, so the lookup is skipped.
+ */
+ useEffect(() => {
+ setItem(null);
+ if (!showItemLink || !email || email.isSpamOk || !dbContext.sqliteClient) {
+ return;
+ }
+ const match = dbContext.sqliteClient.items.findIdByEmail(`${email.toLocal}@${email.toDomain}`.toLowerCase());
+ if (match) {
+ setItem({ ref: { Id: match.Id, ManifestId: match.ManifestId }, name: match.Name ?? '' });
+ }
+ }, [dbContext.sqliteClient, email, showItemLink]);
+
+ /**
+ * Close on a click on the backdrop. The confirm modal renders outside the panel, so its clicks must not close.
+ */
+ const onBackdropClick = (event: React.MouseEvent<HTMLDivElement>): void => {
+ if (event.target === event.currentTarget) {
+ onClose();
+ }
+ };
+
+ /**
+ * Delete the email after confirmation.
+ */
+ const showDeleteConfirmation = async (): Promise<void> => {
+ if (!email) {
+ return;
+ }
+ const confirmed = await showConfirmation(t('components.main.email.emailModal.DeleteEmailTitle'), t('components.main.email.emailModal.DeleteEmailConfirmation'), t('sharedResources.Confirm'), t('sharedResources.Cancel'));
+ if (!confirmed) {
+ return;
+ }
+
+ try {
+ if (email.isSpamOk) {
+ const response = await spamOkRequest('DELETE', `Email/${email.toLocal}/${email.id}`);
+ if (!response.ok) {
+ notifications.addErrorMessage(`${t('components.main.email.emailModal.EmailDeleteFailed')}: ${await response.text()}`, true);
+ return;
+ }
+ onEmailDeleted(email.id);
+ notifications.addSuccessMessage(t('components.main.email.emailModal.EmailDeletedSuccess'), true);
+ onClose();
+ } else {
+ await webApi.delete(`Email/${email.id}`);
+ onEmailDeleted(email.id);
+ notifications.addSuccessMessage(t('components.main.email.emailModal.EmailDeletedSuccess'), true);
+ }
+ } catch (error) {
+ notifications.addErrorMessage(`${t('components.main.email.emailModal.EmailDeleteFailed')}: ${error instanceof Error ? error.message : String(error)}`, true);
+ }
+ };
+
+ /**
+ * Download an attachment.
+ */
+ const downloadAttachment = async (attachment: EmailAttachmentViewModel): Promise<void> => {
+ if (!email || !dbContext.sqliteClient) {
+ return;
+ }
+ try {
+ const bytes = await getAttachmentBytes(webApi, dbContext.sqliteClient, email, attachment);
+ if (!bytes) {
+ notifications.addErrorMessage(t('components.main.email.emailModal.AttachmentDownloadFailed'), true);
+ return;
+ }
+ downloadBytes(attachment.filename, bytes, attachment.mimeType);
+ } catch (error) {
+ notifications.addErrorMessage(`${t('components.main.email.emailModal.AttachmentDownloadError')}: ${error instanceof Error ? error.message : String(error)}`, true);
+ }
+ };
+
+ return (
+ <div className="modal-dialog fixed inset-0 z-50 overflow-auto bg-gray-500 bg-opacity-75 flex items-center justify-center" onClick={onBackdropClick}>
+ <div ref={panelRef} id="emailModal" className="relative bg-white dark:bg-gray-800 w-3/4 flex flex-col rounded-lg shadow-xl max-h-[90vh] border border-gray-200 dark:border-gray-700">
+ <div className="p-4 border-b border-gray-200 dark:border-gray-700">
+ <div className="flex items-center justify-between gap-3 mb-3">
+ <h2 className="text-2xl font-bold text-gray-900 dark:text-gray-100 truncate min-w-0">
+ {email === null
+ ? <SkeletonLine height={28} widthClass="w-3/4" />
+ : email.isSpamOk
+ ? <a target="_blank" rel="noreferrer" href={`https://spamok.com/${email.toLocal}/${email.id}`} className="hover:underline">{email.subject}</a>
+ : <span>{email.subject}</span>}
+ </h2>
+ <div className="flex items-center gap-1 flex-shrink-0">
+ {availableModes.length > 1 && (
+ <ModalHeaderAction onClick={cycleViewMode} title={t('sharedResources.EmailFormatSwitchTitle')}>{formatLabel}</ModalHeaderAction>
+ )}
+ {email !== null && (
+ <ModalHeaderAction onClick={() => void showDeleteConfirmation()} title={t('components.main.email.emailModal.DeleteButton')} variant="danger">
+ <svg className="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" />
+ </svg>
+ </ModalHeaderAction>
+ )}
+ <ModalHeaderAction onClick={onClose} title={t('sharedResources.Close')}>
+ <svg className="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M6 18L18 6M6 6l12 12" />
+ </svg>
+ </ModalHeaderAction>
+ </div>
+ </div>
+ <div className="grid grid-cols-1 sm:grid-cols-2 gap-x-4 text-sm text-gray-500 dark:text-gray-400">
+ {email === null ? (
+ <>
+ <div className="space-y-2">
+ <SkeletonLine height={16} widthClass="w-1/2" />
+ <SkeletonLine height={16} widthClass="w-1/2" />
+ </div>
+ <div className="space-y-2 mt-2 sm:mt-0">
+ <SkeletonLine height={16} widthClass="w-1/3" />
+ <SkeletonLine height={16} widthClass="w-1/4" />
+ </div>
+ </>
+ ) : (
+ <>
+ <div className="space-y-1">
+ <p>{t('components.main.email.emailModal.FromLabel')} {email.fromLocal}@{email.fromDomain}</p>
+ <p>{t('components.main.email.emailModal.ToLabel')} {email.toLocal}@{email.toDomain}</p>
+ </div>
+ <div className="space-y-1 mt-1 sm:mt-0">
+ <p>{t('components.main.email.emailModal.DateLabel')} {new Date(email.dateSystem).toLocaleString()}</p>
+ {showItemLink && (item !== null && item.name.length > 0 ? (
+ <p>
+ <span className="font-medium">{t('sharedResources.EmailItemLabel')}</span>{' '}
+ <button type="button" onClick={() => navigate(itemRoute(item.ref))} className="text-blue-600 hover:underline dark:text-blue-400 cursor-pointer">{item.name}</button>
+ </p>
+ ) : (
+ <p>
+ <span className="font-medium">{t('sharedResources.EmailItemLabel')}</span>{' '}
+ <span className="text-gray-400 dark:text-gray-500">{t('sharedResources.EmailItemNone')}</span>
+ </p>
+ ))}
+ </div>
+ </>
+ )}
+ </div>
+ </div>
+
+ <div className="flex-1 overflow-y-auto p-4">
+ <div className="text-gray-700 dark:text-gray-300">
+ {/* Mount only once the body exists to prevent browsers from dropping a srcdoc change made while the initial empty srcdoc still loads. */}
+ {email === null || isBodyLoading || emailBody === '' ? (
+ <div className="space-y-3" style={{ height: '500px' }}>
+ <SkeletonLine height={16} widthClass="w-11/12" />
+ <SkeletonLine height={16} widthClass="w-full" />
+ <SkeletonLine height={16} widthClass="w-10/12" />
+ <SkeletonLine height={16} widthClass="w-5/6" />
+ <SkeletonLine height={16} widthClass="w-2/3" />
+ </div>
+ ) : (
+ <div>
+ <iframe title="email" className="w-full overscroll-y-auto bg-white rounded" style={{ height: '500px' }} srcDoc={emailBody} sandbox="allow-popups allow-popups-to-escape-sandbox"></iframe>
+ </div>
+ )}
+ </div>
+ <div className="mt-4">
+ {email !== null && email.attachments.length > 0 && (
+ <div className="border-t border-gray-200 dark:border-gray-600 pt-4">
+ <h3 className="text-sm font-medium text-gray-500 dark:text-gray-400 mb-2">{t('components.main.email.emailModal.AttachmentsLabel')}</h3>
+ <div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-4">
+ {email.attachments.map((attachment) => (
+ <div key={attachment.index} className="flex items-center space-x-2">
+ <svg className="w-4 h-4 text-gray-500 dark:text-gray-400 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M15.172 7l-6.586 6.586a2 2 0 102.828 2.828l6.414-6.586a4 4 0 00-5.656-5.656l-6.415 6.585a6 6 0 108.486 8.486L20.5 13"></path>
+ </svg>
+ <button type="button" onClick={() => void downloadAttachment(attachment)} className="text-primary-600 hover:underline text-sm truncate dark:text-primary-400 attachment-link">
+ ({Math.ceil(attachment.size / 1024)} KB) {attachment.filename}
+ </button>
+ </div>
+ ))}
+ </div>
+ </div>
+ )}
+ </div>
+ </div>
+ </div>
+ </div>
+ );
+};
+
+export default EmailModal;
diff --git a/apps/web/src/components/email/EmailPreview.tsx b/apps/web/src/components/email/EmailPreview.tsx
new file mode 100644
index 000000000..0b6597384
--- /dev/null
+++ b/apps/web/src/components/email/EmailPreview.tsx
@@ -0,0 +1,163 @@
+import React from 'react';
+import { useTranslation } from 'react-i18next';
+
+import { useConfirmModal } from '@/context/ConfirmModalContext';
+import { useDb } from '@/context/DbContext';
+import { useNotifications } from '@/context/NotificationContext';
+import { useWebApi } from '@/context/WebApiContext';
+import { useEmailBody } from '@/hooks/useEmailBody';
+import { type EmailAttachmentViewModel, type EmailViewModel, getAttachmentBytes, spamOkRequest } from '@/utils/EmailViewModel';
+import { downloadBytes } from '@/utils/FileDownload';
+
+import type { ItemRef } from '@aliasvault/client/database/ItemRef';
+
+type EmailPreviewProps = {
+ email: EmailViewModel | null;
+ onEmailDeleted: (emailId: number) => void;
+ item: { ref: ItemRef; name: string } | null;
+ onItemClick: (item: ItemRef) => void;
+};
+
+/**
+ * The right-hand email panel of the mailbox page.
+ */
+const EmailPreview: React.FC<EmailPreviewProps> = ({ email, onEmailDeleted, item, onItemClick }) => {
+ const { t } = useTranslation();
+ const dbContext = useDb();
+ const webApi = useWebApi();
+ const notifications = useNotifications();
+ const { showConfirmation } = useConfirmModal();
+ const { emailBody, availableModes, formatLabel, cycleViewMode } = useEmailBody(email);
+
+ /**
+ * Delete the email after confirmation.
+ */
+ const showDeleteConfirmation = async (): Promise<void> => {
+ if (!email) {
+ return;
+ }
+ const confirmed = await showConfirmation(t('components.main.email.emailPreview.DeleteEmailTitle'), t('components.main.email.emailPreview.DeleteEmailConfirmation'), t('sharedResources.Confirm'), t('sharedResources.Cancel'));
+ if (!confirmed) {
+ return;
+ }
+
+ try {
+ if (email.isSpamOk) {
+ const response = await spamOkRequest('DELETE', `Email/${email.toLocal}/${email.id}`);
+ if (!response.ok) {
+ notifications.addErrorMessage(`${t('components.main.email.emailPreview.EmailDeleteFailed')}: ${await response.text()}`, true);
+ return;
+ }
+ } else {
+ await webApi.delete(`Email/${email.id}`);
+ }
+ onEmailDeleted(email.id);
+ notifications.addSuccessMessage(t('components.main.email.emailPreview.EmailDeletedSuccess'), true);
+ } catch (error) {
+ notifications.addErrorMessage(`${t('components.main.email.emailPreview.EmailDeleteFailed')}: ${error instanceof Error ? error.message : String(error)}`, true);
+ }
+ };
+
+ /**
+ * Download an attachment.
+ */
+ const downloadAttachment = async (attachment: EmailAttachmentViewModel): Promise<void> => {
+ if (!email || !dbContext.sqliteClient) {
+ return;
+ }
+ try {
+ const bytes = await getAttachmentBytes(webApi, dbContext.sqliteClient, email, attachment);
+ if (!bytes) {
+ notifications.addErrorMessage(t('components.main.email.emailPreview.AttachmentDownloadFailed'), true);
+ return;
+ }
+ downloadBytes(attachment.filename, bytes, attachment.mimeType);
+ } catch (error) {
+ notifications.addErrorMessage(`${t('components.main.email.emailPreview.AttachmentDownloadError')}: ${error instanceof Error ? error.message : String(error)}`, true);
+ }
+ };
+
+ return (
+ <div className="h-full flex flex-col bg-white border-l border-gray-200 dark:border-gray-700 rounded-l-lg">
+ {email !== null ? (
+ <>
+ <div className="p-4 border-b border-gray-200 dark:border-gray-600 bg-gray-50 dark:bg-gray-700">
+ <div className="flex items-center justify-between mb-3">
+ <h2 className="text-lg font-semibold text-gray-900 dark:text-gray-100 truncate">
+ {email.isSpamOk
+ ? <a target="_blank" rel="noreferrer" href={`https://spamok.com/${email.toLocal}/${email.id}`} className="hover:underline">{email.subject}</a>
+ : <span>{email.subject}</span>}
+ </h2>
+ <div className="flex items-center gap-2">
+ {availableModes.length > 1 && (
+ <button type="button" onClick={cycleViewMode} title={t('sharedResources.EmailFormatSwitchTitle')} className="text-xs font-medium px-2 py-1 rounded text-gray-600 hover:text-gray-800 hover:bg-gray-200 dark:text-gray-300 dark:hover:text-gray-100 dark:hover:bg-gray-600">
+ {formatLabel}
+ </button>
+ )}
+ <button type="button" onClick={() => void showDeleteConfirmation()} id="delete-email" className="text-red-500 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300">
+ <svg className="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" />
+ </svg>
+ </button>
+ </div>
+ </div>
+ <div className="grid grid-cols-1 sm:grid-cols-2 gap-4 text-sm text-gray-600 dark:text-gray-300">
+ <div className="space-y-1">
+ <p><span className="font-medium">{t('components.main.email.emailPreview.FromLabel')}</span> {email.fromLocal}@{email.fromDomain}</p>
+ <p><span className="font-medium">{t('components.main.email.emailPreview.ToLabel')}</span> {email.toLocal}@{email.toDomain}</p>
+ </div>
+ <div className="space-y-1">
+ <p><span className="font-medium">{t('components.main.email.emailPreview.DateLabel')}</span> {new Date(email.dateSystem).toLocaleString()}</p>
+ {item !== null && item.name.length > 0 ? (
+ <p><span className="font-medium">{t('sharedResources.EmailItemLabel')}</span>{' '}
+ <button type="button" onClick={() => onItemClick(item.ref)} className="text-blue-600 hover:underline dark:text-blue-400 cursor-pointer">{item.name}</button>
+ </p>
+ ) : (
+ <p><span className="font-medium">{t('sharedResources.EmailItemLabel')}</span> <span className="text-gray-400 dark:text-gray-500">{t('sharedResources.EmailItemNone')}</span></p>
+ )}
+ </div>
+ </div>
+ </div>
+
+ <div className="flex-1 flex flex-col overflow-hidden">
+ <div className="flex-1 overflow-y-auto p-4">
+ <div className="text-gray-700 dark:text-gray-300 h-full">
+ {/* Mount only once the body exists to prevent browsers from dropping a srcdoc change made while the initial empty srcdoc still loads. */}
+ {emailBody !== '' && <iframe title="email" className="w-full h-full border-0" srcDoc={emailBody} sandbox="allow-popups allow-popups-to-escape-sandbox"></iframe>}
+ </div>
+ </div>
+
+ {email.attachments.length > 0 && (
+ <div className="border-t border-gray-200 dark:border-gray-600 p-4 bg-gray-50 dark:bg-gray-800">
+ <h3 className="text-sm font-medium text-gray-500 dark:text-gray-400 mb-2">{t('components.main.email.emailPreview.AttachmentsLabel')}</h3>
+ <div className="grid grid-cols-1 gap-2 max-h-32 overflow-y-auto">
+ {email.attachments.map((attachment) => (
+ <div key={attachment.index} className="flex items-center space-x-2">
+ <svg className="w-4 h-4 text-gray-500 dark:text-gray-400 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M15.172 7l-6.586 6.586a2 2 0 102.828 2.828l6.414-6.586a4 4 0 00-5.656-5.656l-6.415 6.585a6 6 0 108.486 8.486L20.5 13"></path>
+ </svg>
+ <button type="button" onClick={() => void downloadAttachment(attachment)} className="text-blue-600 hover:underline text-sm truncate dark:text-blue-400 attachment-link">
+ ({Math.ceil(attachment.size / 1024)} KB) {attachment.filename}
+ </button>
+ </div>
+ ))}
+ </div>
+ </div>
+ )}
+ </div>
+ </>
+ ) : (
+ <div className="flex bg-gray-50 dark:bg-gray-700 items-center justify-center h-full text-gray-500 dark:text-gray-400">
+ <div className="text-center">
+ <svg className="mx-auto h-12 w-12 text-gray-300 dark:text-gray-600" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M3 8l7.89 4.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z" />
+ </svg>
+ <p className="mt-2 text-sm">{t('components.main.email.emailPreview.SelectEmailMessage')}</p>
+ </div>
+ </div>
+ )}
+ </div>
+ );
+};
+
+export default EmailPreview;
diff --git a/apps/web/src/components/email/EmailPreviewSkeleton.tsx b/apps/web/src/components/email/EmailPreviewSkeleton.tsx
new file mode 100644
index 000000000..302e35c7c
--- /dev/null
+++ b/apps/web/src/components/email/EmailPreviewSkeleton.tsx
@@ -0,0 +1,33 @@
+import React from 'react';
+
+import SkeletonBase from '@/components/loading/SkeletonBase';
+
+/**
+ * Skeleton placeholder for the email preview panel.
+ */
+const EmailPreviewSkeleton: React.FC = () => (
+ <div className="h-full flex flex-col bg-white dark:bg-gray-800 border-l border-gray-200 dark:border-gray-700">
+ <div className="p-4 border-b border-gray-200 dark:border-gray-600 bg-gray-50 dark:bg-gray-700">
+ <div className="flex items-center justify-between mb-2">
+ <SkeletonBase height={24} additionalClasses="w-3/4">
+ <div className="w-full h-full bg-gray-300 dark:bg-gray-600 rounded"></div>
+ </SkeletonBase>
+ <SkeletonBase height={20} additionalClasses="w-5">
+ <div className="w-full h-full bg-gray-300 dark:bg-gray-600 rounded"></div>
+ </SkeletonBase>
+ </div>
+ <div className="space-y-2">
+ {['w-1/2', 'w-1/3', 'w-1/4', 'w-1/3'].map((width, index) => (
+ <SkeletonBase key={index} height={16} additionalClasses={width}>
+ <div className="w-full h-full bg-gray-300 dark:bg-gray-600 rounded"></div>
+ </SkeletonBase>
+ ))}
+ </div>
+ </div>
+ <div className="flex-1 overflow-y-auto p-4">
+ <div className="space-y-4"></div>
+ </div>
+ </div>
+);
+
+export default EmailPreviewSkeleton;
diff --git a/apps/web/src/components/email/EmailRow.tsx b/apps/web/src/components/email/EmailRow.tsx
new file mode 100644
index 000000000..67d06f813
--- /dev/null
+++ b/apps/web/src/components/email/EmailRow.tsx
@@ -0,0 +1,91 @@
+import React from 'react';
+import { useTranslation } from 'react-i18next';
+
+import SenderInitials from '@/components/email/SenderInitials';
+
+import type { ItemRef } from '@aliasvault/client/database/ItemRef';
+
+/**
+ * One email as shown in the mailbox list.
+ */
+export type MailListEntry = {
+ id: number;
+ date: Date;
+ fromName: string;
+ fromEmail: string;
+ toEmail: string;
+ subject: string;
+ messagePreview: string;
+ item: { ref: ItemRef; name: string } | null;
+ hasAttachments: boolean;
+};
+
+type EmailRowProps = {
+ email: MailListEntry;
+ onEmailClick: (id: number) => void;
+ onEmailCheck: (id: number) => void;
+ isChecked: boolean;
+ isSelected: boolean;
+ isNewEmail: boolean;
+};
+
+/**
+ * Format a date as dd-MM.
+ * @param date - the date
+ */
+const formatShortDate = (date: Date): string => `${String(date.getDate()).padStart(2, '0')}-${String(date.getMonth() + 1).padStart(2, '0')}`;
+
+/**
+ * A row in the mailbox list.
+ */
+const EmailRowComponent: React.FC<EmailRowProps> = ({ email, onEmailClick, onEmailCheck, isChecked, isSelected, isNewEmail }) => {
+ const { t } = useTranslation();
+
+ return (
+ <li className={`flex items-center transition duration-150 ease-in-out cursor-pointer ${isSelected ? 'bg-primary-50 dark:bg-primary-900/30 border-l-4 border-primary-500 hover:bg-primary-200 dark:hover:bg-primary-900/50' : 'hover:bg-gray-100 dark:hover:bg-gray-600'}`}>
+ <div className="pl-4 mr-2 flex-shrink-0">
+ <input
+ className="form-checkbox h-4 w-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600"
+ type="checkbox"
+ checked={isChecked}
+ onChange={() => onEmailCheck(email.id)} />
+ </div>
+ <div onClick={() => onEmailClick(email.id)} className="p-4 flex flex-grow min-w-0 justify-start items-start">
+ <div className="mr-4 flex-shrink-0">
+ <SenderInitials senderName={email.fromName} senderEmail={email.fromEmail} />
+ </div>
+ <div className="flex-grow min-w-0">
+ <div className="flex items-start justify-between">
+ <div className="flex-grow min-w-0 mr-2">
+ <div className="text-gray-800 dark:text-gray-200 font-medium truncate mb-1 flex items-center">
+ {email.fromName}
+ {email.hasAttachments && (
+ <svg className="attachment-indicator w-3 h-3 ml-1 text-gray-500 dark:text-gray-400 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M15.172 7l-6.586 6.586a2 2 0 102.828 2.828l6.414-6.586a4 4 0 00-5.656-5.656l-6.415 6.585a6 6 0 108.486 8.486L20.5 13"></path>
+ </svg>
+ )}
+ {isNewEmail && (
+ <div className="w-2 h-2 ml-1 bg-yellow-500 rounded-full animate-pulse flex-shrink-0" title={t('components.main.email.emailRow.NewEmailTooltip')}></div>
+ )}
+ </div>
+ <div className="text-sm text-gray-600 dark:text-gray-300 truncate mb-1">
+ {email.subject}
+ </div>
+ <div className="text-xs text-gray-500 dark:text-gray-400 truncate">
+ {email.messagePreview}
+ </div>
+ </div>
+ <div className="text-xs text-gray-500 dark:text-gray-400 flex-shrink-0">
+ {formatShortDate(email.date)}
+ </div>
+ </div>
+ </div>
+ </div>
+ </li>
+ );
+};
+
+/** Only re-render when this row's own inputs change. */
+const EmailRow = React.memo(EmailRowComponent);
+
+export default EmailRow;
diff --git a/apps/web/src/components/email/EmailRowSkeleton.tsx b/apps/web/src/components/email/EmailRowSkeleton.tsx
new file mode 100644
index 000000000..c9325bfed
--- /dev/null
+++ b/apps/web/src/components/email/EmailRowSkeleton.tsx
@@ -0,0 +1,46 @@
+import React from 'react';
+
+import SkeletonBase from '@/components/loading/SkeletonBase';
+
+/**
+ * Skeleton placeholder for a mailbox row.
+ */
+const EmailRowSkeleton: React.FC = () => (
+ <li className="hover:bg-gray-50 dark:hover:bg-gray-600 transition duration-150 ease-in-out">
+ <div className="p-4 flex justify-start items-start">
+ <div className="mr-4 flex-shrink-0">
+ <SkeletonBase height={40} additionalClasses="rounded-full w-10">
+ <div className="w-full h-full rounded-full bg-gray-300 dark:bg-gray-700"></div>
+ </SkeletonBase>
+ </div>
+ <div className="flex-grow min-w-0">
+ <div className="flex items-start justify-between">
+ <div className="flex-grow min-w-0 mr-2">
+ <div className="mb-1">
+ <SkeletonBase height={18} additionalClasses="w-40">
+ <div className="w-full h-full bg-gray-300 dark:bg-gray-700 rounded"></div>
+ </SkeletonBase>
+ </div>
+ <div className="mb-1">
+ <SkeletonBase height={16} additionalClasses="w-48">
+ <div className="w-full h-full bg-gray-300 dark:bg-gray-700 rounded"></div>
+ </SkeletonBase>
+ </div>
+ <div>
+ <SkeletonBase height={12} additionalClasses="w-64">
+ <div className="w-full h-full bg-gray-300 dark:bg-gray-700 rounded"></div>
+ </SkeletonBase>
+ </div>
+ </div>
+ <div className="flex-shrink-0">
+ <SkeletonBase height={12} additionalClasses="w-10">
+ <div className="w-full h-full bg-gray-300 dark:bg-gray-700 rounded"></div>
+ </SkeletonBase>
+ </div>
+ </div>
+ </div>
+ </div>
+ </li>
+);
+
+export default EmailRowSkeleton;
diff --git a/apps/web/src/components/email/SenderInitials.tsx b/apps/web/src/components/email/SenderInitials.tsx
new file mode 100644
index 000000000..6a98ae72f
--- /dev/null
+++ b/apps/web/src/components/email/SenderInitials.tsx
@@ -0,0 +1,36 @@
+import React from 'react';
+
+/** Color per first letter of the sender name. */
+const ALPHABET_COLORS: Record<string, string> = {
+ A: 'hsl(175, 50%, 50%)', B: 'hsl(234, 50%, 50%)', C: 'hsl(278, 50%, 50%)', D: 'hsl(191, 50%, 50%)', E: 'hsl(215, 50%, 50%)',
+ F: 'hsl(315, 50%, 50%)', G: 'hsl(247, 50%, 50%)', H: 'hsl(259, 50%, 50%)', I: 'hsl(289, 50%, 50%)', J: 'hsl(206, 50%, 50%)',
+ K: 'hsl(124, 50%, 50%)', L: 'hsl(129, 50%, 50%)', M: 'hsl(69, 50%, 50%)', N: 'hsl(38, 50%, 50%)', O: 'hsl(352, 50%, 50%)',
+ P: 'hsl(311, 50%, 50%)', Q: 'hsl(332, 50%, 50%)', R: 'hsl(344, 50%, 50%)', S: 'hsl(357, 50%, 50%)', T: 'hsl(23, 50%, 50%)',
+ U: 'hsl(16, 50%, 50%)', V: 'hsl(304, 50%, 50%)', W: 'hsl(300, 50%, 50%)', X: 'hsl(332, 50%, 50%)', Y: 'hsl(48, 50%, 50%)', Z: 'hsl(9, 50%, 50%)',
+};
+
+/**
+ * The initials of a sender name (up to two letters).
+ * @param senderName - the display name
+ */
+const getInitials = (senderName: string): string => {
+ const cleaned = senderName.replace(/[^a-zA-Z ]/g, '');
+ const letters = cleaned.split(' ').map(n => (n.length > 0 ? n[0] : '')).join('').substring(0, 2).toUpperCase();
+ return letters.length > 0 ? letters : '?';
+};
+
+/**
+ * Colored circle with the sender's initials.
+ */
+const SenderInitials: React.FC<{ senderName: string; senderEmail: string }> = ({ senderName, senderEmail }) => {
+ const initials = getInitials(senderName);
+ const color = ALPHABET_COLORS[initials.substring(0, 1)] ?? '#666';
+
+ return (
+ <div title={senderEmail} className="justify-content-center align-middle" style={{ paddingTop: '10px', fontSize: '18px', color: 'white', textAlign: 'center', borderRadius: '30px', width: '50px', height: '50px', backgroundColor: color }}>
+ {initials}
+ </div>
+ );
+};
+
+export default SenderInitials;