#!/usr/bin/env node
import { FastMailClient } from './src/fastmail-client.js';
import dotenv from 'dotenv';
dotenv.config({ path: '../.env' });
async function checkTodaysEmails() {
console.log('📧 CHECKING TODAY\'S EMAILS ACROSS ALL FOLDERS\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();
// Get today's date (start of day)
const today = new Date();
today.setHours(0, 0, 0, 0);
const todayISO = today.toISOString().split('T')[0];
console.log(`📅 Checking emails received on: ${todayISO}`);
console.log('='.repeat(80));
const importantFolders = [
'Inbox',
'Information/Newsletters',
'Financial/Receipts',
'Financial/Banking',
'Commerce/Orders',
'Professional/GitHub',
'Professional/Security',
'Personal/Health',
'Personal/Travel',
'Spam'
];
const results = {};
let totalTodaysEmails = 0;
for (const folderPath of importantFolders) {
let folder;
if (folderPath.includes('/')) {
const [parentName, childName] = folderPath.split('/');
const parent = mailboxes.find(mb => mb.name === parentName);
folder = mailboxes.find(mb => mb.parentId === parent?.id && mb.name === childName);
} else {
folder = mailboxes.find(mb => mb.name === folderPath);
}
if (!folder) {
console.log(`⚠️ ${folderPath}: Folder not found`);
continue;
}
// Get recent emails (last 50 to catch today's)
const emailResult = await client.getEmails(folder.id, 50, 0);
if (!emailResult?.emails?.length) {
console.log(`📂 ${folderPath}: No emails found`);
results[folderPath] = [];
continue;
}
// Filter for today's emails
const todaysEmails = emailResult.emails.filter(email => {
if (!email.receivedAt) return false;
const emailDate = new Date(email.receivedAt);
emailDate.setHours(0, 0, 0, 0);
return emailDate.getTime() === today.getTime();
});
results[folderPath] = todaysEmails;
totalTodaysEmails += todaysEmails.length;
if (todaysEmails.length > 0) {
console.log(`\n📂 ${folderPath}: ${todaysEmails.length} emails today`);
console.log('-'.repeat(60));
todaysEmails.forEach((email, index) => {
const sender = email.from?.[0]?.email || 'Unknown sender';
const subject = email.subject || 'No subject';
const time = new Date(email.receivedAt).toLocaleTimeString();
console.log(`${index + 1}. [${time}] FROM: ${sender}`);
console.log(` SUBJECT: ${subject.substring(0, 80)}${subject.length > 80 ? '...' : ''}`);
// Show preview for inbox emails (most important)
if (folderPath === 'Inbox' && email.preview) {
console.log(` PREVIEW: ${email.preview.substring(0, 100)}...`);
}
console.log('');
});
} else {
console.log(`📂 ${folderPath}: No emails today`);
}
}
console.log('\n📊 TODAY\'S EMAIL SUMMARY:');
console.log('='.repeat(60));
console.log(`📧 Total emails received today: ${totalTodaysEmails}`);
// Show breakdown by category
const breakdown = Object.entries(results)
.filter(([_, emails]) => emails.length > 0)
.sort(([_, a], [__, b]) => b.length - a.length);
if (breakdown.length > 0) {
console.log('\n📈 Breakdown by folder:');
breakdown.forEach(([folder, emails]) => {
console.log(` ${folder}: ${emails.length} emails`);
});
} else {
console.log('✅ No emails received today');
}
// Check if inbox is truly empty
const inboxEmails = results['Inbox'] || [];
if (inboxEmails.length === 0) {
console.log('\n✅ INBOX ZERO MAINTAINED - No emails in inbox today!');
} else {
console.log(`\n⚠️ ${inboxEmails.length} emails in inbox today - review needed`);
}
// Show organization effectiveness
const organizedEmails = totalTodaysEmails - inboxEmails.length;
if (totalTodaysEmails > 0) {
const organizationRate = ((organizedEmails / totalTodaysEmails) * 100).toFixed(1);
console.log(`\n📈 Organization effectiveness: ${organizationRate}% (${organizedEmails}/${totalTodaysEmails} emails auto-organized)`);
}
} catch (error) {
console.log('❌ Error:', error.message);
}
}
checkTodaysEmails().catch(console.error);