diff --git a/src/app/api/page.tsx b/src/app/api/page.tsx
index af0a78a..b75b49b 100644
--- a/src/app/api/page.tsx
+++ b/src/app/api/page.tsx
@@ -44,19 +44,17 @@ export default function Component() {
{`[
{
- "id": "{inboxId}",
- "subject": "Test",
- "createdAt": 1732026087000,
- "expiresAt": 1732285287596,
- "fromAddress": "example@gmail.com",
- "toAddress": "{email}",
- "ccAddress": null,
- "bccAddress": null
+ "id": "cm3sqher40005276o336z4fvw",
+ "subject": "Test Email",
+ "createdAt": 1732279492000,
+ "expiresAt": 1732538692335,
+ "fromAddress": "sender@example.com",
+ "toAddress": "recipient@vwh.sh"
}
]`}
@@ -103,14 +101,14 @@ export default function Component() {
{`{
- "id": "{inboxId}",
- "textContent": "Hello\\n",
- "htmlContent": "\\n",
- "subject": "Test",
- "expiresAt": 1732285287596,
- "createdAt": 1732026087000,
- "fromAddress": "example@gmail.com",
- "toAddress": "example@vwh.sh"
+ "id": "cm3sqher40005276o336z4fvw",
+ "textContent": "This is a test email body.\n",
+ "htmlContent": null,
+ "subject": "Test Email",
+ "expiresAt": 1732538692335,
+ "createdAt": 1732279492000,
+ "fromAddress": "sender@example.com",
+ "toAddress": "recipient@vwh.sh"
}`}
diff --git a/src/database/db.ts b/src/database/db.ts
index 9ac0b7d..48f0be2 100644
--- a/src/database/db.ts
+++ b/src/database/db.ts
@@ -41,8 +41,6 @@ export function insertEmail(
const recipientGroups = [
{ type: "from", values: emailData.from?.value || [] },
{ type: "to", values: emailData.to?.value || [] },
- { type: "cc", values: emailData.cc?.value || [] },
- { type: "bcc", values: emailData.bcc?.value || [] }
];
for (const { type, values } of recipientGroups) {
@@ -56,24 +54,15 @@ export function insertEmail(
// Insert inbox entries
const allRecipients = [
...(emailData.to?.value || []),
- ...(emailData.cc?.value || []),
- ...(emailData.bcc?.value || [])
];
for (const recipient of allRecipients) {
- const type = emailData.to?.value?.includes(recipient)
- ? "to"
- : emailData.cc?.value?.includes(recipient)
- ? "cc"
- : "bcc";
-
insertInbox.run(
cuid(),
emailId,
recipient.address,
- type,
- emailData.text ?? null,
- emailData.html ?? null
+ emailData.text,
+ emailData.html
);
}
diff --git a/src/database/statements.ts b/src/database/statements.ts
index e7f671b..f1ed6a7 100644
--- a/src/database/statements.ts
+++ b/src/database/statements.ts
@@ -7,13 +7,12 @@ export const SQL_STATEMENTS = {
id INTEGER PRIMARY KEY AUTOINCREMENT,
subject TEXT,
createdAt INTEGER DEFAULT (strftime('%s', 'now') * 1000),
- expiresAt DATETIME
+ expiresAt DATETIME
);
CREATE TABLE IF NOT EXISTS Inbox (
id TEXT PRIMARY KEY,
address TEXT,
- type TEXT, -- Can be 'to', 'cc', 'bcc'
textContent TEXT,
htmlContent TEXT,
createdAt INTEGER DEFAULT (strftime('%s', 'now') * 1000),
@@ -24,7 +23,7 @@ export const SQL_STATEMENTS = {
CREATE TABLE IF NOT EXISTS EmailAddress (
id INTEGER PRIMARY KEY AUTOINCREMENT,
- type TEXT, -- Can be 'from', 'to', 'cc', 'bcc'
+ type TEXT, -- Can be 'from', 'to'
address TEXT,
emailId INTEGER,
@@ -32,73 +31,45 @@ export const SQL_STATEMENTS = {
);
`,
- // Create indexes
- CREATE_INDEX: `
+ CREATE_INDEX: `
CREATE INDEX IF NOT EXISTS idx_email_id ON EmailAddress(emailId);
CREATE INDEX IF NOT EXISTS idx_inbox_address ON Inbox(address);
`,
- // PRAGMA settings for performance optimization
PRAGMA: `
PRAGMA foreign_keys = ON;
PRAGMA journal_mode = WAL;
PRAGMA synchronous = NORMAL;
- `,
+ `,
- // Insert statement for Email
INSERT_EMAIL: `
- INSERT INTO Email
- (subject, expiresAt)
+ INSERT INTO Email (subject, expiresAt)
VALUES (?, ?)
- `,
+ `,
- // Insert statement for Inbox
INSERT_INBOX: `
- INSERT INTO Inbox
- (id, emailId, address, type, textContent, htmlContent)
- VALUES (?, ?, ?, ?, ?, ?)
- `,
+ INSERT INTO Inbox (id, emailId, address, textContent, htmlContent)
+ VALUES (?, ?, ?, ?, ?)
+ `,
- // Insert statement for EmailAddress
INSERT_EMAIL_ADDRESS: `
- INSERT INTO EmailAddress
- (emailId, type, address)
+ INSERT INTO EmailAddress (emailId, type, address)
VALUES (?, ?, ?)
- `,
+ `,
- // For fetching emails for a specific address
GET_EMAILS_FOR_ADDRESS: `
SELECT
Inbox.id,
Email.subject,
Email.createdAt,
Email.expiresAt,
- (SELECT EmailAddress.address
- FROM EmailAddress
- WHERE EmailAddress.emailId = Email.id AND EmailAddress.type = 'from') as fromAddress,
- GROUP_CONCAT(
- CASE
- WHEN EmailAddress.type = 'to' THEN EmailAddress.address
- ELSE NULL
- END, ', ') as toAddress,
- GROUP_CONCAT(
- CASE
- WHEN EmailAddress.type = 'cc' THEN EmailAddress.address
- ELSE NULL
- END, ', ') as ccAddress,
- GROUP_CONCAT(
- CASE
- WHEN EmailAddress.type = 'bcc' THEN EmailAddress.address
- ELSE NULL
- END, ', ') as bccAddress
+ (SELECT address FROM EmailAddress WHERE emailId = Email.id AND type = 'from') as fromAddress,
+ (SELECT GROUP_CONCAT(address, ', ') FROM EmailAddress WHERE emailId = Email.id AND type = 'to') as toAddress
FROM Email
JOIN Inbox ON Email.id = Inbox.emailId
- LEFT JOIN EmailAddress ON Email.id = EmailAddress.emailId
WHERE Inbox.address = ?
- GROUP BY Email.id;
`,
- // For fetching email by inbox ID (to get the full body)
GET_INBOX_BY_ID: `
SELECT
Inbox.id,
@@ -107,24 +78,18 @@ export const SQL_STATEMENTS = {
Email.subject,
Email.expiresAt,
Email.createdAt,
- (SELECT EmailAddress.address FROM EmailAddress WHERE EmailAddress.emailId = Email.id AND EmailAddress.type = 'from') as fromAddress,
- GROUP_CONCAT(EmailAddress.address, ', ') as toAddress
+ (SELECT address FROM EmailAddress WHERE emailId = Email.id AND type = 'from') as fromAddress,
+ (SELECT GROUP_CONCAT(address, ', ') FROM EmailAddress WHERE emailId = Email.id AND type = 'to') as toAddress
FROM Inbox
JOIN Email ON Inbox.emailId = Email.id
- LEFT JOIN EmailAddress ON Email.id = EmailAddress.emailId AND EmailAddress.type = 'to'
WHERE Inbox.id = ?
- GROUP BY Email.id
`,
- // Delete email by inbox ID
DELETE_BY_INBOX_ID: `
- DELETE FROM Inbox
- WHERE id = ?
+ DELETE FROM Inbox WHERE id = ?
`,
- // To delete expired entries
DELETE_EXPIRED_ENTRIES: `
- DELETE FROM Email
- WHERE expiresAt < strftime('%s', 'now') * 1000;
- `
+ DELETE FROM Email WHERE expiresAt < strftime('%s', 'now') * 1000
+ `
};
diff --git a/src/utils/emails.ts b/src/utils/emails.ts
index f5952bd..558ccae 100644
--- a/src/utils/emails.ts
+++ b/src/utils/emails.ts
@@ -27,8 +27,6 @@ export function simplifyEmail(email: ParsedMail): SimplifiedEmail {
id: email.messageId || "",
from: convertAddress(email.from),
to: convertAddress(email.to),
- cc: convertAddress(email.cc),
- bcc: convertAddress(email.bcc),
subject: email.subject || null,
text: email.text || null,
html: email.html || null,
diff --git a/src/utils/zod.ts b/src/utils/zod.ts
index 0e95656..6012daf 100644
--- a/src/utils/zod.ts
+++ b/src/utils/zod.ts
@@ -21,8 +21,6 @@ export const emailSchema = z.object({
id: z.string(),
from: emailAddressSchema.nullable(),
to: emailAddressSchema.nullable(),
- cc: emailAddressSchema.nullable(),
- bcc: emailAddressSchema.nullable(),
subject: z.string().nullable(),
text: z.string().nullable(),
html: z.string().nullable(),