#!/usr/bin/env node
import { FastMailClient } from './src/fastmail-client.js';
import dotenv from 'dotenv';
dotenv.config({ path: '../.env' });
async function searchSolar() {
console.log('🔍 SEARCHING FOR SOLAR EMAILS\n');
const client = new FastMailClient(
process.env.FASTMAIL_API_TOKEN,
'clark@everson.dev',
'clark@clarkeverson.com',
'clarkeverson.com',
'https://api.fastmail.com/jmap/session'
);
try {
await client.authenticate();
const mailboxes = await client.getMailboxes();
const solarKeywords = ['solar', 'panel', 'quote', 'energy', 'installation', 'sunpower', 'tesla', 'pv'];
const solarEmails = [];
// Search key folders
const importantFolders = ['Archive', 'Financial', 'Commerce', 'Information'];
for (const folderName of importantFolders) {
const folder = mailboxes.find(mb => mb.name === folderName);
if (!folder) continue;
console.log(`📂 Searching ${folderName} (${folder.totalEmails} emails)...`);
// Get emails in batches
let position = 0;
while (position < Math.min(folder.totalEmails, 1000)) { // Limit search for speed
const emailResult = await client.getEmails(folder.id, 50, position);
if (!emailResult?.emails?.length) break;
for (const email of emailResult.emails) {
const subject = (email.subject || '').toLowerCase();
const sender = (email.from?.[0]?.email || '').toLowerCase();
const preview = (email.preview || '').toLowerCase();
const hasSolar = solarKeywords.some(keyword =>
subject.includes(keyword) || sender.includes(keyword) || preview.includes(keyword)
);
if (hasSolar) {
solarEmails.push({
folder: folderName,
date: email.receivedAt,
from: email.from?.[0]?.email || 'Unknown',
subject: email.subject || 'No subject',
preview: email.preview?.substring(0, 150) || ''
});
}
}
position += emailResult.emails.length;
}
}
console.log(`\n🔆 FOUND ${solarEmails.length} SOLAR-RELATED EMAILS:\n`);
if (solarEmails.length === 0) {
console.log('❌ No solar emails found');
return;
}
// Sort by date (newest first)
solarEmails.sort((a, b) => new Date(b.date) - new Date(a.date));
solarEmails.forEach((email, index) => {
const date = new Date(email.date).toLocaleDateString();
console.log(`${index + 1}. 📅 ${date} | 📂 ${email.folder}`);
console.log(` FROM: ${email.from}`);
console.log(` SUBJECT: ${email.subject}`);
console.log(` PREVIEW: ${email.preview}...`);
console.log('');
});
} catch (error) {
console.log('❌ Error:', error.message);
}
}
searchSolar().catch(console.error);