Skip to main content
Glama
final-inbox-cleanup.js7.5 kB
#!/usr/bin/env node import { FastMailClient } from '../src/fastmail-client.js'; import dotenv from 'dotenv'; dotenv.config({ path: '../.env' }); async function finalInboxCleanup() { console.log('🔥 FINAL INBOX CLEANUP - AGGRESSIVE ORGANIZATION\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(); const inboxMailbox = mailboxes.find(mb => mb.name === 'Inbox'); const spamMailbox = mailboxes.find(mb => mb.name === 'Spam'); // Get target folders const infoParent = mailboxes.find(mb => mb.name === 'Information'); const commerceParent = mailboxes.find(mb => mb.name === 'Commerce'); const financialParent = mailboxes.find(mb => mb.name === 'Financial'); const professionalParent = mailboxes.find(mb => mb.name === 'Professional'); const targets = { 'Information/Newsletters': mailboxes.find(mb => mb.parentId === infoParent?.id && mb.name === 'Newsletters'), 'Commerce/Orders': mailboxes.find(mb => mb.parentId === commerceParent?.id && mb.name === 'Orders'), 'Financial/Receipts': mailboxes.find(mb => mb.parentId === financialParent?.id && mb.name === 'Receipts'), 'Professional/Security': mailboxes.find(mb => mb.parentId === professionalParent?.id && mb.name === 'Security'), 'Spam': spamMailbox }; console.log(`📧 PROCESSING ${inboxMailbox.totalEmails} INBOX EMAILS:`); console.log('='.repeat(80)); const emailResult = await client.getEmails(inboxMailbox.id, 50, 0); if (!emailResult?.emails?.length) { console.log('✅ Inbox is empty!'); return; } let moved = 0; let spam = 0; let kept = 0; for (const email of emailResult.emails) { const sender = email.from?.[0]?.email?.toLowerCase() || ''; const subject = email.subject || ''; const senderDomain = sender.split('@')[1]?.toLowerCase() || ''; console.log(`\n📧 ${subject.substring(0, 50)}...`); console.log(` FROM: ${sender}`); let targetPath = null; let action = ''; // SPAM - obvious spam patterns if ( subject.toLowerCase().includes('milf') || subject.toLowerCase().includes('wild night') || subject.toLowerCase().includes('hookup') || subject.toLowerCase().includes('wood more than food') || subject.toLowerCase().includes('blood sugar') || subject.toLowerCase().includes('sciatic pain') || subject.toLowerCase().includes('diabetes') || subject.toLowerCase().includes('biblical trick') || subject.toLowerCase().includes('masculine traits') || sender.includes('@students.') || sender.includes('.edu.ng') || sender.includes('.edu.gh') || sender.includes('@unilorin.') || sender.includes('@learnaboutquail.') || sender.includes('@makeupfridges.') || sender.includes('@lemanmotocover.') || sender.includes('@drivestechno.') ) { targetPath = 'Spam'; action = 'SPAM'; spam++; } // LEGITIMATE BUT PROMOTIONAL - move to newsletters else if ( // Promotional/marketing emails from real companies sender.includes('@hello.') || sender.includes('@mountainhighoutfitters.') || sender.includes('@g2a.') || sender.includes('@misen.') || sender.includes('@pepperpalace.') || sender.includes('@getsunday.') || sender.includes('@nationsphotolab.') || sender.includes('@readnotetoself.') || sender.includes('@vrbo.') || sender.includes('@sleepsutera.') || sender.includes('@wingsover.') || sender.includes('@onyxcoffeelab.') || sender.includes('@grove.co') || sender.includes('@chipolo.') || sender.includes('@sololearn.') || // Subject patterns for promotional content subject.toLowerCase().includes('% off') || subject.toLowerCase().includes('sale') || subject.toLowerCase().includes('discount') || subject.toLowerCase().includes('deal') || subject.toLowerCase().includes('mystery discount') || subject.toLowerCase().includes('sitewide') || subject.toLowerCase().includes('july 4') || subject.toLowerCase().includes('4th of july') || subject.toLowerCase().includes('holiday weekend') || subject.toLowerCase().includes('steam library') || subject.toLowerCase().includes('self-care tips') ) { targetPath = 'Information/Newsletters'; action = 'NEWSLETTERS'; moved++; } // FINANCIAL/INVESTMENT - move to financial else if ( sender.includes('@proxyvote.') || subject.toLowerCase().includes('schwab funds') || subject.toLowerCase().includes('shareholder') || subject.toLowerCase().includes('settlement') ) { if (subject.toLowerCase().includes('settlement')) { targetPath = 'Information/Newsletters'; // Legal notices } else { targetPath = 'Financial/Receipts'; // Investment communications } action = 'FINANCIAL'; moved++; } // PROFESSIONAL/EDUCATION else if ( sender.includes('@edx.org') || sender.includes('@atlassian.') || subject.toLowerCase().includes('august 2025') || subject.toLowerCase().includes('maryville') || subject.toLowerCase().includes('atlassian champion') ) { targetPath = 'Information/Newsletters'; action = 'PROFESSIONAL'; moved++; } // KEEP ONLY STARRED EMAILS - move everything else else { // Check if email is starred (flagged) const isStarred = email.keywords && email.keywords.includes('$flagged'); if (isStarred) { action = 'KEEP IN INBOX (STARRED)'; kept++; } else { // Move unstarred emails to newsletters by default targetPath = 'Information/Newsletters'; action = 'MOVE TO NEWSLETTERS (UNSTARRED)'; moved++; } } // Apply the action if (targetPath && targets[targetPath]) { try { await client.moveEmailsToMailbox([email.id], targets[targetPath].id); console.log(` ✅ ${action} → ${targetPath}`); } catch (error) { console.log(` ❌ Error moving: ${error.message}`); } } else if (action === 'KEEP IN INBOX (STARRED)') { console.log(` ⭐ ${action}`); } } console.log('\n🎉 FINAL INBOX CLEANUP COMPLETE!'); console.log('='.repeat(60)); console.log(`📧 Emails moved to categories: ${moved}`); console.log(`🗑️ Spam emails moved: ${spam}`); console.log(`⭐ Kept in inbox (starred only): ${kept}`); console.log(`📊 Total processed: ${moved + spam + kept}`); if (kept <= 5) { console.log('\n✅ PERFECT! Inbox contains only starred emails'); } else { console.log('\n⭐ Inbox contains starred emails only - review stars if needed'); } } catch (error) { console.log('❌ Error:', error.message); } } finalInboxCleanup().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