Skip to content

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

Add popout and public email support to credential view (#541)

Leendert de Borstf30789f906ee
diff --git a/browser-extensions/chrome/package.json b/browser-extensions/chrome/package.json
index 4abead150..d9f14dd7a 100644
--- a/browser-extensions/chrome/package.json
+++ b/browser-extensions/chrome/package.json
@@ -10,8 +10,7 @@
"lint": "eslint src",
"lint:custom": "eslint",
"lint:fix": "eslint src --fix",
- "build": "vite build",
- "watch": "vite build --watch --mode development"
+ "build": "vite build"
},
"keywords": [],
"author": "",
diff --git a/browser-extensions/chrome/src/app/components/EmailPreview.tsx b/browser-extensions/chrome/src/app/components/EmailPreview.tsx
index a970b9c71..3ef476247 100644
--- a/browser-extensions/chrome/src/app/components/EmailPreview.tsx
+++ b/browser-extensions/chrome/src/app/components/EmailPreview.tsx
@@ -17,62 +17,113 @@ export const EmailPreview: React.FC<EmailPreviewProps> = ({ email }) => {
const [emails, setEmails] = useState<MailboxEmail[]>([]);
const [loading, setLoading] = useState(true);
const [lastEmailId, setLastEmailId] = useState<number>(0);
+ const [isSpamOk, setIsSpamOk] = useState(false);
const webApi = useWebApi();
const dbContext = useDb();
+ const isPublicDomain = async (emailAddress: string): Promise<boolean> => {
+ // Get metadata from storage
+ const storageResult = await chrome.storage.session.get(['publicEmailDomains']);
+ return storageResult.publicEmailDomains.some(domain => emailAddress.toLowerCase().endsWith(domain));
+ };
+
useEffect(() => {
/**
- * Loads the latest emails from the server and decrypts them locally.
+ * Loads the latest emails from the server and decrypts them locally if needed.
*/
const loadEmails = async (): Promise<void> => {
try {
- const response = await webApi.get(`EmailBox/${email}`);
- const data = response as { mails: MailboxEmail[] };
-
- // Only show the latest 2 emails to save space in UI.
- const latestMails = data?.mails.sort((a, b) => new Date(b.dateSystem).getTime() - new Date(a.dateSystem).getTime()).slice(0, 2);
-
- if (latestMails) {
- // Loop through all emails and decrypt them locally
- const decryptedEmails: MailboxEmail[] = await Promise.all(latestMails.map(async (mail: MailboxEmail) => {
- try {
- // Decrypt email locally using private key
- const encryptionKeys = dbContext.sqliteClient!.getAllEncryptionKeys();
- const encryptionKey = encryptionKeys.find(key => key.PublicKey === mail.encryptionKey);
-
- if (!encryptionKey) {
- throw new Error('Encryption key not found');
- }
-
- // Decrypt symmetric key with asymmetric private key
- const symmetricKey = await EncryptionUtility.decryptWithPrivateKey(
- mail.encryptedSymmetricKey,
- encryptionKey.PrivateKey
- );
- const symmetricKeyBase64 = Buffer.from(symmetricKey).toString('base64');
-
- // Create a new object to avoid mutating the original
- const decryptedMail = { ...mail };
-
- // Decrypt all email fields
- decryptedMail.subject = await EncryptionUtility.symmetricDecrypt(mail.subject, symmetricKeyBase64);
- decryptedMail.fromDisplay = await EncryptionUtility.symmetricDecrypt(mail.fromDisplay, symmetricKeyBase64);
- decryptedMail.fromDomain = await EncryptionUtility.symmetricDecrypt(mail.fromDomain, symmetricKeyBase64);
- decryptedMail.fromLocal = await EncryptionUtility.symmetricDecrypt(mail.fromLocal, symmetricKeyBase64);
- decryptedMail.messagePreview = await EncryptionUtility.symmetricDecrypt(mail.messagePreview, symmetricKeyBase64);
-
- return decryptedMail;
- } catch (error) {
- console.error('Error decrypting email:', error);
- return mail; // Return original mail if decryption fails
+ const isPublic = await isPublicDomain(email);
+ setIsSpamOk(isPublic);
+
+ if (isPublic) {
+ // For public domains (SpamOK), use their API directly
+ const emailPrefix = email.split('@')[0];
+ const response = await fetch(`https://api.spamok.com/v2/EmailBox/${emailPrefix}`);
+ const data = await response.json();
+
+ // Only show the latest 2 emails to save space in UI
+ const latestMails = data?.mails
+ ?.sort((a: MailboxEmail, b: MailboxEmail) =>
+ new Date(b.dateSystem).getTime() - new Date(a.dateSystem).getTime())
+ ?.slice(0, 2) || [];
+
+ if (loading && latestMails.length > 0) {
+ setLastEmailId(latestMails[0].id);
+ }
+
+ setEmails(latestMails);
+ } else {
+ // For private domains, use existing encrypted email logic
+ const response = await webApi.get(`EmailBox/${email}`);
+ const data = response as { mails: MailboxEmail[] };
+
+ // Only show the latest 2 emails to save space in UI
+ const latestMails = data?.mails
+ .sort((a, b) => new Date(b.dateSystem).getTime() - new Date(a.dateSystem).getTime())
+ .slice(0, 2);
+
+ if (latestMails) {
+ // Loop through all emails and decrypt them locally
+ const decryptedEmails: MailboxEmail[] = await Promise.all(
+ latestMails.map(async (mail: MailboxEmail) => {
+ try {
+ // Decrypt email locally using private key
+ const encryptionKeys = dbContext.sqliteClient!.getAllEncryptionKeys();
+ const encryptionKey = encryptionKeys.find(
+ key => key.PublicKey === mail.encryptionKey
+ );
+
+ if (!encryptionKey) {
+ throw new Error('Encryption key not found');
+ }
+
+ // Decrypt symmetric key with asymmetric private key
+ const symmetricKey = await EncryptionUtility.decryptWithPrivateKey(
+ mail.encryptedSymmetricKey,
+ encryptionKey.PrivateKey
+ );
+ const symmetricKeyBase64 = Buffer.from(symmetricKey).toString('base64');
+
+ // Create a new object to avoid mutating the original
+ const decryptedMail = { ...mail };
+
+ // Decrypt all email fields
+ decryptedMail.subject = await EncryptionUtility.symmetricDecrypt(
+ mail.subject,
+ symmetricKeyBase64
+ );
+ decryptedMail.fromDisplay = await EncryptionUtility.symmetricDecrypt(
+ mail.fromDisplay,
+ symmetricKeyBase64
+ );
+ decryptedMail.fromDomain = await EncryptionUtility.symmetricDecrypt(
+ mail.fromDomain,
+ symmetricKeyBase64
+ );
+ decryptedMail.fromLocal = await EncryptionUtility.symmetricDecrypt(
+ mail.fromLocal,
+ symmetricKeyBase64
+ );
+ decryptedMail.messagePreview = await EncryptionUtility.symmetricDecrypt(
+ mail.messagePreview,
+ symmetricKeyBase64
+ );
+
+ return decryptedMail;
+ } catch (error) {
+ console.error('Error decrypting email:', error);
+ return mail; // Return original mail if decryption fails
+ }
+ })
+ );
+
+ if (loading && decryptedEmails.length > 0) {
+ setLastEmailId(decryptedEmails[0].id);
}
- }));
- if (loading) {
- setLastEmailId(decryptedEmails[0].id);
+ setEmails(decryptedEmails);
}
-
- setEmails(decryptedEmails);
}
} catch (err) {
console.error('Error loading emails:', err);
@@ -117,24 +168,47 @@ export const EmailPreview: React.FC<EmailPreviewProps> = ({ email }) => {
</div>
{emails.map((mail) => (
- <Link
- key={mail.id}
- to={`/emails/${mail.id}`}
- className={`flex justify-between items-center p-2 rounded cursor-pointer block bg-white dark:bg-gray-800 shadow hover:shadow-md transition-all border border-gray-200 dark:border-gray-700 ${
- mail.id > lastEmailId
- ? 'bg-yellow-50 dark:bg-yellow-900/30'
- : 'hover:bg-gray-50 dark:hover:bg-gray-700'
- }`}
- >
- <div className="truncate flex-1">
- <span className="text-sm text-gray-900 dark:text-white">
- {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>
- </Link>
+ isSpamOk ? (
+ <a
+ key={mail.id}
+ href={`https://spamok.com/${email.split('@')[0]}/${mail.id}`}
+ target="_blank"
+ rel="noopener noreferrer"
+ className={`flex justify-between items-center p-2 rounded cursor-pointer block bg-white dark:bg-gray-800 shadow hover:shadow-md transition-all border border-gray-200 dark:border-gray-700 ${
+ mail.id > lastEmailId
+ ? 'bg-yellow-50 dark:bg-yellow-900/30'
+ : 'hover:bg-gray-50 dark:hover:bg-gray-700'
+ }`}
+ >
+ <div className="truncate flex-1">
+ <span className="text-sm text-gray-900 dark:text-white">
+ {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>
+ </a>
+ ) : (
+ <Link
+ key={mail.id}
+ to={`/emails/${mail.id}`}
+ className={`flex justify-between items-center p-2 rounded cursor-pointer block bg-white dark:bg-gray-800 shadow hover:shadow-md transition-all border border-gray-200 dark:border-gray-700 ${
+ mail.id > lastEmailId
+ ? 'bg-yellow-50 dark:bg-yellow-900/30'
+ : 'hover:bg-gray-50 dark:hover:bg-gray-700'
+ }`}
+ >
+ <div className="truncate flex-1">
+ <span className="text-sm text-gray-900 dark:text-white">
+ {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>
+ </Link>
+ )
))}
</div>
);
diff --git a/browser-extensions/chrome/src/app/pages/CredentialDetails.tsx b/browser-extensions/chrome/src/app/pages/CredentialDetails.tsx
index fcc777a0b..d9c9176d4 100644
--- a/browser-extensions/chrome/src/app/pages/CredentialDetails.tsx
+++ b/browser-extensions/chrome/src/app/pages/CredentialDetails.tsx
@@ -99,13 +99,19 @@ const CredentialDetails: React.FC = () => {
title="Open in new window"
>
<svg
- xmlns="http://www.w3.org/2000/svg"
- className="h-6 w-6"
- viewBox="0 0 20 20"
- fill="currentColor"
- >
- <path d="M3 4a1 1 0 011-1h4a1 1 0 010 2H6.414l2.293 2.293a1 1 0 11-1.414 1.414L5 6.414V8a1 1 0 01-2 0V4zm13 0a1 1 0 00-1-1h-4a1 1 0 100 2h1.586l-2.293 2.293a1 1 0 001.414 1.414L14 6.414V8a1 1 0 102 0V4zM3 16a1 1 0 001 1h4a1 1 0 100-2H6.414l2.293-2.293a1 1 0 00-1.414-1.414L5 13.586V12a1 1 0 10-2 0v4zm13 0a1 1 0 01-1 1h-4a1 1 0 110-2h1.586l-2.293-2.293a1 1 0 011.414-1.414L14 13.586V12a1 1 0 112 0v4z" />
- </svg>
+ className="w-5 h-5"
+ fill="none"
+ stroke="currentColor"
+ viewBox="0 0 24 24"
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <path
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth={2}
+ d="M4 8V4m0 0h4M4 4l5 5m11-1V4m0 0h-4m4 0l-5 5M4 16v4m0 0h4m-4 0l5-5m11 5l-5-5m5 5v-4m0 4h-4"
+ />
+ </svg>
</button>
</div>
@@ -118,8 +124,8 @@ const CredentialDetails: React.FC = () => {
)}
</div>
- <div className="grid gap-6 md:grid-cols-2">
- <div className="space-y-4">
+ <div className="grid gap-6">
+ <div className="space-y-4 lg:col-span-2 xl:col-span-1">
<h2 className="text-xl font-semibold text-gray-900 dark:text-white">Login credentials</h2>
<FormInputCopyToClipboard
id="email"
@@ -171,7 +177,7 @@ const CredentialDetails: React.FC = () => {
</div>
{credential.Notes && (
- <div className="space-y-4">
+ <div className="space-y-4 lg:col-span-2 xl:col-span-1">
<h2 className="text-xl font-semibold text-gray-900 dark:text-white">Notes</h2>
<div className="p-4 bg-gray-50 rounded-lg dark:bg-gray-700">
<p className="text-gray-900 dark:text-gray-100 whitespace-pre-wrap">
diff --git a/browser-extensions/chrome/src/app/pages/EmailDetails.tsx b/browser-extensions/chrome/src/app/pages/EmailDetails.tsx
index e7275e220..2ab0fba94 100644
--- a/browser-extensions/chrome/src/app/pages/EmailDetails.tsx
+++ b/browser-extensions/chrome/src/app/pages/EmailDetails.tsx
@@ -21,6 +21,13 @@ const EmailDetails: React.FC = () => {
const [isLoading, setIsLoading] = useMinDurationLoading(true, 150);
useEffect(() => {
+ // For popup windows, ensure we have proper history state for navigation
+ if (isPopup()) {
+ // Clear existing history and create fresh entries
+ window.history.replaceState({}, '', `index.html#/emails`);
+ window.history.pushState({}, '', `index.html#/emails/${id}`);
+ }
+
/**
* Load the email.
*/
@@ -86,6 +93,33 @@ const EmailDetails: React.FC = () => {
}
};
+ /**
+ * Check if the current page is a popup.
+ */
+ const isPopup = () : boolean => {
+ const urlParams = new URLSearchParams(window.location.search);
+ return urlParams.get('popup') === 'true';
+ };
+
+ /**
+ * Open the credential details in a new popup.
+ */
+ const openInNewPopup = () : void => {
+ const width = 800;
+ const height = 1000;
+ const left = window.screen.width / 2 - width / 2;
+ const top = window.screen.height / 2 - height / 2;
+
+ window.open(
+ `index.html?popup=true#/emails/${id}`,
+ 'EmailDetails',
+ `width=${width},height=${height},left=${left},top=${top},popup=true`
+ );
+
+ // Close the current tab
+ window.close();
+ };
+
if (isLoading) {
return (
<div className="flex justify-center items-center p-8">
@@ -110,6 +144,26 @@ const EmailDetails: React.FC = () => {
<div className="flex justify-between items-start mb-4">
<h1 className="text-2xl font-bold text-gray-900 dark:text-white">{email.subject}</h1>
<div className="flex space-x-2">
+ <button
+ onClick={openInNewPopup}
+ className="text-gray-600 hover:text-gray-900 dark:text-gray-400 dark:hover:text-white"
+ title="Open in new window"
+ >
+ <svg
+ className="w-5 h-5"
+ fill="none"
+ stroke="currentColor"
+ viewBox="0 0 24 24"
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <path
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth={2}
+ d="M4 8V4m0 0h4M4 4l5 5m11-1V4m0 0h-4m4 0l-5 5M4 16v4m0 0h4m-4 0l5-5m11 5l-5-5m5 5v-4m0 4h-4"
+ />
+ </svg>
+ </button>
<button
onClick={handleDelete}
className="p-2 text-red-500 hover:text-red-600 rounded-md hover:bg-red-100 dark:hover:bg-red-900/20"
diff --git a/browser-extensions/chrome/vite.config.js b/browser-extensions/chrome/vite.config.js
index b3c9c9ca3..db1b95b6c 100644
--- a/browser-extensions/chrome/vite.config.js
+++ b/browser-extensions/chrome/vite.config.js
@@ -43,4 +43,9 @@ export default defineConfig({
'@': '/src'
}
},
+ build: {
+ watch: process.env.NODE_ENV === 'development' ? {
+ include: ['src/**', 'manifest.json'],
+ } : null
+ }
});