#!/usr/bin/env node
import { FastMailClient } from './src/fastmail-client.js';
import dotenv from 'dotenv';
dotenv.config({ path: '../.env' });
async function checkSolarAttachments() {
console.log('📎 CHECKING SOLAR EMAILS FOR ATTACHMENTS\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();
// Target the specific solar emails that likely had attachments
const solarSenders = [
'jeff@d2hsolar.com',
'alex@alex-sun.com',
'daniela@incitesolarsolutions.com',
'rebeccab.barnard@gmail.com'
];
const attachmentKeywords = [
'layout', 'quote', 'proposal', 'estimate', 'roof', 'panel',
'attachment', 'pdf', 'image', 'diagram', 'blueprint'
];
let emailsWithAttachments = [];
// Search key folders
const foldersToCheck = ['Newsletters', 'Sent', 'Financial', 'Commerce'];
for (const folderName of foldersToCheck) {
let folder = mailboxes.find(mb => mb.name === folderName);
// Handle nested folders
if (!folder && folderName === 'Newsletters') {
const infoParent = mailboxes.find(mb => mb.name === 'Information');
folder = mailboxes.find(mb => mb.parentId === infoParent?.id && mb.name === 'Newsletters');
}
if (!folder) continue;
console.log(`📂 Checking ${folderName}...`);
let position = 0;
while (position < folder.totalEmails) {
const emailResult = await client.getEmails(folder.id, 50, position);
if (!emailResult?.emails?.length) break;
for (const email of emailResult.emails) {
const sender = email.from?.[0]?.email?.toLowerCase() || '';
const subject = (email.subject || '').toLowerCase();
const preview = (email.preview || '').toLowerCase();
// Check if it's from a solar company
const isSolarEmail = solarSenders.some(solarSender =>
sender.includes(solarSender.toLowerCase())
) || subject.includes('solar');
if (isSolarEmail) {
// Check for attachment indicators
const hasAttachmentIndicators =
attachmentKeywords.some(keyword =>
subject.includes(keyword) || preview.includes(keyword)
) ||
preview.includes('attach') ||
preview.includes('pdf') ||
preview.includes('image') ||
preview.includes('layout') ||
preview.includes('didn\'t load') ||
subject.includes('quote');
if (hasAttachmentIndicators) {
emailsWithAttachments.push({
folder: folderName,
date: email.receivedAt,
from: sender,
subject: email.subject || 'No subject',
preview: email.preview?.substring(0, 300) || '',
emailId: email.id
});
}
}
}
position += emailResult.emails.length;
}
}
console.log(`\n📎 FOUND ${emailsWithAttachments.length} SOLAR EMAILS WITH POTENTIAL ATTACHMENTS:\n`);
if (emailsWithAttachments.length === 0) {
console.log('❌ No solar emails with attachment indicators found');
return;
}
// Sort by date (newest first)
emailsWithAttachments.sort((a, b) => new Date(b.date) - new Date(a.date));
emailsWithAttachments.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}`);
// Highlight attachment indicators
const attachmentClues = [];
if (email.preview.includes('attach')) attachmentClues.push('mentions attachment');
if (email.preview.includes('layout')) attachmentClues.push('mentions layout');
if (email.preview.includes('image')) attachmentClues.push('mentions image');
if (email.preview.includes('pdf')) attachmentClues.push('mentions PDF');
if (email.preview.includes('didn\'t load')) attachmentClues.push('attachment failed to load');
if (email.subject.includes('quote')) attachmentClues.push('quote document');
if (attachmentClues.length > 0) {
console.log(` 📎 ATTACHMENT CLUES: ${attachmentClues.join(', ')}`);
}
console.log('');
});
console.log('💡 RECOMMENDATIONS:');
console.log('1. Check these emails directly in FastMail for attachments');
console.log('2. Look for PDF downloads in your Downloads folder');
console.log('3. Contact D2H Solar (Jeff Jean) for the latest panel layout');
console.log('4. Check if Alex Sun Solar quote is still available');
} catch (error) {
console.log('❌ Error:', error.message);
}
}
checkSolarAttachments().catch(console.error);