Files
platform/scripts/reimport-gmail.ts
T
pastilhasandClaude Opus 4.6 28f5cefb5b gmail sync: locale-agnostic folder mapping and import all mail
[Google Mail] locale variant was not matched by hardcoded [Gmail] paths,
so Sent/Starred/Important/Drafts were never labeled. All Mail was skipped
entirely, losing ~9k archived emails. Now normalizes the prefix, imports
everything with proper labels, and processes All Mail last so specific
folder labels take priority.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 09:29:22 +00:00

34 lines
1.0 KiB
TypeScript

import { join } from 'node:path';
import { unlinkSync } from 'node:fs';
import { openEmailDb } from '../src/servers/api/email/email-db';
import { importMaildir } from '../src/servers/queue/handlers/gmail-sync';
const DATA_PATH = process.env.DATA_PATH ?? join(process.cwd(), 'data');
const email = process.argv[2];
if (!email) {
console.error('Usage: bun scripts/reimport-gmail.ts <email>');
process.exit(1);
}
const maildirPath = join(DATA_PATH, email, 'Gmail', 'Maildir');
const dbPath = join(DATA_PATH, email, 'emails.db');
// Delete existing DB for a fresh import
try {
unlinkSync(dbPath);
console.log(`Deleted ${dbPath}`);
} catch {
console.log('No existing DB to delete');
}
const db = openEmailDb(email);
console.log(`Importing from ${maildirPath}...`);
const result = await importMaildir(maildirPath, email, db, (saved, skipped) => {
process.stdout.write(`\r saved ${saved}, skipped ${skipped}`);
});
console.log(`\nDone: saved ${result.saved}, skipped ${result.skipped}, errors ${result.errors}`);
db.close();