Skip to main content
Glama
count-all-emails.jsβ€’5.22 kB
#!/usr/bin/env node import { FastMailClient } from '../src/fastmail-client.js'; import dotenv from 'dotenv'; dotenv.config({ path: '../.env' }); async function countAllEmails() { console.log('πŸ“Š COUNTING ALL EMAILS IN ENTIRE SYSTEM\n'); const client = new FastMailClient( process.env.FASTMAIL_API_TOKEN, 'clark@clarkeverson.com', 'clark@clarkeverson.com', 'clarkeverson.com', 'https://api.fastmail.com/jmap/session' ); try { await client.authenticate(); const mailboxes = await client.getMailboxes(); console.log('πŸ“‚ COMPLETE EMAIL INVENTORY:'); console.log('='.repeat(70)); let totalSystemEmails = 0; let hierarchicalEmails = 0; let inboxEmails = 0; let oldFolderEmails = 0; let systemFolderEmails = 0; // Categorize all mailboxes const hierarchicalParents = ['Information', 'Financial', 'Commerce', 'Professional', 'Personal']; const systemFolders = ['Inbox', 'Sent', 'Drafts', 'Trash', 'Archive', 'Spam']; const oldFolders = [ 'Newsletter', 'screened-newsletters', 'Updates', 'Education', 'News', 'Banking', 'Transactions', 'Shopping', 'Technical', 'Unsubscribed', 'NeedsAction', 'Notifications', 'Snoozed' ]; console.log('πŸ—οΈ HIERARCHICAL STRUCTURE:'); hierarchicalParents.forEach(parentName => { const parent = mailboxes.find(mb => mb.name === parentName); if (parent) { console.log(`πŸ“‚ ${parentName} (${parent.totalEmails} emails)`); hierarchicalEmails += parent.totalEmails; totalSystemEmails += parent.totalEmails; const children = mailboxes.filter(mb => mb.parentId === parent.id); children.forEach(child => { console.log(` └── ${child.name} (${child.totalEmails} emails)`); hierarchicalEmails += child.totalEmails; totalSystemEmails += child.totalEmails; }); } }); console.log('\nπŸ“₯ SYSTEM FOLDERS:'); systemFolders.forEach(folderName => { const folder = mailboxes.find(mb => mb.name === folderName); if (folder) { console.log(`πŸ“‚ ${folderName} (${folder.totalEmails} emails)`); if (folderName === 'Inbox') { inboxEmails = folder.totalEmails; } else { systemFolderEmails += folder.totalEmails; } totalSystemEmails += folder.totalEmails; } }); console.log('\nπŸ—‚οΈ OLD FOLDERS (NEED TO BE ORGANIZED):'); oldFolders.forEach(folderName => { const folder = mailboxes.find(mb => mb.name === folderName && !mb.parentId); if (folder && folder.totalEmails > 0) { console.log(`πŸ“‚ ${folderName} (${folder.totalEmails} emails) ⚠️ NEEDS MIGRATION`); oldFolderEmails += folder.totalEmails; totalSystemEmails += folder.totalEmails; } }); // Check for any other folders not accounted for console.log('\nπŸ” OTHER/UNKNOWN FOLDERS:'); const accountedFolders = [...hierarchicalParents, ...systemFolders, ...oldFolders]; let otherEmails = 0; mailboxes.forEach(mb => { const isHierarchicalChild = hierarchicalParents.some(parent => { const parentMb = mailboxes.find(p => p.name === parent); return parentMb && mb.parentId === parentMb.id; }); const isSubFolder = mb.parentId && !isHierarchicalChild; const isUnaccounted = !accountedFolders.includes(mb.name) && !mb.parentId && !isSubFolder; if (isUnaccounted || isSubFolder) { console.log(`πŸ“‚ ${mb.name} (${mb.totalEmails} emails)${mb.parentId ? ' [sub-folder]' : ''}`); otherEmails += mb.totalEmails; totalSystemEmails += mb.totalEmails; } }); console.log('\nπŸ“Š COMPLETE SYSTEM SUMMARY:'); console.log('='.repeat(50)); console.log(`πŸ“§ Total emails in entire system: ${totalSystemEmails}`); console.log(`βœ… Emails in hierarchical structure: ${hierarchicalEmails} (${((hierarchicalEmails/totalSystemEmails)*100).toFixed(1)}%)`); console.log(`πŸ“₯ Emails in Inbox (need categorization): ${inboxEmails}`); console.log(`⚠️ Emails in old folders (need migration): ${oldFolderEmails}`); console.log(`πŸ“ Emails in system folders: ${systemFolderEmails}`); console.log(`❓ Emails in other folders: ${otherEmails}`); const unorganizedEmails = inboxEmails + oldFolderEmails; console.log(`\n🎯 EMAILS STILL NEEDING ORGANIZATION: ${unorganizedEmails}`); if (unorganizedEmails > 0) { console.log('\nπŸ“‹ NEXT ACTIONS NEEDED:'); console.log('='.repeat(40)); if (oldFolderEmails > 0) { console.log(`1. πŸ“§ Migrate ${oldFolderEmails} emails from old folders to hierarchy`); } if (inboxEmails > 0) { console.log(`2. πŸ“₯ Categorize ${inboxEmails} inbox emails into hierarchy`); } console.log('3. πŸ—‘οΈ Delete empty old folders'); console.log('4. πŸ“ Update sieve rules for automatic organization'); } else { console.log('\nπŸŽ‰ ALL EMAILS ARE ORGANIZED!'); } } catch (error) { console.log('❌ Error:', error.message); } } countAllEmails().catch(console.error);

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/gr3enarr0w/fastmail-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server