email: store emails.db per account under email_accounts/<account>/
Reorganizes email storage: the DB moves from DATA_PATH/<user>/emails.db to DATA_PATH/<user>/email_accounts/<accountEmail>/emails.db, with a shared email_accounts/attachment_cache/ (was Gmail/emails/attachments). openEmailDb now takes (owner, account); a new openUserEmailDb(owner, userId) resolves the user's configured account (first enabled) for read paths. Threads the account through email.ts, accounts, resync, queue sync, channel handlers, and the email_db MCP tool path. Drops the dead getUserEmailDir helper. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -6,7 +6,7 @@ import { chunkMessage } from './chunker';
|
||||
import { listPiModels } from '@@/api/pi/list-models';
|
||||
import { enqueueJob } from '../../queue/init';
|
||||
import { readJob } from '@@/queue/storage';
|
||||
import { openEmailDb } from '@@/api/email/email-db';
|
||||
import { openUserEmailDb } from '@@/api/email/email-db';
|
||||
import type { ModelInfo } from '@@/api/pi/types';
|
||||
import { toShellUsername } from '@@/data-path';
|
||||
|
||||
@@ -45,15 +45,17 @@ type CommandContext = {
|
||||
};
|
||||
|
||||
async function handleEmailSync(ctx: CommandContext): Promise<void> {
|
||||
const { channel, email } = ctx;
|
||||
const { channel, email, userId } = ctx;
|
||||
|
||||
// Count emails before sync
|
||||
let countBefore = 0;
|
||||
try {
|
||||
const db = openEmailDb(email);
|
||||
const row = db.query('SELECT COUNT(*) as count FROM emails WHERE deleted = 0').get() as { count: number };
|
||||
countBefore = row.count;
|
||||
db.close();
|
||||
const db = await openUserEmailDb(email, userId);
|
||||
if (db) {
|
||||
const row = db.query('SELECT COUNT(*) as count FROM emails WHERE deleted = 0').get() as { count: number };
|
||||
countBefore = row.count;
|
||||
db.close();
|
||||
}
|
||||
} catch {
|
||||
// DB might not exist yet
|
||||
}
|
||||
@@ -84,7 +86,8 @@ async function handleEmailSync(ctx: CommandContext): Promise<void> {
|
||||
|
||||
// Count emails after sync and get newest ones
|
||||
try {
|
||||
const db = openEmailDb(email);
|
||||
const db = await openUserEmailDb(email, userId);
|
||||
if (!db) return;
|
||||
const row = db.query('SELECT COUNT(*) as count FROM emails WHERE deleted = 0').get() as { count: number };
|
||||
const countAfter = row.count;
|
||||
const newCount = countAfter - countBefore;
|
||||
|
||||
@@ -7,7 +7,7 @@ import { getTelegramBot } from './bot';
|
||||
import { listPiModels } from '@@/api/pi/list-models';
|
||||
import { enqueueJob } from '../../queue/init';
|
||||
import { readJob } from '@@/queue/storage';
|
||||
import { openEmailDb } from '@@/api/email/email-db';
|
||||
import { openUserEmailDb } from '@@/api/email/email-db';
|
||||
import type { ModelInfo } from '@@/api/pi/types';
|
||||
import { toShellUsername } from '@@/data-path';
|
||||
|
||||
@@ -46,14 +46,16 @@ type CommandContext = {
|
||||
};
|
||||
|
||||
async function handleEmailSync(ctx: CommandContext): Promise<void> {
|
||||
const { send, email } = ctx;
|
||||
const { send, email, userId } = ctx;
|
||||
|
||||
let countBefore = 0;
|
||||
try {
|
||||
const db = openEmailDb(email);
|
||||
const row = db.query('SELECT COUNT(*) as count FROM emails WHERE deleted = 0').get() as { count: number };
|
||||
countBefore = row.count;
|
||||
db.close();
|
||||
const db = await openUserEmailDb(email, userId);
|
||||
if (db) {
|
||||
const row = db.query('SELECT COUNT(*) as count FROM emails WHERE deleted = 0').get() as { count: number };
|
||||
countBefore = row.count;
|
||||
db.close();
|
||||
}
|
||||
} catch {
|
||||
// DB might not exist yet
|
||||
}
|
||||
@@ -82,7 +84,8 @@ async function handleEmailSync(ctx: CommandContext): Promise<void> {
|
||||
}
|
||||
|
||||
try {
|
||||
const db = openEmailDb(email);
|
||||
const db = await openUserEmailDb(email, userId);
|
||||
if (!db) return;
|
||||
const row = db.query('SELECT COUNT(*) as count FROM emails WHERE deleted = 0').get() as { count: number };
|
||||
const countAfter = row.count;
|
||||
const newCount = countAfter - countBefore;
|
||||
|
||||
@@ -6,7 +6,7 @@ import { getWhatsAppClient } from './bot';
|
||||
import { listPiModels } from '@@/api/pi/list-models';
|
||||
import { enqueueJob } from '../../queue/init';
|
||||
import { readJob } from '@@/queue/storage';
|
||||
import { openEmailDb } from '@@/api/email/email-db';
|
||||
import { openUserEmailDb } from '@@/api/email/email-db';
|
||||
import type { ModelInfo } from '@@/api/pi/types';
|
||||
import { toShellUsername } from '@@/data-path';
|
||||
|
||||
@@ -50,14 +50,16 @@ type CommandContext = {
|
||||
};
|
||||
|
||||
async function handleEmailSync(ctx: CommandContext): Promise<void> {
|
||||
const { send, email } = ctx;
|
||||
const { send, email, userId } = ctx;
|
||||
|
||||
let countBefore = 0;
|
||||
try {
|
||||
const db = openEmailDb(email);
|
||||
const row = db.query('SELECT COUNT(*) as count FROM emails WHERE deleted = 0').get() as { count: number };
|
||||
countBefore = row.count;
|
||||
db.close();
|
||||
const db = await openUserEmailDb(email, userId);
|
||||
if (db) {
|
||||
const row = db.query('SELECT COUNT(*) as count FROM emails WHERE deleted = 0').get() as { count: number };
|
||||
countBefore = row.count;
|
||||
db.close();
|
||||
}
|
||||
} catch {
|
||||
// DB might not exist yet
|
||||
}
|
||||
@@ -86,7 +88,8 @@ async function handleEmailSync(ctx: CommandContext): Promise<void> {
|
||||
}
|
||||
|
||||
try {
|
||||
const db = openEmailDb(email);
|
||||
const db = await openUserEmailDb(email, userId);
|
||||
if (!db) return;
|
||||
const row = db.query('SELECT COUNT(*) as count FROM emails WHERE deleted = 0').get() as { count: number };
|
||||
const countAfter = row.count;
|
||||
const newCount = countAfter - countBefore;
|
||||
|
||||
Reference in New Issue
Block a user