Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Update email attachment indicators (#2159)
Leendert de Borst2022e0bf6248
diff --git a/apps/browser-extension/src/entrypoints/popup/components/EmailPreview.tsx b/apps/browser-extension/src/entrypoints/popup/components/EmailPreview.tsxindex fd2dc4b55..63e36db03 100644--- a/apps/browser-extension/src/entrypoints/popup/components/EmailPreview.tsx+++ b/apps/browser-extension/src/entrypoints/popup/components/EmailPreview.tsx@@ -2,6 +2,7 @@ import React, { useState, useEffect } from 'react';import { useTranslation } from 'react-i18next';import { Link, useLocation } from 'react-router-dom';+import { AttachmentIcon } from '@/entrypoints/popup/components/Icons/AttachmentIcon';import { useDb } from '@/entrypoints/popup/context/DbContext';import { useWebApi } from '@/entrypoints/popup/context/WebApiContext';@@ -287,8 +288,9 @@ export const EmailPreview: React.FC<EmailPreviewProps> = ({ email }) => {{mail.subject.substring(0, 30)}{mail.subject.length > 30 ? '...' : ''}</span></div>- <div className="text-xs text-gray-500 dark:text-gray-400 ml-2">- {new Date(mail.dateSystem).toLocaleDateString()}+ <div className="flex items-center gap-1 text-xs text-gray-500 dark:text-gray-400 ml-2 flex-shrink-0">+ {mail.hasAttachments && <AttachmentIcon className="w-3.5 h-3.5" />}+ <span>{new Date(mail.dateSystem).toLocaleDateString()}</span></div></a>) : (@@ -305,8 +307,9 @@ export const EmailPreview: React.FC<EmailPreviewProps> = ({ email }) => {{mail.subject.substring(0, 30)}{mail.subject.length > 30 ? '...' : ''}</span></span>- <span className="text-xs text-gray-500 dark:text-gray-400 ml-2">- {new Date(mail.dateSystem).toLocaleDateString()}+ <span className="flex items-center gap-1 text-xs text-gray-500 dark:text-gray-400 ml-2 flex-shrink-0">+ {mail.hasAttachments && <AttachmentIcon className="w-3.5 h-3.5" />}+ <span>{new Date(mail.dateSystem).toLocaleDateString()}</span></span></Link>)diff --git a/apps/browser-extension/src/entrypoints/popup/components/Icons/AttachmentIcon.tsx b/apps/browser-extension/src/entrypoints/popup/components/Icons/AttachmentIcon.tsxnew file mode 100644index 000000000..af99c0d05--- /dev/null+++ b/apps/browser-extension/src/entrypoints/popup/components/Icons/AttachmentIcon.tsx@@ -0,0 +1,26 @@+import React from 'react';++type AttachmentIconProps = {+ className?: string;+};++/**+ * Paperclip icon used to indicate that an email carries attachments.+ */+export const AttachmentIcon: React.FC<AttachmentIconProps> = ({ className = 'w-4 h-4' }) => (+ <svg+ className={className}+ fill="none"+ stroke="currentColor"+ viewBox="0 0 24 24"+ xmlns="http://www.w3.org/2000/svg"+ aria-hidden="true"+ >+ <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"+ />+ </svg>+);diff --git a/apps/browser-extension/src/entrypoints/popup/pages/emails/EmailDetails.tsx b/apps/browser-extension/src/entrypoints/popup/pages/emails/EmailDetails.tsxindex 55880ae66..abca2c818 100644--- a/apps/browser-extension/src/entrypoints/popup/pages/emails/EmailDetails.tsx+++ b/apps/browser-extension/src/entrypoints/popup/pages/emails/EmailDetails.tsx@@ -1,8 +1,9 @@-import React, { useEffect, useMemo, useState, useCallback } from 'react';+import React, { useEffect, useMemo, useRef, useState, useCallback } from 'react';import { useTranslation } from 'react-i18next';import { Link, useParams, useNavigate, useSearchParams } from 'react-router-dom';import Modal from '@/entrypoints/popup/components/Dialogs/Modal';+import { AttachmentIcon } from '@/entrypoints/popup/components/Icons/AttachmentIcon';import LoadingSpinner from '@/entrypoints/popup/components/LoadingSpinner';import { useDb } from '@/entrypoints/popup/context/DbContext';import { useHeaderButtons } from '@/entrypoints/popup/context/HeaderButtonsContext';@@ -11,7 +12,7 @@ import { useWebApi } from '@/entrypoints/popup/context/WebApiContext';import ConversionUtility from '@/entrypoints/popup/utils/ConversionUtility';import { PopoutUtility } from '@/entrypoints/popup/utils/PopoutUtility';-import type { EmailAttachment, Email } from '@/utils/dist/core/models/webapi';+import type { Email } from '@/utils/dist/core/models/webapi';import EncryptionUtility, { type DecryptedEmail } from '@/utils/EncryptionUtility';import { decodeEmailSource, extractEmailAttachment, type ParsedEmailAttachment } from '@/utils/RustCore';@@ -40,6 +41,7 @@ const EmailDetails: React.FC = (): React.ReactElement => {const [showMetadata, setShowMetadata] = useState(false);const [viewMode, setViewMode] = useState<'html' | 'plain' | 'source'>('html');const [credential, setCredential] = useState<{ id: string; name: string } | null>(null);+ const attachmentsRef = useRef<HTMLDivElement>(null);const { setIsInitialLoading } = useLoading();const { setHeaderButtons } = useHeaderButtons();@@ -241,38 +243,6 @@ const EmailDetails: React.FC = (): React.ReactElement => {}};- /**- * Handle downloading an attachment stored as a separate record (legacy emails): fetch the- * encrypted bytes from the API and decrypt them locally.- */- const handleDownloadAttachment = async (attachment: EmailAttachment): Promise<void> => {- try {- // Get the encrypted attachment bytes from the API- const encryptedBytes = await webApi.downloadBlob(`Email/${id}/attachments/${attachment.id}`);-- if (!dbContext?.sqliteClient || !email) {- setError('Database context or email not available');- return;- }-- // Get encryption keys for decryption- const encryptionKeys = dbContext.sqliteClient.encryptionKeys.getAll();-- // Decrypt the attachment using raw bytes- const decryptedBytes = await EncryptionUtility.decryptAttachment(encryptedBytes, email, encryptionKeys);-- if (!decryptedBytes) {- setError('Failed to decrypt attachment');- return;- }-- triggerAttachmentDownload(new Uint8Array(decryptedBytes), attachment.mimeType, attachment.filename);- } catch (err) {- console.error('handleDownloadAttachment error', err);- setError(err instanceof Error ? err.message : 'Failed to download attachment');- }- };-/** Set header buttons whenever the available formats or active view mode change so the* format-cycle button label stays in sync. Mirrors the web app's header layout.@@ -375,6 +345,16 @@ const EmailDetails: React.FC = (): React.ReactElement => {</svg></button></div>+ {parsedAttachments.length > 0 && (+ <button+ onClick={() => attachmentsRef.current?.scrollIntoView({ behavior: 'smooth', block: 'start' })}+ className="flex items-center gap-1 flex-shrink-0 px-2 py-1 rounded-full text-sm text-gray-600 dark:text-gray-300 bg-gray-100 dark:bg-gray-700 hover:bg-gray-200 dark:hover:bg-gray-600 transition-colors"+ title={t('common.attachments')}+ >+ <AttachmentIcon className="w-4 h-4" />+ <span>{parsedAttachments.length}</span>+ </button>+ )}</div>{showMetadata && (<div className="space-y-1 text-sm text-gray-600 dark:text-gray-400 mt-2">@@ -421,13 +401,13 @@ const EmailDetails: React.FC = (): React.ReactElement => {</div>{/* Attachments */}- {(parsedAttachments.length > 0 || (email.attachments && email.attachments.length > 0)) && (- <div className="p-6 border-t border-gray-200 dark:border-gray-700">+ {parsedAttachments.length > 0 && (+ <div ref={attachmentsRef} className="p-6 border-t border-gray-200 dark:border-gray-700"><h2 className="text-lg font-semibold mb-4 text-gray-900 dark:text-white">{t('common.attachments')}</h2><div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-4">- {parsedAttachments.length > 0 ? parsedAttachments.map((attachment, index) => (+ {parsedAttachments.map((attachment, index) => (<buttonkey={index}onClick={() => handleDownloadParsedAttachment(attachment, index)}@@ -450,29 +430,6 @@ const EmailDetails: React.FC = (): React.ReactElement => {{attachment.filename} ({Math.ceil(attachment.size / 1024)} KB)</span></button>- )) : email.attachments.map((attachment) => (- <button- key={attachment.id}- onClick={() => handleDownloadAttachment(attachment)}- className="flex items-center space-x-2 text-sm text-gray-600 dark:text-gray-400 hover:text-primary-600 dark:hover:text-primary-400 text-left"- >- <svg- className="w-4 h-4"- fill="none"- stroke="currentColor"- viewBox="0 0 24 24"- >- <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"- />- </svg>- <span>- {attachment.filename} ({Math.ceil(attachment.filesize / 1024)} KB)- </span>- </button>))}</div></div>diff --git a/apps/browser-extension/src/entrypoints/popup/pages/emails/EmailsList.tsx b/apps/browser-extension/src/entrypoints/popup/pages/emails/EmailsList.tsxindex 43082e7ec..5d7e2a65c 100644--- a/apps/browser-extension/src/entrypoints/popup/pages/emails/EmailsList.tsx+++ b/apps/browser-extension/src/entrypoints/popup/pages/emails/EmailsList.tsx@@ -3,6 +3,7 @@ import { useTranslation } from 'react-i18next';import { Link } from 'react-router-dom';import HeaderButton from '@/entrypoints/popup/components/HeaderButton';+import { AttachmentIcon } from '@/entrypoints/popup/components/Icons/AttachmentIcon';import { HeaderIconType } from '@/entrypoints/popup/components/Icons/HeaderIcons';import LoadingSpinner from '@/entrypoints/popup/components/LoadingSpinner';import PageTitle from '@/entrypoints/popup/components/PageTitle';@@ -267,8 +268,9 @@ const EmailsList: React.FC = () => {<div className="text-gray-900 dark:text-white mb-1 font-bold">{email.subject}</div>- <div className="text-sm text-gray-500 dark:text-gray-400">- {formatEmailDate(email.dateSystem)}+ <div className="flex items-center gap-1.5 flex-shrink-0 text-sm text-gray-500 dark:text-gray-400">+ {email.hasAttachments && <AttachmentIcon className="w-4 h-4" />}+ <span>{formatEmailDate(email.dateSystem)}</span></div></div><div className="text-gray-600 text-sm dark:text-gray-300 line-clamp-2">diff --git a/apps/browser-extension/src/utils/__tests__/EncryptionUtility.crypto.test.ts b/apps/browser-extension/src/utils/__tests__/EncryptionUtility.crypto.test.tsindex 00d0901b8..59f2a248f 100644--- a/apps/browser-extension/src/utils/__tests__/EncryptionUtility.crypto.test.ts+++ b/apps/browser-extension/src/utils/__tests__/EncryptionUtility.crypto.test.ts@@ -48,7 +48,6 @@ async function createEmail(): Promise<Email> {return {messageSource: '',- attachmentCount: 0,id: 1,subject: '',fromDisplay: '',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.tsindex 8cf670e99..cd33cebe7 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@@ -187,7 +187,6 @@ type MailboxBulkRequest = {* Mailbox bulk response type.*/type MailboxBulkResponse = {- addresses: string[];currentPage: number;pageSize: number;totalRecords: number;@@ -214,8 +213,6 @@ type EmailAttachment = {type Email = {/** The raw RFC 822 source of the email message (ciphertext, base64) */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 */@@ -240,8 +237,6 @@ type Email = {decryptionKeys: EmailDecryptionKey[];/** The public keys referenced by this email's decryption keys, indexed by EmailDecryptionKey.keyIndex */publicKeys: string[];- /** The attachments of the email */- attachments: EmailAttachment[];};/**diff --git a/apps/mobile-app/utils/dist/core/models/webapi/index.d.ts b/apps/mobile-app/utils/dist/core/models/webapi/index.d.tsindex 8cf670e99..cd33cebe7 100644--- a/apps/mobile-app/utils/dist/core/models/webapi/index.d.ts+++ b/apps/mobile-app/utils/dist/core/models/webapi/index.d.ts@@ -187,7 +187,6 @@ type MailboxBulkRequest = {* Mailbox bulk response type.*/type MailboxBulkResponse = {- addresses: string[];currentPage: number;pageSize: number;totalRecords: number;@@ -214,8 +213,6 @@ type EmailAttachment = {type Email = {/** The raw RFC 822 source of the email message (ciphertext, base64) */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 */@@ -240,8 +237,6 @@ type Email = {decryptionKeys: EmailDecryptionKey[];/** The public keys referenced by this email's decryption keys, indexed by EmailDecryptionKey.keyIndex */publicKeys: string[];- /** The attachments of the email */- attachments: EmailAttachment[];};/**